How to use grids/Tables in LWUIT?
The grid layout object is com.sun.lwuit.layouts.GridLayout -- say you make:
GridLayout myGrid = new GridLayout(numrows, numcolumns);
with the number of rows and columns you want, then you make a container (i.e. a com.sun.lwuit.Container) like:
Container myTable = new Container(myGrid);
and then you work with myTable
as you would with any other Container
as per the docs, i.e., by calling myTable.addComponent
with the components you want to put in the grid/table, myTable.getComponentIndex
to find the index corresponding to a component you've added, myTable.getComponent
to retrieve a component from its index, .removeComponent
to take a component away, removeAll
to empty the whole table, replace
to change one component into another via a transition, etc, etc.
Don't be misled by the two-arguments form of getComponent
: like for any other container, the two arguments are pixel coordinates, NOT row and col indices -- to retrieve a component by row and col you'll instead be using the single-argument form (indexing starts on the top left and proceeds rightwards, then downwards).
Now you can do too:
TableModel model = new DefaultTableModel(
new String[] {"Date", "Detail", "$"},
new Object[][] {
{"21/03/2010", "aaa", "$ -102"},
{"18/03/2010", "bbb", "$ -230"},
{"23/03/2010", "ccc", "$ 500"},
{"Saldo Actual", "", "$ 2.520"},
});
Table mytable = new Table(model);