Java Code Examples for javax.swing.JCheckBoxMenuItem

The following examples show how to use javax.swing.JCheckBoxMenuItem. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: openAGV   Source File: FileModeMenu.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param appState Stores the application's current mode of operation.
 * @param view The application's main view.
 * @param actionMap The application's action map.
 */
@Inject
public FileModeMenu(final ApplicationState appState,
                    final OpenTCSView view,
                    final ViewActionMap actionMap) {
  super(labels.getString("fileModeMenu.text"));
  requireNonNull(view, "view");
  requireNonNull(actionMap, "actionMap");

  final ButtonGroup modeButtonGroup = new ButtonGroup();

  modellingModeItem = new JCheckBoxMenuItem(actionMap.get(SwitchToModellingAction.ID));
  add(modellingModeItem);
  modeButtonGroup.add(modellingModeItem);

  operatingModeItem = new JCheckBoxMenuItem(actionMap.get(SwitchToOperatingAction.ID));
  add(operatingModeItem);
  modeButtonGroup.add(operatingModeItem);
}
 
Example 2
Source Project: dragonwell8_jdk   Source File: bug8031573.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                JMenuBar bar = new JMenuBar();
                JMenu menu = new JMenu("Menu");
                JCheckBoxMenuItem checkBoxMenuItem
                        = new JCheckBoxMenuItem("JCheckBoxMenuItem");
                checkBoxMenuItem.setSelected(true);
                menu.add(checkBoxMenuItem);
                bar.add(menu);
                setJMenuBar(bar);
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source Project: binnavi   Source File: CGraphWindowMenuBar.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new menu bar for a given graph.
 *
 * @param model Contains the information about the displayed graph the menu refers to.
 * @param viewSwitcher Toggles between the different graph panel perspectives.
 */
public CGraphWindowMenuBar(final CGraphModel model, final IViewSwitcher viewSwitcher) {
  Preconditions.checkNotNull(model, "IE01626: Model argument can not be null");

  m_model = model;

  m_actionSave = new CActionSave(model.getParent(), model.getGraph());
  final JCheckBoxMenuItem autoLayoutMenu =
      new JCheckBoxMenuItem(new CActionAutomaticLayouting(model.getGraph()));
  final JCheckBoxMenuItem proximityBrowsingMenu = new JCheckBoxMenuItem(CActionProxy.proxy(
      new CActionProximityBrowsing(model.getParent(), model.getGraph())));

  add(new CViewMenu(model.getParent(), model.getGraphPanel(), model.getGraph(), model
      .getViewContainer(), m_actionSave));
  add(new CGraphMenu(model.getParent(), model.getGraph(), model.getViewContainer(),
      proximityBrowsingMenu, autoLayoutMenu));
  add(m_selectionMenu = new CSelectionMenu(model));
  add(new CSearchMenu(model.getGraph()));
  add(m_pluginsMenu = new CPluginsMenu(model));
  add(new CWindowsMenu(model.getParent(), viewSwitcher));

  m_synchronizer = new CGraphWindowMenuBarSynchronizer(
      model.getGraph().getSettings(), proximityBrowsingMenu, autoLayoutMenu);

  updateGui();
}
 
Example 4
Source Project: jdk8u60   Source File: bug8031573.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                JMenuBar bar = new JMenuBar();
                JMenu menu = new JMenu("Menu");
                JCheckBoxMenuItem checkBoxMenuItem
                        = new JCheckBoxMenuItem("JCheckBoxMenuItem");
                checkBoxMenuItem.setSelected(true);
                menu.add(checkBoxMenuItem);
                bar.add(menu);
                setJMenuBar(bar);
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 5
Source Project: netbeans   Source File: AbstractQuickSearchComboBar.java    License: Apache License 2.0 6 votes vote down vote up
protected void maybeShowPopup (MouseEvent evt) {
    if (evt != null && !SwingUtilities.isLeftMouseButton(evt)) {
        return;
    }

    JPopupMenu pm = new JPopupMenu();
    final Set<ProviderModel.Category> evalCats =
            new LinkedHashSet<ProviderModel.Category>();
    evalCats.addAll(CommandEvaluator.getEvalCats());
    JMenuItem allCats = new AllMenuItem(evalCats);
    pm.add(allCats);

    for (ProviderModel.Category cat : ProviderModel.getInstance().getCategories()) {
        if (!CommandEvaluator.RECENT.equals(cat.getName())) {
            JCheckBoxMenuItem item = new CategoryCheckBoxMenuItem(cat,
                    evalCats);
            pm.add(item);
        }
    }

    pm.show(getInnerComponent(), 0, getInnerComponent().getHeight() - 1);
}
 
