mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
ComboBox: support using as cell renderer (e.g. in JTable)
This commit is contained in:
@@ -134,6 +134,7 @@ public class FlatComponents2Test
|
||||
"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"
|
||||
};
|
||||
cm.getColumn(2).setCellRenderer( new TestComboBoxTableCellRenderer() );
|
||||
cm.getColumn(2).setCellEditor( new DefaultCellEditor( new JComboBox<>( months ) ) );
|
||||
JComboBox<String> editableComboBox = new JComboBox<>( months );
|
||||
editableComboBox.setEditable( true );
|
||||
@@ -1219,4 +1220,23 @@ public class FlatComponents2Test
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
//---- class TestComboBoxTableCellRenderer --------------------------------
|
||||
|
||||
private static class TestComboBoxTableCellRenderer
|
||||
extends JComboBox<String>
|
||||
implements TableCellRenderer
|
||||
{
|
||||
@Override
|
||||
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected,
|
||||
boolean hasFocus, int row, int column )
|
||||
{
|
||||
setModel( new DefaultComboBoxModel<>( new String[] { String.valueOf( value ) } ) );
|
||||
|
||||
setBackground( isSelected ? table.getSelectionBackground() : table.getBackground() );
|
||||
setForeground( isSelected ? table.getSelectionForeground() : table.getForeground() );
|
||||
setBorder( null );
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user