下面列出了javax.swing.JCheckBoxMenuItem#addItemListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
/**
* (Re-)creates the type menu with the selected type
* @param selected the selected column Type
*/
private void updateTypeMenu(String selected) {
typeMenu.removeAll();
ButtonGroup typeGroup = new ButtonGroup();
for (ColumnType columnType : ColumnType.values()) {
String columnTypeName = DataImportWizardUtils.getNameForColumnType(columnType);
JCheckBoxMenuItem checkboxItem = new JCheckBoxMenuItem(columnTypeName);
if (columnTypeName.equals(selected)) {
checkboxItem.setSelected(true);
}
checkboxItem.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
changeType(columnType);
}
});
typeGroup.add(checkboxItem);
typeMenu.add(checkboxItem);
}
}
public JMenuItem getPopupMenuItem(JTextComponent target) {
item = new JCheckBoxMenuItem(NbBundle.getBundle(BaseKit.class).
getString("line-numbers-menuitem"), isLineNumbersVisible());
item.addItemListener( new ItemListener() {
public void itemStateChanged(ItemEvent e) {
actionPerformed(null,null);
}
});
return item;
}
JMenu makeStopOptionsMenu()
{
return new JMenu(Strings.get("menu_stopOptions")) {
private static final long serialVersionUID = 1L;
{
setToolTipText(Strings.get("menu_stopOptions.descr"));
final ItemListener itemListener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e)
{
updateNameOfActionStopBundles();
}
};
itemStopOptionsTransient =
new JCheckBoxMenuItem(Strings.get("stop_option_transient"), false);
itemStopOptionsTransient.setToolTipText(Strings
.get("stop_option_transient.descr"));
itemStopOptionsTransient.addItemListener(itemListener);
add(itemStopOptionsTransient);
updateNameOfActionStopBundles();
}
};
}
JMenu makeStartOptionsMenu()
{
return new JMenu(Strings.get("menu_startOptions")) {
private static final long serialVersionUID = 1L;
{
setToolTipText(Strings.get("menu_startOptions.descr"));
final ItemListener itemListener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e)
{
updateNameOfActionStartBundles();
}
};
itemStartOptionsTransient =
new JCheckBoxMenuItem(Strings.get("start_option_transient"), false);
itemStartOptionsTransient.setToolTipText(Strings
.get("start_option_transient.descr"));
itemStartOptionsTransient.addItemListener(itemListener);
itemStartOptionsPolicy =
new JCheckBoxMenuItem(Strings.get("start_option_policy"), true);
itemStartOptionsPolicy.setToolTipText(Strings
.get("start_option_policy.descr"));
itemStartOptionsPolicy.addItemListener(itemListener);
add(itemStartOptionsTransient);
add(itemStartOptionsPolicy);
updateNameOfActionStartBundles();
}
};
}
private void addCheckBox(JMenu menu, String title, boolean state, ItemListener il) {
JCheckBoxMenuItem item = new JCheckBoxMenuItem(title);
item.setSelected(state);
item.addItemListener(il);
menu.add(item);
}
private void addCheckBox(JMenu menu, String title, boolean state, ItemListener il) {
JCheckBoxMenuItem item = new JCheckBoxMenuItem(title);
item.setSelected(state);
item.addItemListener(il);
menu.add(item);
}
private void addCheckBox(JMenu menu, String title, boolean state, ItemListener il) {
JCheckBoxMenuItem item = new JCheckBoxMenuItem(title);
item.setSelected(state);
item.addItemListener(il);
menu.add(item);
}
public SpectraIdentificationResultsWindow() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(new Dimension(1400, 900));
getContentPane().setLayout(new BorderLayout());
setTitle("Processing...");
pnGrid = new JPanel();
// any number of rows
pnGrid.setLayout(new GridLayout(0, 1, 0, 0));
pnGrid.setBackground(Color.WHITE);
pnGrid.setAutoscrolls(false);
noMatchesFound = new JLabel("I'm working on it", SwingConstants.CENTER);
noMatchesFound.setFont(headerFont);
// yellow
noMatchesFound.setForeground(new Color(0xFFCC00));
pnGrid.add(noMatchesFound, BorderLayout.CENTER);
// Add the Windows menu
JMenuBar menuBar = new JMenuBar();
menuBar.add(new WindowsMenu());
// set font size of chart
JMenuItem btnSetup = new JMenuItem("Setup dialog");
btnSetup.addActionListener(e -> {
if (MZmineCore.getConfiguration()
.getModuleParameters(SpectraIdentificationResultsModule.class)
.showSetupDialog(this, true) == ExitCode.OK) {
showExportButtonsChanged();
}
});
menuBar.add(btnSetup);
JCheckBoxMenuItem cbCoupleZoomY = new JCheckBoxMenuItem("Couple y-zoom");
cbCoupleZoomY.setSelected(true);
cbCoupleZoomY.addItemListener(e -> setCoupleZoomY(cbCoupleZoomY.isSelected()));
menuBar.add(cbCoupleZoomY);
JMenuItem btnSetFont = new JMenuItem("Set chart font");
btnSetFont.addActionListener(e -> setChartFont());
menuBar.add(btnSetFont);
setJMenuBar(menuBar);
scrollPane = new JScrollPane(pnGrid);
getContentPane().add(scrollPane, BorderLayout.CENTER);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setViewportView(pnGrid);
totalMatches = new ArrayList<>();
matchPanels = new HashMap<>();
setCoupleZoomY(true);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
validate();
repaint();
}
private void addCheckBox(JMenu menu, String title, boolean state, ItemListener il) {
JCheckBoxMenuItem item = new JCheckBoxMenuItem(title);
item.setSelected(state);
item.addItemListener(il);
menu.add(item);
}