Rob Bamforth's Blog
Java, SQL,T-SQL, MySQL, Networking, SQL Server, PHP, COM, DBA, ODBC

Posts Tagged ‘jtable’

JAVA – Remove Row from A JTable

March 30, 2009

How to remeve a row from a JTable.
This example illustrates how to remove a row from an existing JTable called table.
The row to be deleted will be the row that has been selected by clicking the mouse on it.
 
//CREATE MODEL INSTANCE FROM EXISTING TABLE
DefaultTableModel model = new DefaultTableModel();
model = (DefaultTableModel) table.getModel();
//DELETE THE SELECTED ROW
model.removeRow(table.getSelectedRow());
                
//INSERT A [...]

How To Set The Column Width Of A Jtable

February 2, 2009

Setting the column width of a jTable.
table is a JTabel that already exists.
int col = 1;
int colWidth = 100;
TableColumn column = table.getColumnModel().getColumn(col);
column.setPreferredWidth(colWidth);
This example will set column 1 with a width of 100 pixels.

How To Set The Row Height Of A Jtable

February 2, 2009

Setting the row height of a jTable.
table is a JTabel that already exists.
int height = 50;
table.setRowHeight(height);
This will set each row in the jTable with a height of 50 pixels.