Java Code Examples for javax.swing.JMenuItem#getActionCommand()
The following examples show how to use
javax.swing.JMenuItem#getActionCommand() .
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 File: GltfBrowserApplication.java From JglTF with MIT License | 6 votes |
/** * Recursively attach the given action listener to all items in the * given menu that have a non-<code>null</code> action command * * @param menuElement The menu element * @param actionListener The action listener */ private static void attachActionListener( MenuElement menuElement, ActionListener actionListener) { if (menuElement instanceof JMenuItem) { JMenuItem menuItem = (JMenuItem)menuElement; if (menuItem.getActionCommand() != null) { menuItem.addActionListener(actionListener); } } MenuElement[] subElements = menuElement.getSubElements(); for (MenuElement subElement : subElements) { attachActionListener(subElement, actionListener); } }
Example 2
Source File: PlotFrame.java From OpenDA with GNU Lesser General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent e) { JMenuItem target = (JMenuItem)e.getSource(); String actionCommand = target.getActionCommand(); try { if (actionCommand.equals("Open")) { _open(); } else if (actionCommand.equals("Save")) { _save(); } else if (actionCommand.equals("SaveAs")) { _saveAs(); } else if (actionCommand.equals("Export")) { _export(); } else if (actionCommand.equals("Print")) { _print(); } else if (actionCommand.equals("Close")) { _close(); } } catch (Exception exception) { // If we do not catch exceptions here, then they // disappear to stdout, which is bad if we launched // where there is no stdout visible. JOptionPane.showMessageDialog(null, "File Menu Exception:\n" + exception.toString(), "Ptolemy Plot Error", JOptionPane.WARNING_MESSAGE); } // NOTE: The following should not be needed, but there jdk1.3beta // appears to have a bug in swing where repainting doesn't // properly occur. repaint(); }
Example 3
Source File: PlotFrame.java From OpenDA with GNU Lesser General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent e) { JMenuItem target = (JMenuItem)e.getSource(); String actionCommand = target.getActionCommand(); try { if (actionCommand.equals("About")) { _about(); } else if (actionCommand.equals("Help")) { _help(); } else if (actionCommand.equals("Fill")) { plot.fillPlot(); } else if (actionCommand.equals("Reset axes")) { plot.resetAxes(); } else if (actionCommand.equals("Clear")) { plot.clear(false); plot.repaint(); } } catch (Exception exception) { // If we do not catch exceptions here, then they // disappear to stdout, which is bad if we launched // where there is no stdout visible. JOptionPane.showMessageDialog(null, "Special Menu Exception:\n" + exception.toString(), "Ptolemy Plot Error", JOptionPane.WARNING_MESSAGE); } // NOTE: The following should not be needed, but there jdk1.3beta // appears to have a bug in swing where repainting doesn't // properly occur. repaint(); }
Example 4
Source File: PlotFrame.java From opt4j with MIT License | 5 votes |
@Override public void actionPerformed(ActionEvent e) { JMenuItem target = (JMenuItem) e.getSource(); String actionCommand = target.getActionCommand(); try { if (actionCommand.equals("Open")) { _open(); } else if (actionCommand.equals("Save")) { _save(); } else if (actionCommand.equals("SaveAs")) { _saveAs(); } else if (actionCommand.equals("Export")) { _export(); } else if (actionCommand.equals("Print")) { _print(); } else if (actionCommand.equals("Close")) { _close(); } } catch (Exception exception) { // If we do not catch exceptions here, then they // disappear to stdout, which is bad if we launched // where there is no stdout visible. JOptionPane.showMessageDialog(null, "File Menu Exception:\n" + exception.toString(), "Ptolemy Plot Error", JOptionPane.WARNING_MESSAGE); } // NOTE: The following should not be needed, but there jdk1.3beta // appears to have a bug in swing where repainting doesn't // properly occur. repaint(); }
Example 5
Source File: PlotFrame.java From opt4j with MIT License | 5 votes |
@Override public void actionPerformed(ActionEvent e) { JMenuItem target = (JMenuItem) e.getSource(); String actionCommand = target.getActionCommand(); try { if (actionCommand.equals("About")) { _about(); } else if (actionCommand.equals("Help")) { _help(); } else if (actionCommand.equals("Fill")) { plot.fillPlot(); } else if (actionCommand.equals("Reset axes")) { plot.resetAxes(); } else if (actionCommand.equals("Clear")) { plot.clear(false); plot.repaint(); } else if (actionCommand.equals("Sample plot")) { plot.clear(true); samplePlot(); } } catch (Exception exception) { // If we do not catch exceptions here, then they // disappear to stdout, which is bad if we launched // where there is no stdout visible. JOptionPane.showMessageDialog(null, "Special Menu Exception:\n" + exception.toString(), "Ptolemy Plot Error", JOptionPane.WARNING_MESSAGE); } // NOTE: The following should not be needed, but there jdk1.3beta // appears to have a bug in swing where repainting doesn't // properly occur. repaint(); }