J2ME Polish
J2ME Polish 2.4 Documentation
Enough Software

TableItem

The TableItem allows you to organize data in tabular form. It will automatically scroll sideways if it doesn't fit on the screen.

Design

Two table items in a Form.
The above tables have been designed with this CSS code:

.defaultTable {
	padding: 3;
	padding-horizontal: 6;
	font-color: gray;
	font-size: small;
	background {
		type: round-rect;
		color: #dfdfaa;
	}
}

.defaultTable:hover {
	padding: 1;
	padding-vertical: 3;
	border {
		type: round-rect;
		width: 2;
		color: #333;
	}
}

.heading {
	font-color: #333;
	font-style: bold;
	font-size: small;
}

.centeredCell {
	padding: 0;
	font-color: gray;
	font-size: small;
	layout: center;
}

If the line color is not specified programatically or using CSS, the font-color will be used by default.

Use these attributes to design the TableItem:

Programming

You can create tables in different ways:

Static Tables

You can specify the dimension of the table in the constructor and then specify each cell:

//#style defaultTable
table = new TableItem(3, 2);
//#style centeredCell
table.set( 1, 0, "1,0");
//#style centeredCell
table.set( 2, 0, "2,0");
//#style centeredCell
table.set( 0, 1, "0,1");
//#style centeredCell
table.set( 1, 1, "xxxx1,1");
//#style centeredCell
table.set( 2, 1, "2,1");
 // set the line color to black:
table.setLineStyle( TableItem.LINE_STYLE_SOLID, 0x000000 ); 
this.form.append( table );

Using TableData

You can also construct a table using de.enough.polish.util.TableData. This can be useful as you can easily persist the data or send it over the network.

TableData data = new TableData(3,2);
data.set( 1, 0, "1,0");
data.set( 2, 0, "2,0");
data.set( 0, 1, "0,1");
data.set( 1, 1, "xxxx1,1");
data.set( 2, 1, "2,1");
//#style defaultTable
table = new TableItem(data);
this.form.append( table );

Dynamic Tables

You can also use the addColumn(), addRow(), removeColumn(int column) and removeRow( int row ) method in either TableItem or TableData for dynamically constructing a table on by one:

//#style defaultTable
table = new TableItem();
Object[] data;
while ( (data = getNextData()) != null ) {
	int row = table.addRow();
	for (int i=0; i<data.length; i++ ) {
		if (i  >= table.getNumberOfColumns() ) {
			table.addColumn();
		}
		table.set( i, row, data[i] );
	}
}

TableItem Contents

You can add any Object as well as Items into a TableItem. Objects are converted into StringItems by calling their respective toString() method.

Sample Application

Please compare the tableitem sample application for a full example.

JavaDoc

back to top