Example 6
Source Project: netbeans   Source File: Actions.java    License: Apache License 2.0 6 votes vote down vote up
private void init(JCheckBoxMenuItem item, boolean popup) {
    this.popup = popup;

    if (popup) {
        prepareMargins(item, action);
    }

    Object base = action.getValue("iconBase"); //NOI18N
    Object i = null;

    if (action instanceof SystemAction) {
        i = action.getValue(SystemAction.PROP_ICON);
    } else {
        i = action.getValue(Action.SMALL_ICON);
    }

    hasOwnIcon = (base != null) || (i != null);
}
 
Example 7
Source Project: triplea   Source File: ViewMenu.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void addShowMapDetails() {
  showMapDetails = new JCheckBoxMenuItem("Show Map Details");
  showMapDetails.setMnemonic(KeyEvent.VK_D);
  showMapDetails.setSelected(TileImageFactory.getShowReliefImages());
  showMapDetails.addActionListener(
      e -> {
        if (TileImageFactory.getShowReliefImages() == showMapDetails.isSelected()) {
          return;
        }
        TileImageFactory.setShowReliefImages(showMapDetails.isSelected());
        new Thread(
                () -> frame.getMapPanel().updateCountries(gameData.getMap().getTerritories()),
                "Show map details thread")
            .start();
      });
  add(showMapDetails);
}
 
Example 8
Source Project: netbeans   Source File: ButtonBuilders.java    License: Apache License 2.0 6 votes vote down vote up
static ComponentBuilder getBuilder(Instance instance, Heap heap) {
    if (DetailsUtils.isSubclassOf(instance, JButton.class.getName())) {
        return new JButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JCheckBox.class.getName())) {
        return new JCheckBoxBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JRadioButton.class.getName())) {
        return new JRadioButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JToggleButton.class.getName())) {
        return new JToggleButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JCheckBoxMenuItem.class.getName())) {
        return new JCheckBoxMenuItemBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JRadioButtonMenuItem.class.getName())) {
        return new JRadioButtonMenuItemBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenu.class.getName())) {
        return new JMenuBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenuBar.class.getName())) {
        return new JMenuBarBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenuItem.class.getName())) {
        return new JMenuItemBuilder(instance, heap);
    }
    return null;
}
 
Example 9
Source Project: netbeans   Source File: NbEditorKit.java    License: Apache License 2.0 6 votes vote down vote up
public @Override JMenuItem getPopupMenuItem(JTextComponent target) {
    Preferences prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
    boolean toolbarVisible = prefs.getBoolean(SimpleValueNames.TOOLBAR_VISIBLE_PROP, EditorPreferencesDefaults.defaultToolbarVisible);
    
    JCheckBoxMenuItem item = new JCheckBoxMenuItem(
        NbBundle.getBundle(ToggleToolbarAction.class).getString("PROP_base_toolbarVisible"), //NOI18N
        toolbarVisible);
    
    item.addItemListener( new ItemListener() {
        public @Override void itemStateChanged(ItemEvent e) {
            actionPerformed(null,null);
        }
    });
    
    return item;
}
 
