I am using this JTable method to create a Cell with a JComboBox as their rendered appearance.
public void addComboBoxToColumn(String[] options, int column_index){
ComboTableCellRenderer renderer = new ComboTableCellRenderer();
JComboBox<String> combo = new JComboBox<String>(options);
TableCellEditor combo_editor = new DefaultCellEditor(combo);
TableColumn column = getColumnModel().getColumn(column_index);
column.setCellRenderer(renderer);
column.setCellEditor(combo_editor);
}
…
public class ComboTableCellRenderer implements ListCellRenderer, TableCellRenderer
{
DefaultListCellRenderer listRenderer = new DefaultListCellRenderer();
DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer();
private void configureRenderer(JLabel renderer, Object value)
{
if (value != null)
renderer.setText((String)value);
}
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
{
listRenderer = (DefaultListCellRenderer)listRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
configureRenderer(listRenderer, value);
return listRenderer;
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
tableRenderer = (DefaultTableCellRenderer)tableRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
configureRenderer(tableRenderer, value);
return tableRenderer;
}
}
My problem is that the combobox is always the size of the cell. I do not want that. Is it possible to make the combo box bigger? Some options in the combobox are too big and are half-hidden.
not possible without jumping of cell
Dimmensionon the Screen, don’t to confuse the userto avoiding possible side effects, I’d be
create popup undecorated
JDialog(for editableJComboBox),JWindow, put thereJComboBoxadd
ListSelectionListener(have to changeListSelectionModetoSINGLE)change built in
KeyBindinginJTableforTableCellEditor(double_clickorF2) to showingJDialog/JWindowhave to center to the desiredPointon the scren,setVisiblemust be wrapped ininvokeLateradd
ItemListener, test forSELECTED, on selected to store value to (setValueAt())XxxTableModel, then to hideJDialog/JWindowuse only one
JDialog(reuse byremoveAllfrom content pane for another action fromGUI) for wholeJVMinstance, only one forJTable