List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction(String name)
From source file:Main.java
public Main() { list.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); JPanel panel = new JPanel(); panel.add(new JButton(new AbstractAction("Add") { @Override//from ww w .j ava2s . c o m public void actionPerformed(ActionEvent e) { append(); if (count <= N) { list.setVisibleRowCount(count); dlg.pack(); } } })); panel.add(new JButton(new AbstractAction("Remove") { @Override public void actionPerformed(ActionEvent e) { int itemNo = list.getSelectedIndex(); if (itemNo > -1) { removeActionPerformed(e, itemNo); } } })); for (int i = 0; i < N - 2; i++) { this.append(); } list.setVisibleRowCount(N - 2); dlg.add(sp, BorderLayout.CENTER); dlg.add(panel, BorderLayout.SOUTH); dlg.pack(); dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dlg.setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);// w ww . j ava 2 s.c om menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new AbstractAction("Exit") { @Override public void actionPerformed(ActionEvent arg0) { System.out.println("action"); } }); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); }
From source file:org.jfreechart.SVGExporter.java
public static Action createExportAction(final JFreeChart chart, final JPanel bounds) { return new AbstractAction("Save as SVG...") { public void actionPerformed(ActionEvent e) { try { JFileChooser fc = new JFileChooser(); fc.showSaveDialog(null); if (fc.getSelectedFile() != null) { exportChartAsSVG(chart, bounds.getBounds(), fc.getSelectedFile()); }/* w w w . j a v a 2 s .co m*/ } catch (IOException ex) { ex.printStackTrace(); } } }; }
From source file:MainClass.java
MainClass(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToolBar toolBar = new JToolBar(); Action a = new AbstractAction("Demo") { public void actionPerformed(ActionEvent e) { System.out.println("Action taken."); }// w w w . j av a 2 s . co m }; JButton b = toolBar.add(a); b.setText("Demo Button"); b.setToolTipText("Press me to take action."); JMenu mainMenu = new JMenu("Menu"); JMenuItem mi = mainMenu.add(a); mi.getAccessibleContext().setAccessibleName("Menu item"); JMenuBar mb = new JMenuBar(); mb.add(mainMenu); setJMenuBar(mb); JPanel pane = new JPanel(); pane.setLayout(new BorderLayout()); pane.setPreferredSize(new Dimension(200, 100)); pane.add(toolBar, BorderLayout.NORTH); setContentPane(pane); pack(); setVisible(true); }
From source file:Main.java
/** * Initialises the {@link JDialog} for the {@link JComponent}. * //from w w w. j av a 2 s . c om * @param dialog * @param component * @param parentComponent */ private static void initDialog(final JDialog dialog, final JComponent component, final Component parentComponent) { dialog.setResizable(true); dialog.setComponentOrientation(component.getComponentOrientation()); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(component, BorderLayout.CENTER); final int buttonWidth = 75; final JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 4, 4)); buttonPanel.add(Box.createHorizontalGlue()); @SuppressWarnings("serial") final Action closeAction = new AbstractAction("Close") { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; final JButton button = new JButton(closeAction); fixWidth(button, buttonWidth); buttonPanel.add(button); contentPane.add(buttonPanel, BorderLayout.SOUTH); if (JDialog.isDefaultLookAndFeelDecorated()) { boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations(); if (supportsWindowDecorations) { dialog.setUndecorated(true); component.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); } } dialog.pack(); dialog.setLocationRelativeTo(parentComponent); WindowAdapter adapter = new WindowAdapter() { // private boolean gotFocus = false; public void windowClosing(WindowEvent we) { fireAction(we.getSource(), closeAction, "close"); } }; dialog.addWindowListener(adapter); dialog.addWindowFocusListener(adapter); }
From source file:Main.java
@SuppressWarnings("serial") public static void installUndoManager(JTextComponent textComponent, final UndoManager undoManager) { Document doc = textComponent.getDocument(); doc.addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { undoManager.addEdit(e.getEdit()); }// w w w .jav a2 s. co m }); ActionMap am = textComponent.getActionMap(); InputMap im = textComponent.getInputMap(); am.put("undo", new AbstractAction("undo") { @Override public void actionPerformed(ActionEvent e) { undoManager.undo(); } @Override public boolean isEnabled() { return undoManager.canUndo(); } }); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, getMenuShortcutKeyMask()), "undo"); am.put("redo", new AbstractAction("redo") { @Override public void actionPerformed(ActionEvent e) { undoManager.redo(); } @Override public boolean isEnabled() { return undoManager.canRedo(); } }); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_Y, getMenuShortcutKeyMask()), "redo"); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);// w ww . j a v a 2 s. co m menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); menu.insert(new AbstractAction("Action") { @Override public void actionPerformed(ActionEvent arg0) { } }, 0); }
From source file:Main.java
Main() { gui.setBorder(new EmptyBorder(2, 3, 2, 3)); String userDirLocation = System.getProperty("user.dir"); File userDir = new File(userDirLocation); // default to user directory fileChooser = new JFileChooser(userDir); Action open = new AbstractAction("Open") { @Override/*from w w w . j a va 2s. co m*/ public void actionPerformed(ActionEvent e) { int result = fileChooser.showOpenDialog(gui); if (result == JFileChooser.APPROVE_OPTION) { try { File f = fileChooser.getSelectedFile(); FileReader fr = new FileReader(f); output.read(fr, f); fr.close(); } catch (Exception ex) { ex.printStackTrace(); } } } }; Action save = new AbstractAction("Save") { @Override public void actionPerformed(ActionEvent e) { int result = fileChooser.showSaveDialog(gui); System.out.println("Not supported yet."); } }; JToolBar tb = new JToolBar(); gui.add(tb, BorderLayout.PAGE_START); tb.add(open); tb.add(save); gui.add(new JScrollPane(output)); }
From source file:Main.java
public Main(JFrame frame) { analyzer = new MyDialog(frame); analyzer.pack();//from w w w . j a v a 2s. c o m analyzer.setLocationRelativeTo(frame); Point location = analyzer.getLocation(); location = new Point(location.x - LOC_SHIFT, location.y - LOC_SHIFT); analyzer.setLocation(location); analyzer.setVisible(true); add(new JButton(new AbstractAction(DISABLE_DIALOG_COMPONENTS) { @Override public void actionPerformed(ActionEvent evt) { AbstractButton btn = (AbstractButton) evt.getSource(); if (btn.getText().equals(DISABLE_DIALOG_COMPONENTS)) { btn.setText(ENABLE_DIALOG_COMPONENTS); analyzer.setComponentEnabled(false); } else { btn.setText(DISABLE_DIALOG_COMPONENTS); analyzer.setComponentEnabled(true); } } })); add(new JButton(new AbstractAction(DISABLE_DIALOG) { @Override public void actionPerformed(ActionEvent evt) { AbstractButton btn = (AbstractButton) evt.getSource(); if (btn.getText().equals(DISABLE_DIALOG)) { btn.setText(ENABLE_DIALOG); analyzer.setEnabled(false); } else { btn.setText(DISABLE_DIALOG); analyzer.setEnabled(true); } } })); }
From source file:Main.java
public JComponent makeUI() { UIManager.put("TabbedPane.tabInsets", new Insets(2, 2, 2, 50)); final JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab("A", new JPanel()); JPanel p = new JPanel(new BorderLayout()); p.add(new JLayer<JTabbedPane>(tabbedPane, new CloseableTabbedPaneLayerUI())); p.add(new JButton(new AbstractAction("add tab") { @Override/*from www . ja v a 2s. c o m*/ public void actionPerformed(ActionEvent e) { tabbedPane.addTab("test", new JPanel()); } }), BorderLayout.SOUTH); return p; }