List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction(String name)
From source file:Main.java
public static void main(String[] argv) throws Exception { JButton component = new JButton("Button"); component.getInputMap().put(KeyStroke.getKeyStroke("F2"), "actionName"); component.getInputMap().put(KeyStroke.getKeyStroke("control A"), "actionName"); component.getInputMap().put(KeyStroke.getKeyStroke("shift F2"), "actionName"); component.getInputMap().put(KeyStroke.getKeyStroke('('), "actionName"); component.getInputMap().put(KeyStroke.getKeyStroke("button3 F"), "actionName"); component.getInputMap().put(KeyStroke.getKeyStroke("typed x"), "actionName"); component.getInputMap().put(KeyStroke.getKeyStroke("released DELETE"), "actionName"); component.getInputMap().put(KeyStroke.getKeyStroke("shift UP"), "actionName"); component.getActionMap().put("actionName", new AbstractAction("actionName") { public void actionPerformed(ActionEvent evt) { System.out.println(evt); }//from w w w. java 2s . c o m }); }
From source file:Main.java
public static void main(String[] argv) { JTextComponent textcomp = new JTextArea(); final UndoManager undo = new UndoManager(); Document doc = textcomp.getDocument(); doc.addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { undo.addEdit(evt.getEdit()); }// w w w. ja va2 s . c o m }); textcomp.getActionMap().put("Undo", new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { try { if (undo.canUndo()) { undo.undo(); } } catch (CannotUndoException e) { } } }); textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo"); textcomp.getActionMap().put("Redo", new AbstractAction("Redo") { public void actionPerformed(ActionEvent evt) { try { if (undo.canRedo()) { undo.redo(); } } catch (CannotRedoException e) { } } }); textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo"); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(textcomp)); frame.setSize(380, 320); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { BoundedRangeModel model = new DefaultBoundedRangeModel(); BlockedColorLayerUI layerUI = new BlockedColorLayerUI(); JPanel p = new JPanel(new GridLayout(2, 1, 12, 12)); p.add(new JLayer<JProgressBar>(new JProgressBar(model), layerUI)); JPanel box = new JPanel(); box.add(new JButton(new AbstractAction("+10") { private int i = 0; @Override//from w w w. j a v a 2s .co m public void actionPerformed(ActionEvent e) { model.setValue(i = (i >= 100) ? 0 : i + 10); } })); p.repaint(); JPanel panel = new JPanel(new BorderLayout()); panel.add(p, BorderLayout.NORTH); panel.add(box, BorderLayout.SOUTH); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(panel); f.setSize(320, 240); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextComponent textcomp = new JTextArea(); final UndoManager undo = new UndoManager(); Document doc = textcomp.getDocument(); JFrame f = new JFrame(); f.add(new JScrollPane(textcomp)); f.setSize(330, 300);/*from w w w .j a v a 2 s . c o m*/ f.setVisible(true); doc.addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { undo.addEdit(evt.getEdit()); } }); textcomp.getActionMap().put("Undo", new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { try { if (undo.canUndo()) { undo.undo(); } } catch (CannotUndoException e) { } } }); textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo"); textcomp.getActionMap().put("Redo", new AbstractAction("Redo") { public void actionPerformed(ActionEvent evt) { try { if (undo.canRedo()) { undo.redo(); } } catch (CannotRedoException e) { } } }); textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo"); }
From source file:Main.java
public static void main(String[] args) throws Exception { Toolkit tk = Toolkit.getDefaultToolkit(); final Main main = new Main(); tk.addAWTEventListener(main, AWTEvent.WINDOW_EVENT_MASK); final JFrame frame = new JFrame(""); frame.setName("your frame"); JMenuBar mb = new JMenuBar(); JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Quit") { public void actionPerformed(ActionEvent evt) { try { main.saveSettings();// w w w . j a v a 2 s. c om System.exit(0); } catch (Exception ex) { System.out.println(ex); } } }); mb.add(menu); frame.setJMenuBar(mb); frame.pack(); frame.setVisible(true); }
From source file:com.moss.appprocs.swing.ProgressMonitorPanel.java
/** * Not useful beyond testing this class. *//* w w w .ja va2 s.c o m*/ @SuppressWarnings("serial") public static void main(String[] args) throws Exception { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); Action a = new AbstractAction("Do Something") { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "Hi"); } }; JFrame window = new JFrame("Test"); ProgressMonitorPanel panel = new ProgressMonitorPanel(true); panel.addNonPersistentProcess(new TestProcess()); panel.addNonPersistentProcess(new TestProcess()); panel.addNonPersistentProcess(new TrackableTestProcess()); panel.addNonPersistentProcess(new TestProcess()); panel.addPersistentProcess(new TrackableTestProcess(), a); // // JPanel panel = new JPanel(); // panel.add(new JLabel("Howdy")); // panel.setBorder(new LineBorder(Color.BLUE, 5)); window.getContentPane().add(panel); window.setSize(400, 800); window.setVisible(true); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:com.google.code.facebook.graph.sna.applet.GraphEditorDemo.java
/** * a driver for this demo//from w w w .j a va2s .com */ @SuppressWarnings("serial") public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final GraphEditorDemo demo = new GraphEditorDemo(); JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Make Image") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeJPEGImage(file); } } }); menu.add(new AbstractAction("Print") { public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(demo); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception ex) { ex.printStackTrace(); } } } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); }
From source file:external.jung.demo.GraphEditorDemo.java
/** * a driver for this demo// ww w . j av a 2s . c om */ @SuppressWarnings("serial") public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final GraphEditorDemo demo = new GraphEditorDemo(); JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Make Image") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeJPEGImage(file); } } }); menu.add(new AbstractAction("Print") { public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(demo); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception ex) { ex.printStackTrace(); } } } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void bindUndoManager(final JTextComponent text, final UndoManager undo) { text.getDocument().addUndoableEditListener(new UndoableEditListener() { @Override//from ww w.j a v a2 s. c o m public void undoableEditHappened(UndoableEditEvent e) { undo.addEdit(e.getEdit()); } }); text.getActionMap().put("Undo", new AbstractAction("Undo") { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent evt) { try { if (undo.canUndo()) { undo.undo(); } } catch (CannotUndoException e) { } } }); // Bind the undo action to ctl-Z text.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo"); // Create a redo action and add it to the text component text.getActionMap().put("Redo", new AbstractAction("Redo") { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent evt) { try { if (undo.canRedo()) { undo.redo(); } } catch (CannotRedoException e) { } } }); // Bind the redo action to ctl-Y text.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo"); }
From source file:GraphEditorDemo.java
/** * a driver for this demo//from w ww.ja va 2 s.c o m */ @SuppressWarnings("serial") public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final GraphEditorDemo demo = new GraphEditorDemo(); JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Make Image") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeJPEGImage(file); } } }); menu.add(new AbstractAction("Print") { public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(demo); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception ex) { ex.printStackTrace(); } } } }); menu.add(new AbstractAction("Save") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeTopologyFile(file); } } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); }