List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction(String name)
From source file:burlov.ultracipher.swing.MainPanel.java
public Action getDeleteEntryAction() { Action ret = new AbstractAction("deleteEntryAction") { /**/*from w w w. ja v a2 s . com*/ * */ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { deleteCurrentEntry(); } }; ret.putValue(Action.NAME, "Delete entry"); ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control D")); return ret; }
From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java
/** * Initializes action objects. <br> * Does not assign actions to components yet! *///from ww w . ja va 2s . c om private void initializeActions() { actionSelectAll = new AbstractAction(Localization.lang("Select all")) { @Override public void actionPerformed(ActionEvent e) { CheckableTreeNode rootNode = (CheckableTreeNode) tree.getModel().getRoot(); rootNode.setSelected(true); tree.invalidate(); tree.repaint(); } }; actionUnselectAll = new AbstractAction(Localization.lang("Unselect all")) { @Override public void actionPerformed(ActionEvent e) { CheckableTreeNode rootNode = (CheckableTreeNode) tree.getModel().getRoot(); rootNode.setSelected(false); tree.invalidate(); tree.repaint(); } }; actionExpandTree = new AbstractAction(Localization.lang("Expand all")) { @Override public void actionPerformed(ActionEvent e) { CheckableTreeNode rootNode = (CheckableTreeNode) tree.getModel().getRoot(); expandTree(tree, new TreePath(rootNode), true); } }; actionCollapseTree = new AbstractAction(Localization.lang("Collapse all")) { @Override public void actionPerformed(ActionEvent e) { CheckableTreeNode rootNode = (CheckableTreeNode) tree.getModel().getRoot(); expandTree(tree, new TreePath(rootNode), false); } }; dialogPositionListener = new ComponentAdapter() { /* (non-Javadoc) * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent) */ @Override public void componentResized(ComponentEvent e) { storeSizeOfDialog(); } /* (non-Javadoc) * @see java.awt.event.ComponentAdapter#componentMoved(java.awt.event.ComponentEvent) */ @Override public void componentMoved(ComponentEvent e) { storeSizeOfDialog(); } }; }
From source file:burlov.ultracipher.swing.MainPanel.java
public Action getNewEntryAction() { Action ret = new AbstractAction("deleteEntryAction") { /**//w ww .j a va 2 s .c o m * */ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { getEditDataPanel().setEditable(true); newEntry(); } }; ret.putValue(Action.NAME, "New entry"); ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control N")); return ret; }
From source file:biomine.bmvis2.crawling.CrawlSuggestionList.java
public CrawlSuggestionList() { // setMinimumSize(new Dimension(600,200)); // initialize layout GridBagLayout layout = new GridBagLayout(); this.setLayout(layout); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1;/*from www . j ava2 s .c o m*/ c.weighty = 0; c.gridx = 0; c.gridy = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 1; c.gridheight = 1; dbSelect = new JComboBox(); for (String db : Databases.getDatabases()) { dbSelect.addItem(db); } dbSelect.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { suggestionQuery.setDb(dbSelect.getSelectedItem().toString()); } }); this.add(dbSelect, c); c.gridy++; this.add(query, c); c.gridwidth = 1; c.weighty = 3; c.weightx = 10; c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridy++; // listScroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); listScroller = new JScrollPane(list); this.add(listScroller, c); c.weighty = 0; c.weightx = 10; c.gridwidth = 1; c.gridx = 0; c.gridy++; this.add(new JLabel("Selected nodes:"), c); c.weighty = 3; c.weightx = 10; c.gridwidth = 1; c.gridx = 0; c.gridy++; JScrollPane selectedScroller = new JScrollPane(selectedList); this.add(selectedScroller, c); // initialize components back.setAction(new AbstractAction("< back to unfiltered results") { public void actionPerformed(ActionEvent arg0) { suggestionQuery.back(); updateList(); } }); query.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent arg0) { updateList(); } }); list.setModel(new SuggestListModel()); list.addMouseListener(new SuggestMouseListener(list)); list.addMouseMotionListener(new SuggestMouseListener(list)); list.setCellRenderer(new SuggestCellRenderer()); selectedList.setModel(new SelectedListModel()); selectedList.addMouseListener(new SuggestMouseListener(selectedList)); selectedList.addMouseMotionListener(new SuggestMouseListener(selectedList)); selectedList.setCellRenderer(new SuggestCellRenderer()); }
From source file:com.diversityarrays.kdxplore.field.FieldViewDialog.java
public FieldViewDialog(Window owner, String title, SampleGroupChoice sgcSamples, Trial trial, SampleGroupChoice sgcNewMedia, KDSmartDatabase db) throws IOException { super(owner, title, ModalityType.MODELESS); advanceRetreatControls = Box.createHorizontalBox(); advanceRetreatControls.add(new JButton(retreatAction)); advanceRetreatControls.add(new JButton(advanceAction)); autoAdvanceControls = Box.createHorizontalBox(); autoAdvanceControls.add(new JButton(autoAdvanceAction)); autoAdvanceOption.addActionListener(new ActionListener() { @Override//w w w .j a v a 2s . c om public void actionPerformed(ActionEvent e) { updateMovementControls(); } }); this.database = db; this.sampleGroupChoiceForSamples = sgcSamples; this.sampleGroupChoiceForNewMedia = sgcNewMedia; NumberSpinner fontSpinner = new NumberSpinner(new SpinnerNumberModel(), "0.00"); this.fieldViewPanel = FieldViewPanel.create(database, trial, SeparatorVisibilityOption.VISIBLE, null, Box.createHorizontalGlue(), new JButton(showInfoAction), Box.createHorizontalGlue(), new JLabel("Font Size:"), fontSpinner, Box.createHorizontalGlue(), advanceRetreatControls, autoAdvanceOption, autoAdvanceControls); initialiseAction(advanceAction, "ic_object_advance_black.png", "Auto-Advance"); this.xyProvider = fieldViewPanel.getXYprovider(); this.traitMap = fieldViewPanel.getTraitMap(); fieldLayoutTable = fieldViewPanel.getFieldLayoutTable(); JScrollPane scrollPane = fieldViewPanel.getFieldTableScrollPane(); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); fieldLayoutTable.setTransferHandler(flth); fieldLayoutTable.setDropMode(DropMode.ON); fieldLayoutTable.addMouseListener(new MouseAdapter() { JPopupMenu popupMenu; @Override public void mouseClicked(MouseEvent e) { if (!SwingUtilities.isRightMouseButton(e) || 1 != e.getClickCount()) { return; } Point pt = e.getPoint(); int row = fieldLayoutTable.rowAtPoint(pt); if (row >= 0) { int col = fieldLayoutTable.columnAtPoint(pt); if (col >= 0) { Plot plot = fieldViewPanel.getPlotAt(col, row); if (plot != null) { if (popupMenu == null) { popupMenu = new JPopupMenu("View Attachments"); } popupMenu.removeAll(); Set<File> set = plot.getMediaFiles(); if (Check.isEmpty(set)) { popupMenu.add(new JMenuItem("No Attachments available")); } else { for (File file : set) { Action a = new AbstractAction(file.getName()) { @Override public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().browse(file.toURI()); } catch (IOException e1) { MsgBox.warn(FieldViewDialog.this, e1, file.getName()); } } }; popupMenu.add(new JMenuItem(a)); } } popupMenu.show(fieldLayoutTable, pt.x, pt.y); } } } } }); Font font = fieldLayoutTable.getFont(); float fontSize = font.getSize2D(); fontSizeModel = new SpinnerNumberModel(fontSize, fontSize, 50.0, 1.0); fontSpinner.setModel(fontSizeModel); fontSizeModel.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { float fsize = fontSizeModel.getNumber().floatValue(); System.out.println("Using fontSize=" + fsize); Font font = fieldLayoutTable.getFont().deriveFont(fsize); fieldLayoutTable.setFont(font); FontMetrics fm = fieldLayoutTable.getFontMetrics(font); int lineHeight = fm.getMaxAscent() + fm.getMaxDescent(); fieldLayoutTable.setRowHeight(4 * lineHeight); // GuiUtil.initialiseTableColumnWidths(fieldLayoutTable, false); fieldLayoutTable.repaint(); } }); fieldLayoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); fieldLayoutTable.setResizable(true, true); fieldLayoutTable.getTableColumnResizer().setResizeAllColumns(true); advanceAction.setEnabled(false); fieldLayoutTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { handlePlotSelection(); } } }); TableColumnModel columnModel = fieldLayoutTable.getColumnModel(); columnModel.addColumnModelListener(new TableColumnModelListener() { @Override public void columnSelectionChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { handlePlotSelection(); } } @Override public void columnRemoved(TableColumnModelEvent e) { } @Override public void columnMoved(TableColumnModelEvent e) { } @Override public void columnMarginChanged(ChangeEvent e) { } @Override public void columnAdded(TableColumnModelEvent e) { } }); PropertyChangeListener listener = new PropertyChangeListener() { // Use a timer and redisplay other columns when delay is GT 100 ms Timer timer = new Timer(true); TimerTask timerTask; long lastActive; boolean busy = false; private int eventColumnWidth; private TableColumn eventColumn; @Override public void propertyChange(PropertyChangeEvent evt) { if (busy) { return; } if (evt.getSource() instanceof TableColumn && "width".equals(evt.getPropertyName())) { eventColumn = (TableColumn) evt.getSource(); eventColumnWidth = eventColumn.getWidth(); lastActive = System.currentTimeMillis(); if (timerTask == null) { timerTask = new TimerTask() { @Override public void run() { if (System.currentTimeMillis() - lastActive > 200) { timerTask.cancel(); timerTask = null; busy = true; try { for (Enumeration<TableColumn> en = columnModel.getColumns(); en .hasMoreElements();) { TableColumn tc = en.nextElement(); if (tc != eventColumn) { tc.setWidth(eventColumnWidth); } } } finally { busy = false; } } } }; timer.scheduleAtFixedRate(timerTask, 100, 150); } } } }; for (Enumeration<TableColumn> en = columnModel.getColumns(); en.hasMoreElements();) { TableColumn tc = en.nextElement(); tc.addPropertyChangeListener(listener); } Map<Integer, Plot> plotById = new HashMap<>(); for (Plot plot : fieldViewPanel.getFieldLayout()) { plotById.put(plot.getPlotId(), plot); } TrialItemVisitor<Sample> sampleVisitor = new TrialItemVisitor<Sample>() { @Override public void setExpectedItemCount(int count) { } @Override public boolean consumeItem(Sample sample) throws IOException { Plot plot = plotById.get(sample.getPlotId()); if (plot == null) { throw new IOException("Missing plot for plotId=" + sample.getPlotId() + " sampleIdent=" + Util.createUniqueSampleKey(sample)); } plot.addSample(sample); SampleCounts counts = countsByTraitId.get(sample.getTraitId()); if (counts == null) { counts = new SampleCounts(); countsByTraitId.put(sample.getTraitId(), counts); } if (sample.hasBeenScored()) { ++counts.scored; } else { ++counts.unscored; } return true; } }; database.visitSamplesForTrial(sampleGroupChoiceForSamples, trial.getTrialId(), SampleOrder.ALL_BY_PLOT_ID_THEN_TRAIT_ID_THEN_INSTANCE_NUMBER_ORDER_THEN_SPECIMEN_NUMBER, sampleVisitor); setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.trial = trial; KDClientUtils.initAction(ImageId.SETTINGS_24, showInfoAction, "Trial Summary"); Action clear = new AbstractAction("Clear") { @Override public void actionPerformed(ActionEvent e) { infoTextArea.setText(""); } }; JPanel bottom = new JPanel(new BorderLayout()); bottom.add(GuiUtil.createLabelSeparator("Plot Details", new JButton(clear)), BorderLayout.NORTH); bottom.add(new JScrollPane(infoTextArea), BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, fieldViewPanel, new JScrollPane(infoTextArea)); splitPane.setResizeWeight(0.0); splitPane.setOneTouchExpandable(true); setContentPane(splitPane); updateMovementControls(); pack(); }
From source file:org.openconcerto.erp.core.finance.accounting.element.AnalytiqueSQLElement.java
private void actionDroitOnglet(final int index, final MouseEvent e) { JPopupMenu pop = new JPopupMenu(); pop.add(new AbstractAction("Ajouter un axe") { public void actionPerformed(ActionEvent e) { if (ajoutAxeFrame == null) { ajoutAxeFrame = new AjouterAxeAnalytiqueFrame(a); }/*from w ww .j av a 2 s. c o m*/ ajoutAxeFrame.pack(); ajoutAxeFrame.setVisible(true); } }); // si un onglet est selectionn if (index != -1) { pop.add(new AbstractAction("Supprimer l'axe") { public void actionPerformed(ActionEvent e) { supprimerAxe(index); } }); pop.add(new AbstractAction("Modifier le nom") { public void actionPerformed(ActionEvent aE) { actionModifierAxe(e, index); } }); } pop.show(e.getComponent(), e.getX(), e.getY()); System.out.println("Click droit onglet"); }
From source file:nz.ac.massey.cs.gql4jung.browser.ResultBrowser.java
private void initActions() { actExit = new AbstractAction("exit") { @Override/* w w w. ja v a 2 s . c o m*/ public void actionPerformed(ActionEvent e) { dispose(); } }; actLoadData = new AbstractAction("load data", getIcon("Open16.gif")) { @Override public void actionPerformed(ActionEvent e) { actLoadData(); } }; actLoadData.putValue(Action.SHORT_DESCRIPTION, "load a program dependency graph from a graphml file"); actLoadQuery = new AbstractAction("load query", getIcon("Import16.gif")) { @Override public void actionPerformed(ActionEvent e) { actLoadQuery(); } }; actLoadQuery.putValue(Action.SHORT_DESCRIPTION, "load a query from a xml file"); actRunQuery = new AbstractAction("run query", getIcon("Play16.gif")) { @Override public void actionPerformed(ActionEvent e) { actRunQuery(); } }; actRunQuery.putValue(Action.SHORT_DESCRIPTION, "execute the query"); actCancelQuery = new AbstractAction("cancel", getIcon("Stop16.gif")) { @Override public void actionPerformed(ActionEvent e) { actCancelQuery(); } }; actCancelQuery.putValue(Action.SHORT_DESCRIPTION, "cancel the currently running query"); actExport2CSV = new AbstractAction("export to csv", getIcon("Export16.gif")) { @Override public void actionPerformed(ActionEvent e) { actExport2CSV(); } }; actExport2CSV.putValue(Action.SHORT_DESCRIPTION, "export the query results to a CSV (spreadsheet) file"); actPreviousMinorInstance = new AbstractAction("previous minor instance", getIcon("PreviousMinor16.gif")) { @Override public void actionPerformed(ActionEvent e) { actPreviousMinorInstance(); } }; actPreviousMinorInstance.putValue(Action.SHORT_DESCRIPTION, "show the previous variant of the selected instance"); actNextMinorInstance = new AbstractAction("next minor instance", getIcon("NextMinor16.gif")) { @Override public void actionPerformed(ActionEvent e) { actNextMinorInstance(); } }; actNextMinorInstance.putValue(Action.SHORT_DESCRIPTION, "show the next variant of the selected instance"); actPreviousMajorInstance = new AbstractAction("previous major instance", getIcon("PreviousMajor16.gif")) { @Override public void actionPerformed(ActionEvent e) { actPreviousMajorInstance(); } }; actPreviousMajorInstance.putValue(Action.SHORT_DESCRIPTION, "show the previous instance"); actNextMajorInstance = new AbstractAction("next major instance", getIcon("NextMajor16.gif")) { @Override public void actionPerformed(ActionEvent e) { actNextMajorInstance(); } }; actNextMajorInstance.putValue(Action.SHORT_DESCRIPTION, "show the next instance"); initBuiltInQueries(); }
From source file:org.ayound.js.debug.ui.DebugMainFrame.java
private void initAction() { actionOpen = new AbstractAction(Messages.getString("DebugMainFrame.Open")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); // fileDialog.setFileFilter(new FileFilter() { @Override/*from w w w.j a v a2 s.co m*/ public boolean accept(File f) { String fileName = f.getName().toLowerCase(); if (fileName.endsWith(".htm") //$NON-NLS-1$ || fileName.endsWith(".html") //$NON-NLS-1$ || fileName.endsWith(".js") || f.isDirectory()) { //$NON-NLS-1$ return true; } else { return false; } } @Override public String getDescription() { return ".htm,.html,.js"; //$NON-NLS-1$ } }); int result = fileDialog.showOpenDialog(DebugMainFrame.this); if (result == JFileChooser.APPROVE_OPTION) { openHtmlFile(fileDialog.getSelectedFile()); } } }; actionClose = new AbstractAction(Messages.getString("DebugMainFrame.Close")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { int index = mainPane.getSelectedIndex(); if (index > -1) { mainPane.remove(index); } } }; actionExit = new AbstractAction(Messages.getString("DebugMainFrame.Exit")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { System.exit(0); } }; ImageIcon startIcon = new ImageIcon(DebugMainFrame.class.getResource("icons/launch_run.gif")); //$NON-NLS-1$ actionDebugStart = new AbstractAction(Messages.getString("DebugMainFrame.Start"), startIcon) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { startDebug(); } }; ImageIcon endIcon = new ImageIcon(DebugMainFrame.class.getResource("icons/terminate_co.gif")); //$NON-NLS-1$ actionDebugEnd = new AbstractAction(Messages.getString("DebugMainFrame.End"), endIcon) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { endDebug(); } }; actionDebugEnd.setEnabled(false); actionHelp = new AbstractAction(Messages.getString("DebugMainFrame.Content")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { String locale = DebugMainFrame.this.getLocale().toString(); String helpPath = "help/index_" + locale + ".html"; File testFile = new File(new File(getBaseDir()), helpPath); //$NON-NLS-1$ final String url = "file:///" + testFile.getAbsolutePath().replace('\\', '/'); //$NON-NLS-1$ SwingUtilities.invokeLater(new Runnable() { public void run() { try { // TODO Auto-generated method stub JFrame someWindow = new JFrame(); JEditorPane htmlPane = new JEditorPane(url); htmlPane.setEditable(false); someWindow.setSize(800, 600); someWindow.setExtendedState(JFrame.MAXIMIZED_BOTH); someWindow.setVisible(true); someWindow.add(new JScrollPane(htmlPane)); } catch (IOException ioe) { System.err.println(Messages.getString("DebugMainFrame.ErrorDisplay") + url); //$NON-NLS-1$ } } }); } }; actionAbout = new AbstractAction(Messages.getString("DebugMainFrame.About")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(DebugMainFrame.this, Messages.getString("DebugMainFrame.AboutContent"), //$NON-NLS-1$ Messages.getString("DebugMainFrame.ApplicationName"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$ } }; actionLanguageChinese = new AbstractAction("Chinese") { public void actionPerformed(ActionEvent e) { DebugUIUtil.updateUI(Locale.SIMPLIFIED_CHINESE); } }; actionLanguageEnglish = new AbstractAction("English") { public void actionPerformed(ActionEvent e) { DebugUIUtil.updateUI(Locale.ENGLISH); } }; }
From source file:net.pandoragames.far.ui.swing.component.UndoHistory.java
/** * Registers the specified text component for the undo history. * This enables the <code>ctrl + z</code> and <code>ctrl + y</code> shortcuts. * @param component to be registered for undos. *//*w w w. ja v a 2 s .c o m*/ public void registerUndoHistory(JTextComponent component) { // Create an undo action and add it to the text component undoAction = new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { if (UndoHistory.this.canUndo()) { UndoHistory.this.undo(); } } }; undoAction.setEnabled(false); component.getActionMap().put(ACTION_KEY_UNDO, undoAction); // Create a redo action and add it to the text component redoAction = new AbstractAction("Redo") { public void actionPerformed(ActionEvent evt) { if (UndoHistory.this.canRedo()) { UndoHistory.this.redo(); } } }; redoAction.setEnabled(false); component.getActionMap().put(ACTION_KEY_REDO, redoAction); // Bind the actions to ctl-Z and ctl-Y component.getInputMap().put(KeyStroke.getKeyStroke("control Z"), ACTION_KEY_UNDO); undoAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Z")); component.getInputMap().put(KeyStroke.getKeyStroke("control Y"), ACTION_KEY_REDO); redoAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Y")); // registers this UndoHistory as an UndoableEditListener component.getDocument().addUndoableEditListener(this); }
From source file:misc.TextBatchPrintingDemo.java
/** * Create and display the main application frame. *//* ww w . ja v a2 s .c o m*/ void createAndShowGUI() { messageArea = new JLabel(defaultMessage); selectedPages = new JList(new DefaultListModel()); selectedPages.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); selectedPages.addListSelectionListener(this); setPage(homePage); JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(pageItem), new JScrollPane(selectedPages)); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); /** Menu item and keyboard shortcuts for the "add page" command. */ fileMenu.add(createMenuItem(new AbstractAction("Add Page") { public void actionPerformed(ActionEvent e) { DefaultListModel pages = (DefaultListModel) selectedPages.getModel(); pages.addElement(pageItem); selectedPages.setSelectedIndex(pages.getSize() - 1); } }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.ALT_MASK))); /** Menu item and keyboard shortcuts for the "print selected" command.*/ fileMenu.add(createMenuItem(new AbstractAction("Print Selected") { public void actionPerformed(ActionEvent e) { printSelectedPages(); } }, KeyEvent.VK_P, KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK))); /** Menu item and keyboard shortcuts for the "clear selected" command.*/ fileMenu.add(createMenuItem(new AbstractAction("Clear Selected") { public void actionPerformed(ActionEvent e) { DefaultListModel pages = (DefaultListModel) selectedPages.getModel(); pages.removeAllElements(); } }, KeyEvent.VK_C, KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK))); fileMenu.addSeparator(); /** Menu item and keyboard shortcuts for the "home page" command. */ fileMenu.add(createMenuItem(new AbstractAction("Home Page") { public void actionPerformed(ActionEvent e) { setPage(homePage); } }, KeyEvent.VK_H, KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK))); /** Menu item and keyboard shortcuts for the "quit" command. */ fileMenu.add(createMenuItem(new AbstractAction("Quit") { public void actionPerformed(ActionEvent e) { for (Window w : Window.getWindows()) { w.dispose(); } } }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK))); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); JPanel contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentPane.add(pane); contentPane.add(messageArea); JFrame frame = new JFrame("Text Batch Printing Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(menuBar); frame.setContentPane(contentPane); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); if (printService == null) { // Actual printing is not possible, issue a warning message. JOptionPane.showMessageDialog(frame, "No default print service", "Print Service Alert", JOptionPane.WARNING_MESSAGE); } }