Example 10
Source Project: jdk8u_jdk   Source File: bug8031573.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    try {

        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                JMenuBar bar = new JMenuBar();
                JMenu menu = new JMenu("Menu");
                JCheckBoxMenuItem checkBoxMenuItem
                        = new JCheckBoxMenuItem("JCheckBoxMenuItem");
                checkBoxMenuItem.setSelected(true);
                menu.add(checkBoxMenuItem);
                bar.add(menu);
                setJMenuBar(bar);
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 11
@Override
public void init() {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                JMenuBar bar = new JMenuBar();
                JMenu menu = new JMenu("Menu");
                JCheckBoxMenuItem checkBoxMenuItem
                        = new JCheckBoxMenuItem("JCheckBoxMenuItem");
                checkBoxMenuItem.setSelected(true);
                menu.add(checkBoxMenuItem);
                bar.add(menu);
                setJMenuBar(bar);
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 12
Source Project: scelight   Source File: BoolSettingAction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Overrides {@link XAction#addToMenu(JMenu)} to add a {@link JCheckBoxMenuItem} instead of a {@link JMenuItem}.
 */
@Override
public JMenuItem addToMenu( final JMenu menu ) {
	final JCheckBoxMenuItem mi = new JCheckBoxMenuItem();
	
	menu.add( mi );
	mi.setAction( this );
	mi.setToolTipText( null ); // We don't want tool tip on menu items...
	
	return mi;
}
 
Example 13
Source Project: openAGV   Source File: ViewPluginPanelsMenu.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Removes/adds plugin panels depending on the <code>OperationMode</code>.
 *
 * @param operationMode The operation mode.
 */
private void evaluatePluginPanels(OperationMode operationMode) {
  Kernel.State kernelState = OperationMode.equivalent(operationMode);
  if (kernelState == null) {
    return;
  }

  removeAll();

  SortedSet<PluggablePanelFactory> factories = new TreeSet<>((factory1, factory2) -> {
    return factory1.getPanelDescription().compareTo(factory2.getPanelDescription());
  });
  factories.addAll(panelRegistry.getFactories());

  for (final PluggablePanelFactory factory : factories) {
    if (factory.providesPanel(kernelState)) {
      String title = factory.getPanelDescription();
      final JCheckBoxMenuItem utilMenuItem = new JCheckBoxMenuItem();
      utilMenuItem.setAction(new AddPluginPanelAction(view, factory));
      utilMenuItem.setText(title);
      dockingManager.addPropertyChangeListener(new PluginPanelPropertyHandler(utilMenuItem));
      add(utilMenuItem);
    }
  }
  // If the menu is empty, add a single disabled menu item to it that explains
  // to the user that no plugin panels are available.
  if (getMenuComponentCount() == 0) {
    JMenuItem dummyItem = new JMenuItem(BUNDLE.getString("viewPluginPanelsMenu.menuItem_none.text"));
    dummyItem.setEnabled(false);
    add(dummyItem);
  }
}
 
Example 14
private void addMenu() {
  JMenuBar menu = new JMenuBar();
  JMenu settings = new JMenu("Settings");
  menu.add(settings);
  JFrame thisframe = this;

  // reset zoom
  JMenuItem resetZoom = new JMenuItem("reset zoom");
  menu.add(resetZoom);
  resetZoom.addActionListener(e -> {
    if (group != null)
      group.resetZoom();
  });

  // JMenuItem setSize = new JMenuItem("chart size");
  // menu.add(setSize);
  // setSize.addActionListener(e -> {
  // Dimension dim = SizeSelectDialog.getSizeInput();
  // if (dim != null)
  // setChartSize(dim);
  // });

  //
  addCheckBox(settings, "show legend", showLegend,
      e -> setShowLegend(((JCheckBoxMenuItem) e.getSource()).isSelected()));
  addCheckBox(settings, "show title", showTitle,
      e -> setShowTitle(((JCheckBoxMenuItem) e.getSource()).isSelected()));
  addCheckBox(settings, "show crosshair", showCrosshair,
      e -> setShowCrosshair(((JCheckBoxMenuItem) e.getSource()).isSelected()));;

  this.setJMenuBar(menu);
}
 
Example 15
Source Project: jdk8u-dev-jdk   Source File: bug6438430.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JMenu subMenu1 = new JMenu("Long-titled Sub Menu");
    subMenu1.add(new JMenuItem("SubMenu Item"));
    JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox");

    JMenu menu1 = new JMenu("It works always");
    menu1.add(checkBoxMenuItem1);
    menu1.add(subMenu1);

    // Simulate DefaultMenuLayout calls.
    // The latest traversed menu item must be the widest.
    checkBoxMenuItem1.getPreferredSize();
    int width1 = subMenu1.getPreferredSize().width;
    System.out.println("width1 = " + width1);


    JMenu subMenu2 = new JMenu("Long-titled Sub Menu");
    subMenu2.add(new JMenuItem("SubMenu Item"));
    JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox");

    JMenu menu2 = new JMenu("It did not work before the fix");
    menu2.add(subMenu2);
    menu2.add(checkBoxMenuItem2);

    // Simulate DefaultMenuLayout calls.
    // The latest traversed menu item must be the widest.
    subMenu2.getPreferredSize();
    int width2 = checkBoxMenuItem2.getPreferredSize().width;
    System.out.println("width2 = " + width2);

    if (width1 != width2) {
        throw new RuntimeException( "Submenu title and submenu indicator " +
                                    "overlap on JMenuItem!" );
    }

    System.out.println("Test passed");
}
 
Example 16
Source Project: TencentKona-8   Source File: bug6438430.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JMenu subMenu1 = new JMenu("Long-titled Sub Menu");
    subMenu1.add(new JMenuItem("SubMenu Item"));
    JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox");

    JMenu menu1 = new JMenu("It works always");
    menu1.add(checkBoxMenuItem1);
    menu1.add(subMenu1);

    // Simulate DefaultMenuLayout calls.
    // The latest traversed menu item must be the widest.
    checkBoxMenuItem1.getPreferredSize();
    int width1 = subMenu1.getPreferredSize().width;
    System.out.println("width1 = " + width1);


    JMenu subMenu2 = new JMenu("Long-titled Sub Menu");
    subMenu2.add(new JMenuItem("SubMenu Item"));
    JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox");

    JMenu menu2 = new JMenu("It did not work before the fix");
    menu2.add(subMenu2);
    menu2.add(checkBoxMenuItem2);

    // Simulate DefaultMenuLayout calls.
    // The latest traversed menu item must be the widest.
    subMenu2.getPreferredSize();
    int width2 = checkBoxMenuItem2.getPreferredSize().width;
    System.out.println("width2 = " + width2);

    if (width1 != width2) {
        throw new RuntimeException( "Submenu title and submenu indicator " +
                                    "overlap on JMenuItem!" );
    }

    System.out.println("Test passed");
}
 
Example 17
Source Project: jdk8u60   Source File: bug6438430.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JMenu subMenu1 = new JMenu("Long-titled Sub Menu");
    subMenu1.add(new JMenuItem("SubMenu Item"));
    JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox");

    JMenu menu1 = new JMenu("It works always");
    menu1.add(checkBoxMenuItem1);
    menu1.add(subMenu1);

    // Simulate DefaultMenuLayout calls.
    // The latest traversed menu item must be the widest.
    checkBoxMenuItem1.getPreferredSize();
    int width1 = subMenu1.getPreferredSize().width;
    System.out.println("width1 = " + width1);


    JMenu subMenu2 = new JMenu("Long-titled Sub Menu");
    subMenu2.add(new JMenuItem("SubMenu Item"));
    JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox");

    JMenu menu2 = new JMenu("It did not work before the fix");
    menu2.add(subMenu2);
    menu2.add(checkBoxMenuItem2);

    // Simulate DefaultMenuLayout calls.
    // The latest traversed menu item must be the widest.
    subMenu2.getPreferredSize();
    int width2 = checkBoxMenuItem2.getPreferredSize().width;
    System.out.println("width2 = " + width2);

    if (width1 != width2) {
        throw new RuntimeException( "Submenu title and submenu indicator " +
                                    "overlap on JMenuItem!" );
    }

    System.out.println("Test passed");
}
 
