Use JCheckBoxMenuItem instead of custom painting
This commit is contained in:
parent
cb86446b22
commit
383bb4e4bb
@ -9,6 +9,7 @@ import javax.swing.AbstractListModel;
|
|||||||
import javax.swing.ComboBoxModel;
|
import javax.swing.ComboBoxModel;
|
||||||
import javax.swing.DefaultComboBoxModel;
|
import javax.swing.DefaultComboBoxModel;
|
||||||
import javax.swing.DefaultListCellRenderer;
|
import javax.swing.DefaultListCellRenderer;
|
||||||
|
import javax.swing.JCheckBoxMenuItem;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
@ -216,7 +217,7 @@ public class SearchableAndGroupableComboBox<G extends Group, T extends Groupable
|
|||||||
|
|
||||||
// Add the search field at the top
|
// Add the search field at the top
|
||||||
menu.add(searchFieldGroups);
|
menu.add(searchFieldGroups);
|
||||||
menu.addSeparator(); // Separator between search field and menu items
|
menu.addSeparator();
|
||||||
|
|
||||||
// Fill the menu with the groups
|
// Fill the menu with the groups
|
||||||
for (G group : itemGroupMap.keySet()) {
|
for (G group : itemGroupMap.keySet()) {
|
||||||
@ -234,16 +235,8 @@ public class SearchableAndGroupableComboBox<G extends Group, T extends Groupable
|
|||||||
|
|
||||||
if (itemsForGroup != null) {
|
if (itemsForGroup != null) {
|
||||||
for (T item : itemsForGroup) {
|
for (T item : itemsForGroup) {
|
||||||
JMenuItem itemMenu = new JMenuItem(getDisplayString(item)) {
|
JCheckBoxMenuItem itemMenu = new JCheckBoxMenuItem(getDisplayString(item));
|
||||||
@Override
|
itemMenu.setSelected(item == SearchableAndGroupableComboBox.this.getSelectedItem());
|
||||||
public void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
// If the item is currently selected, draw a checkmark before it
|
|
||||||
if (item == SearchableAndGroupableComboBox.this.getSelectedItem()) {
|
|
||||||
g.drawString(CHECKMARK + " ", CHECKMARK_X_OFFSET, getHeight() - CHECKMARK_Y_OFFSET);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
itemMenu.addActionListener(e -> {
|
itemMenu.addActionListener(e -> {
|
||||||
setSelectedItem(item);
|
setSelectedItem(item);
|
||||||
fireActionEvent();
|
fireActionEvent();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user