- Common ways to obtain JCheckBoxMenuItem
private void myMethod () {JCheckBoxMenuItem j =
new JCheckBoxMenuItem()
String str;new JCheckBoxMenuItem(str)
Action action;new JCheckBoxMenuItem(action)
- Smart code suggestions by Codota
}
/** * Overridden to reopen the menu. * * @param pressTime the time to "hold down" the button, in milliseconds */ @Override public void doClick(int pressTime) { super.doClick(pressTime); MenuSelectionManager.defaultManager().setSelectedPath(path); } }
frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); SwingUtilities.invokeLater(new Runnable() { public void run() { for (int i = 0; i < menuBar.getMenuCount(); i++) { JMenu menu = menuBar.getMenu(i); if ("View".equals(menu.getText())) { int componentCount = menu.getMenuComponentCount(); for (int j = 0; j < componentCount; j++) { Component c = menu.getMenuComponent(j); if (c instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem chkBoxMenuItem = (JCheckBoxMenuItem) c; String text = chkBoxMenuItem.getText(); if ("Show SearchPanel".equals(text)) { chkBoxMenuItem.doClick(); } } } } } } });
checkboxes[i].doClick();
public void testSimple() { assertFalse(model.isState()); assertFalse(menuItem.isSelected()); model.setState(true); assertTrue(menuItem.isSelected()); assertTrue(model.isState()); menuItem.doClick(); assertFalse(model.isState()); assertFalse(menuItem.isSelected()); } }