Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTable problems, Resizing and Editing

Status
Not open for further replies.

fatcodeguy

Programmer
Feb 25, 2002
281
CA
Hi, I have a JTable with two columns, and it's the only component on a JTabbedPane. The records in one column are small, and in another large, but the title for each column is just a word. How do I set the size of a column, and have the other take the rest of the space. The other problem, is how do I set the table for no editing. Thanks
 
Is the JTable set directly into the JTabbedPane, or do you set it into a JPanel, and then the JTabbedPane - this may affect issues ...
 
You could try something like this for setting the column sizes:

for(int id = 0; id < 2; id++)
{
column = tableName.getColumnModel().getColumn(id);
switch(id)
{
case 0: column.setPreferredWidth(10); break;
case 1: column.setPreferredWidth(30); break;
}
}

or you could just set the size of the first column and use:
tableName.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

For no editing you could try:
tableName.setCellSelectionEnabled(false);
or something like:
tableName.setColumnSelectionAllowed(false);
tableName.setRowSelectionAllowed(false);

This might be useful to you:
 
for preventing editing on a table :

In your TableModel to the isCellEditable method add return false;

public MyTableModel extends AbstractTabelModel{
public boolean isCellEditable(int iRow, int iCol){
return false;
}
}
this will prevent the table from editing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top