Complet details of jtable and renderer
Hello user based on my search on JTable i am posting this thread, If any correction in this post please reply.
JTable is one of the difficult component in swings.
Creating a JTable
JTable jt=new JTable();
The above create code create jtable.
Adding ScrollPane to table
JScrollPane jsb=new JScrollPane(jt);
Creating a Default Table Model
DefaultTableModel dt=new DefaultTableModel( new Object[][] , new Object[] {" Column Name1 ", ".....", "Column nth name"});
jt.setModel(dt);
Setting Number of rows
we cant set no.of rows to using jtable.
First get the table model and set number of rows
jt.getModel().setRowCount(n); //n is any integer
these are the simple task on jtable.
Add a component to jtable column model
For add a component to jtable column we should use ediotors/ renders
i am explaining using jcombobox.
first get the column model
TableColumnModel tcm=JTable.getColumnModel();
Then use Editor
tcm.getColumn(nth column).setCellEditor(new DefaultCellEditor(jcombobox));
in the similar way we can add diffrent components in jtable column.
The above procuder will create a jcombobox in nth column in every row of nth column.
if we need to add diffrent components in single column in diffrent rows use cell render.