Example 18
Source Project: FancyBing   Source File: ContextMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
private JCheckBoxMenuItem createCheckBox(String label,
                                         String actionCommand)
{
    JCheckBoxMenuItem item = new JCheckBoxMenuItem(i18n(label));
    item.addActionListener(m_actionListener);
    item.setActionCommand(actionCommand);
    return item;
}
 
Example 19
Source Project: openjdk-jdk8u   Source File: bug6438430.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JMenu subMenu1 = new JMenu("Long-titled Sub Menu");
    subMenu1.add(new JMenuItem("SubMenu Item"));
    JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox");

    JMenu menu1 = new JMenu("It works always");
    menu1.add(checkBoxMenuItem1);
    menu1.add(subMenu1);

    // Simulate DefaultMenuLayout calls.
    // The latest traversed menu item must be the widest.
    checkBoxMenuItem1.getPreferredSize();
    int width1 = subMenu1.getPreferredSize().width;
    System.out.println("width1 = " + width1);


    JMenu subMenu2 = new JMenu("Long-titled Sub Menu");
    subMenu2.add(new JMenuItem("SubMenu Item"));
    JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox");

    JMenu menu2 = new JMenu("It did not work before the fix");
    menu2.add(subMenu2);
    menu2.add(checkBoxMenuItem2);

    // Simulate DefaultMenuLayout calls.
    // The latest traversed menu item must be the widest.
    subMenu2.getPreferredSize();
    int width2 = checkBoxMenuItem2.getPreferredSize().width;
    System.out.println("width2 = " + width2);

    if (width1 != width2) {
        throw new RuntimeException( "Submenu title and submenu indicator " +
                                    "overlap on JMenuItem!" );
    }

    System.out.println("Test passed");
}
 
