Re: Controlling JComboBox size in JTable cell



Yulia wrote:
Hi,

I have a JTable where each cell is huge (in purpose).
One of the columns uses DefaultCellEditor with JComboBox (so when user
edits value of this column, a combo-box is displayed).

The problem is that this combo-box is stretched and gets huge
arrow-button (with height similar to its containing cell).
How can I make the combo-box smaller, so its height will be smaller
than the height of the cell that contains it?

Thanks in advance,

Yulia


Method of JTable public Component prepareEditor(TableCellEditor editor, int r, int c) returns your combobox. You can override it and return JPanle with combobox

something like this:

public Component prepareEditor(TableCellEditor editor, int r, int c) {
    Component comp = super.prepareEditor(editor, r, c);
    editorPanel.removeAll();
    // editorPanel is JPanel defined as private class variable
    // size of your combobox should be its preferred size
    editorPanel.add(comp);
    return editorPanel;
}
.