I changed to Nimbus look and feel, as it is described here.
It works fine except for JCheckBoxMenuItems, where the check squares disappeared. The selection color is incorrect too.
This is the code of the popupmenu with the JCheckBoxMenuItems:
public class FilterByNodeUI
{
private JPopupMenu filterMenu;
private PopupMenuButton menu;
private JMenu eventLogFilters, commandFilters;
private JCheckBoxMenuItem[] commandsPeriodicalItems, commandsPeriodicalAllPortsItems;
private JCheckBoxMenuItem alarm, connection, standard;
private String id;
public FilterByNodeUI(Node node)
{
this.id = node.getIp();
filterMenu = new JPopupMenu();
eventLogFilter();
int cpNbr = node.getCommands().getCommandsPeriodical().size();
int cpapNbr = node.getCommands().getCommandsPeriodicalAllPorts().size();
commandsPeriodicalItems = new JCheckBoxMenuItem[cpNbr];
commandsPeriodicalAllPortsItems = new JCheckBoxMenuItem[cpapNbr];
commandFilters = new JMenu("Commands");
for(int i = 0; i < cpNbr; i++)
{
commandsPeriodicalItems[i] = menuItemFactory(node.getCommands().getCommandsPeriodical().get(i).getCommand());
commandFilters.add(commandsPeriodicalItems[i]);
}
commandFilters.addSeparator();
for(int i = 0; i < cpapNbr; i++)
{
commandsPeriodicalAllPortsItems[i] = menuItemFactory(node.getCommands().getCommandsPeriodicalAllPorts().get(i).getCommand());
commandFilters.add(commandsPeriodicalAllPortsItems[i]);
}
filterMenu.add(eventLogFilters);
filterMenu.add(commandFilters);
menu = new PopupMenuButton(node.getDispName(), filterMenu);
commandFilterListeners(commandsPeriodicalItems, node, true);
commandFilterListeners(commandsPeriodicalAllPortsItems, node, false);
}
private void eventLogFilter()
{
alarm = menuItemFactory("Alarm messages");
standard = menuItemFactory("Standard messages");
connection = menuItemFactory("Connection messages");
eventLogFilters = new JMenu("Event Log Messages");
eventLogFilters.add(alarm);
eventLogFilters.add(connection);
eventLogFilters.add(standard);
}
private JCheckBoxMenuItem menuItemFactory(String name)
{
JCheckBoxMenuItem tmp;
tmp = new JCheckBoxMenuItem(name);
tmp.setSelected(true);
tmp.setUI(new StayOpenCheckBoxMenuItemUI()); // I set a new UI here
return tmp;
}
}
This is what it looks like now:
It seems to me that the new look and feel did not apply for the JCheckBoxMenuitems or the JMenu.
The cause of the problem is that I set a new UI for hte JCheckBoxMenuItems because I do not want to close the popup menu when the user checks/unchecks an item.
Here is the code:
public class StayOpenCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI
{
@Override
protected void doClick(MenuSelectionManager msm)
{
menuItem.doClick(0);
}
public static ComponentUI createUI(JComponent c)
{
return new StayOpenCheckBoxMenuItemUI();
}
}
Is there a way to keep this unclosing feature beside the nimbus look and feel?