Example 20
Source Project: ontopia   Source File: VizPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates search menu items.
 */
protected void createSearchMenuItems() {
  searchMenuItem = new JCheckBoxMenuItem(Messages
      .getString("Viz.ShowSearchBar"),
      searchPanelVisible);
  searchMenuItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent action) {
      switchSearchPanel();
      searchMenuItem.setSelected(searchPanelVisible);
    }
  });
  add(glPopup, searchMenuItem, ITEM_ID_SHOW_SEARCH_BAR);
}
 
Example 21
Source Project: netbeans   Source File: MenuEditLayer.java    License: Apache License 2.0 5 votes vote down vote up
private String getComponentDefaultsPrefix(JComponent c) {
    if(c instanceof JMenuBar) {
        return "MenuBar"; // NOI18N
    }
    if(c instanceof JMenu) {
        return "Menu"; // NOI18N
    }
    if(c instanceof JCheckBoxMenuItem) {
        return "CheckBoxMenuItem"; // NOI18N
    }
    if(c instanceof JRadioButtonMenuItem) {
        return "RadioButtonMenuItem"; // NOI18N
    }
    return "MenuItem"; // NOI18N
}
 
Example 22
Source Project: netbeans   Source File: FilterSubmenuAction.java    License: Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent ev) {
    Object source = ev.getSource();
    // react just on submenu items, not on submenu click itself
    if (source instanceof JCheckBoxMenuItem) {
        JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem)source;
        String filterName = (String)(menuItem.getClientProperty(PROP_FILTER_NAME));
        filters.setSelected(filterName, menuItem.isSelected());
    }
}
 
