public void actionPerformed(ActionEvent e) { String oldEncoding = selectedEncoding; selectedEncoding = ((JCheckBoxMenuItem)e.getSource()).getText(); if(!oldEncoding.equals(selectedEncoding)) { // Notify listeners of the new encoding fireEncodingListener(oldEncoding, EncodingMenu.this.selectedEncoding); } } });
JCheckBoxMenuItem item = new JCheckBoxMenuItem(new AbstractAction("...") { // Store the object here. private String someObject; public void actionPerformed(ActionEvent e) { JCheckBoxMenuItem source = (JCheckBoxMenuItem) e.getSource(); if (source.isSelected()) { someObject = "Object " + source.getText(); // trivial. someList.add(someObject); } else { someList.remove(someObject); someObject = null; } } });
public Icon getIcon() { if(BuPreferences.BU.getBooleanProperty("icons.menu",true)|| (super.getText()==null)) return super.getIcon(); return null; }
/** * Triggered from popup menu. * * @param e menu item event */ @Override public void itemStateChanged (ItemEvent e) { JCheckBoxMenuItem item = (JCheckBoxMenuItem) e.getItem(); Board board = getBoard(item.getText()); board.setSelected(item.getState()); }
@Override public void showPopup(Component invoker, int x, int y) { final SynchData synch = (SynchData) getActionValue(ActionW.SYNCH_LINK.cmd()); if (synch == null) { return; } JPopupMenu popupMenu = new JPopupMenu(); TitleMenuItem itemTitle = new TitleMenuItem(ActionW.SYNCH.getTitle(), popupMenu.getInsets()); popupMenu.add(itemTitle); popupMenu.addSeparator(); for (Entry<String, Boolean> a : synch.getActions().entrySet()) { JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(a.getKey(), a.getValue()); menuItem.addActionListener(e -> { if (e.getSource() instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem item = (JCheckBoxMenuItem) e.getSource(); synch.getActions().put(item.getText(), item.isSelected()); } }); popupMenu.add(menuItem); } popupMenu.show(invoker, x, y); } }, SYNCH_ICON);
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(); } } } } } } });
boolean selected = props.getBooleanProperty(checkboxes[i].getText());
@Override public JMenu createMenu(String title) { JMenu menu = new JMenu(title); for (CheckBoxModel item : itemList) { Icon icon = null; if (item.getObject() instanceof GUIEntry) { icon = ((GUIEntry) item.getObject()).getIcon(); } JCheckBoxMenuItem box = new JCheckBoxMenuItem(item.getObject().toString(), icon, item.isSelected()); box.addActionListener(e -> { if (e.getSource() instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem btn = (JCheckBoxMenuItem) e.getSource(); if (startBySelectAll && itemList.get(0).getObject().toString().equals(btn.getText())) { selectAll(menu, btn.isSelected()); } else { item.setSelected(btn.isSelected()); } } }); menu.add(box); } return menu; }
@Override public void itemStateChanged(ItemEvent e) { JCheckBoxMenuItem cMenu = (JCheckBoxMenuItem) e.getItemSelectable(); if (cMenu == matchCase) { qss.setMatchCase(cMenu.isSelected()); } else { String cName = cMenu.getText(); if (cMenu.isSelected()) { qss.addColumnToSearch(cName); } else { qss.removeColumnFromSearch(cName); } } doSearchAction.actionPerformed(null); //doSearch(lastSearchText, Bias.Forward); } };
/** * Get plugin properties to be saved in a project. */ public IFuture getProperties() { Properties props = new Properties(); for(int i=0; i<checkboxes.length; i++) { // System.out.println(""+checkboxes[i].getText()+" "+checkboxes[i].isSelected()); props.addProperty(new Property(checkboxes[i].getText(), ""+checkboxes[i].isSelected())); } return new Future(props); }
@Override public void actionPerformed(ActionEvent e) { JCheckBoxMenuItem item = (JCheckBoxMenuItem)e.getSource(); if (item.getState()) { DrawingMode[] validModes = mainTrack.getValidDrawingModes(); for (int j = 0; j < modeItems.length; j++) { if (item.getText().equals(validModes[j].getDescription())) { for (TrackAdapter t: frame.getTracks()) { AnalyticsAgent.log( new NameValuePair[] { new NameValuePair("track-event","DisplayModeChanged"), new NameValuePair("track-type",t.getClass().getSimpleName()), new NameValuePair("target-mode",validModes[j].getDescription()) } ); t.setDrawingMode(validModes[j]); } drawModePosition = j; } else { modeItems[j].setState(false); } } } else { item.setState(true); } } });
if (item.isSelected()) toBeExecuted.add(item.getText());
checkbox.setChecked(entry.getState()); checkbox.setShortcut(entry.getMnemonic()); checkbox.setText(entry.getText());
item.setTitle(new NSString(ch.getText())); item.setImage(bm); item.setEnabled(ch.isEnabled());
item.setTitle(new NSString(ch.getText())); item.setImage(bm); item.setEnabled(ch.isEnabled());