posted 20 years ago
I have a JTable with a comboBox as a cell editor.
This works fine but looks a little bad.
The comboBox needs to be editable. When the user clicks on a cloumn in the table whose editor is the combo box, it appears to be not tall enough.
Here are some code snippets to show you what I mean:
[code]
// create the table
final JTable table = new JTable(new MyTableModel( ));
// create the combo box
JComboBox acctsComboBox = new JComboBox(theAccounts);
acctsComboBox.setEditable( true );
// set the editor
TableColumn descColumn = table.getColumnModel().getColumn(2);
descColumn.setCellEditor(new DefaultCellEditor( acctsComboBox ));
// adjust the width of the column
int preferredWidth = getWidestEntry( acctsComboBox,
table.getFontMetrics(table.getFont()), table.getGraphics());
if (preferredWidth >= 0)
descColumn.setPreferredWidth( preferredWidth );
[\code]