Example 23
Source Project: netbeans   Source File: ShowEditorOnlyAction.java    License: Apache License 2.0 5 votes vote down vote up
private void createItems() {
    synchronized( this ) {
        if (menuItems == null) {
            menuItems = new JCheckBoxMenuItem[1];
            menuItems[0] = new JCheckBoxMenuItem(this);
            menuItems[0].setIcon(null);
            Mnemonics.setLocalizedText(menuItems[0], NbBundle.getMessage( ShowEditorOnlyAction.class, "CTL_ShowOnlyEditor"));
        }
    }
}
 
Example 24
Source Project: netbeans   Source File: ToggleFullScreenAction.java    License: Apache License 2.0 5 votes vote down vote up
private void createItems() {
    synchronized( this ) {
        if (menuItems == null) {
            menuItems = new JCheckBoxMenuItem[1];
            menuItems[0] = new JCheckBoxMenuItem(this);
            menuItems[0].setIcon(null);
            Mnemonics.setLocalizedText(menuItems[0], NbBundle.getMessage(ToggleFullScreenAction.class, "CTL_ToggleFullScreenAction"));
        }
    }
}
 
Example 25
Source Project: visualvm   Source File: DropdownButton.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void addAction(JPopupMenu popup, Action action) {
    if (action == null) {
        popup.addSeparator();
    } else {
        Class cls = (Class)action.getValue(KEY_CLASS);
        if (Boolean.class.equals(cls)) {
            Boolean boolvalue = (Boolean)action.getValue(KEY_BOOLVALUE);
            JCheckBoxMenuItem item = new JCheckBoxMenuItem(action);
            item.setSelected(boolvalue);
            popup.add(item);
        } else {
            popup.add(action);
        }
    }
}
 
Example 26
Source Project: jdk8u-jdk   Source File: bug6438430.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JMenu subMenu1 = new JMenu("Long-titled Sub Menu");
    subMenu1.add(new JMenuItem("SubMenu Item"));
    JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox");

    JMenu menu1 = new JMenu("It works always");
    menu1.add(checkBoxMenuItem1);
    menu1.add(subMenu1);

    // Simulate DefaultMenuLayout calls.
    // The latest traversed menu item must be the widest.
    checkBoxMenuItem1.getPreferredSize();
    int width1 = subMenu1.getPreferredSize().width;
    System.out.println("width1 = " + width1);


    JMenu subMenu2 = new JMenu("Long-titled Sub Menu");
    subMenu2.add(new JMenuItem("SubMenu Item"));
    JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox");

    JMenu menu2 = new JMenu("It did not work before the fix");
    menu2.add(subMenu2);
    menu2.add(checkBoxMenuItem2);

    // Simulate DefaultMenuLayout calls.
    // The latest traversed menu item must be the widest.
    subMenu2.getPreferredSize();
    int width2 = checkBoxMenuItem2.getPreferredSize().width;
    System.out.println("width2 = " + width2);

    if (width1 != width2) {
        throw new RuntimeException( "Submenu title and submenu indicator " +
                                    "overlap on JMenuItem!" );
    }

    System.out.println("Test passed");
}
 
Example 27
private void addMenuItemListener(final JCheckBoxMenuItem menuItem) {
    final boolean[] internalChange = new boolean[1];
    menuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
            if (internalChange[0]) return;
            final int column = Integer.parseInt(e.getActionCommand());
            if (column == 3 && !instancesListTableModel.isRealColumnVisible(column)) {
                BrowserUtils.performTask(new Runnable() {
                    public void run() {
                        final int retainedSizesState = instancesListController.getInstancesController().
                                getHeapFragmentWalker().computeRetainedSizes(false, true);
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                if (retainedSizesState != HeapFragmentWalker.RETAINED_SIZES_COMPUTED) {
                                    internalChange[0] = true;
                                    menuItem.setSelected(!menuItem.isSelected());
                                    internalChange[0] = false;
                                } else {
                                    toggleColumnVisibility(column, true);
                                }
                            }
                        });
                    }
                });
            } else {
                toggleColumnVisibility(column, true);
            }

        }
    });
}
 
Example 28
private void addMenuItemListener(final JCheckBoxMenuItem menuItem) {
    final boolean[] internalChange = new boolean[1];
    menuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
            if (internalChange[0]) return;
            final int column = Integer.parseInt(e.getActionCommand());
            if (column == 5 && !fieldsListTableModel.isRealColumnVisible(column)) {
                BrowserUtils.performTask(new Runnable() {
                    public void run() {
                        final int retainedSizesState = referencesBrowserController.getReferencesControllerHandler().
                                getHeapFragmentWalker().computeRetainedSizes(false, true);
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                if (retainedSizesState != HeapFragmentWalker.RETAINED_SIZES_COMPUTED) {
                                    internalChange[0] = true;
                                    menuItem.setSelected(!menuItem.isSelected());
                                    internalChange[0] = false;
                                } else {
                                    fieldsListTableModel.setRealColumnVisibility(column,
                                            !fieldsListTableModel.isRealColumnVisible(column));
                                    fieldsListTable.createDefaultColumnsFromModel();
                                    fieldsListTable.updateTreeTableHeader();
                                    setColumnsData();
                                }
                            }
                        });
                    }
                });
            } else {
                fieldsListTableModel.setRealColumnVisibility(column,
                        !fieldsListTableModel.isRealColumnVisible(column));
                fieldsListTable.createDefaultColumnsFromModel();
                fieldsListTable.updateTreeTableHeader();
                setColumnsData();
            }
        }
    });
}
 
Example 29
private void addMenuItemListener(final JCheckBoxMenuItem menuItem) {
    final boolean[] internalChange = new boolean[1];
    menuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
            if (internalChange[0]) return;
            final int column = Integer.parseInt(e.getActionCommand());
            if (column == 5 && !fieldsListTableModel.isRealColumnVisible(column)) {
                BrowserUtils.performTask(new Runnable() {
                    public void run() {
                        final int retainedSizesState = fieldsBrowserController.getInstancesControllerHandler().
                                getHeapFragmentWalker().computeRetainedSizes(false, true);
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                if (retainedSizesState != HeapFragmentWalker.RETAINED_SIZES_COMPUTED) {
                                    internalChange[0] = true;
                                    menuItem.setSelected(!menuItem.isSelected());
                                    internalChange[0] = false;
                                } else {
                                    fieldsListTableModel.setRealColumnVisibility(column,
                                            !fieldsListTableModel.isRealColumnVisible(column));
                                    fieldsListTable.createDefaultColumnsFromModel();
                                    fieldsListTable.updateTreeTableHeader();
                                    setColumnsData();
                                }
                            }
                        });
                    }
                });
            } else {
                fieldsListTableModel.setRealColumnVisibility(column,
                        !fieldsListTableModel.isRealColumnVisible(column));
                fieldsListTable.createDefaultColumnsFromModel();
                fieldsListTable.updateTreeTableHeader();
                setColumnsData();
            }
        }
    });
}
 
Example 30
Source Project: netbeans   Source File: InstancesListControllerUI.java    License: Apache License 2.0 5 votes vote down vote up
private void addMenuItemListener(final JCheckBoxMenuItem menuItem) {
    final boolean[] internalChange = new boolean[1];
    menuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
            if (internalChange[0]) return;
            final int column = Integer.parseInt(e.getActionCommand());
            if (column == 3 && !instancesListTableModel.isRealColumnVisible(column)) {
                BrowserUtils.performTask(new Runnable() {
                    public void run() {
                        final int retainedSizesState = instancesListController.getInstancesController().
                                getHeapFragmentWalker().computeRetainedSizes(false, true);
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                if (retainedSizesState != HeapFragmentWalker.RETAINED_SIZES_COMPUTED) {
                                    internalChange[0] = true;
                                    menuItem.setSelected(!menuItem.isSelected());
                                    internalChange[0] = false;
                                } else {
                                    toggleColumnVisibility(column, true);
                                }
                            }
                        });
                    }
                });
            } else {
                toggleColumnVisibility(column, true);
            }

        }
    });
}