List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction(String name)
From source file:Main.java
public Main() { JRadioButton radMarriedYes = new JRadioButton(new AbstractAction("Yes") { @Override// ww w .j ava 2s .c om public void actionPerformed(ActionEvent arg0) { } }); JRadioButton radMarriedNo = new JRadioButton("No?", false); JRadioButton radGolfYes = new JRadioButton("Yes?", false); JRadioButton radGolfNo = new JRadioButton("No?", true); ButtonGroup radioGroup1 = new ButtonGroup(); ButtonGroup radioGroup2 = new ButtonGroup(); setLayout(null); add(radMarriedYes); add(radMarriedNo); add(radGolfYes); add(radGolfNo); radioGroup1.add(radMarriedYes); radioGroup1.add(radMarriedNo); radioGroup2.add(radGolfYes); radioGroup2.add(radGolfNo); radMarriedYes.setBounds(30, 50, 50, 20); radMarriedNo.setBounds(30, 80, 50, 20); radGolfYes.setBounds(150, 50, 50, 20); radGolfNo.setBounds(150, 80, 50, 20); }
From source file:Main.java
public Main() { this.setLayout(new GridLayout(0, 1)); this.add(new JLabel("Dialog close test.", JLabel.CENTER)); this.add(new JButton(new AbstractAction("Close") { @Override// w w w . j a v a 2 s .com public void actionPerformed(ActionEvent e) { Main.this.setVisible(false); Main.this.dispatchEvent(new WindowEvent(Main.this, WindowEvent.WINDOW_CLOSING)); } })); }
From source file:Main.java
public static void associaTeclaAtalho(final AbstractButton button, String nomeAcao, String... atalhos) { Action action = new AbstractAction(nomeAcao) { @Override//from ww w . j a va 2s . co m public void actionPerformed(ActionEvent e) { for (ActionListener listener : button.getActionListeners()) { listener.actionPerformed(e); } } }; associaTeclaAtalho(button, action, nomeAcao, atalhos); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu(new AbstractAction("File") { @Override// w w w . j a v a 2s . c o m public void actionPerformed(ActionEvent arg0) { System.out.println("action"); } }); bar.add(menu); 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:Main.java
public Main() { this.setLayout(new GridLayout(0, 1)); this.add(new JLabel("Dialog event test.", JLabel.CENTER)); this.add(new JButton(new AbstractAction("Close") { @Override//from w w w .ja v a 2s . co m public void actionPerformed(ActionEvent e) { Main.this.setVisible(false); Main.this.dispatchEvent(new WindowEvent(Main.this, WindowEvent.WINDOW_CLOSING)); } })); this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.out.println(e.paramString()); } }); }
From source file:Main.java
public Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); JButton openDialog = new JButton("Click here"); JPanel myPanel = new JPanel(); myPanel.add(new JButton(new AbstractAction("Click here") { @Override//from w w w . j a v a 2 s .co m public void actionPerformed(ActionEvent e) { JDialog dialog = new JDialog(myFrame, true); JTextField myField = new JTextField(10); JPanel innerPanel = new JPanel(); innerPanel.add(myField); dialog.add(innerPanel); dialog.pack(); dialog.setSize(new Dimension(160, 120)); dialog.setLocationRelativeTo(myFrame); dialog.setVisible(true); } })); add(myPanel); pack(); setSize(new Dimension(320, 240)); setLocationRelativeTo(null); setVisible(true); }
From source file:Main.java
public Main() { this.setLayout(new GridLayout(0, 1)); this.add(label); this.add(new JButton(new AbstractAction("OK") { @Override/* w ww .j av a 2 s . co m*/ public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); b.setText("123"); } })); new Timer(100, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { label.setText(String.valueOf(System.nanoTime())); } }).start(); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); bar.add(menu);//from www .j ava2s.c o m 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:Main.java
private void display() { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JButton(new AbstractAction("<Prev") { @Override/*from w w w . j a v a 2 s. c om*/ public void actionPerformed(ActionEvent e) { if (--index < 0) { index = list.size() - 1; } update(); } }), BorderLayout.LINE_START); f.add(label); f.add(new JButton(new AbstractAction("Next>") { @Override public void actionPerformed(ActionEvent e) { if (++index == list.size()) { index = 0; } update(); } }), BorderLayout.LINE_END); f.pack(); f.setVisible(true); }
From source file:Main.java
public static boolean showModalDialogOnEDT(JComponent contents, String title, String okButtonMessage, String cancelButtonMessage, ModalityType modalityType, final boolean systemExitOnDisposed) { class Result { boolean OK = false; }/*from ww w . j ava 2s . c o m*/ final Result result = new Result(); final JDialog dialog = new JDialog((Frame) null, title, true) { @Override public void dispose() { super.dispose(); if (systemExitOnDisposed) { System.exit(0); } } }; // ensure it doesn't block other dialogs if (modalityType != null) { dialog.setModalityType(modalityType); } // See http://stackoverflow.com/questions/1343542/how-do-i-close-a-jdialog-and-have-the-window-event-listeners-be-notified dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); if (okButtonMessage != null) { buttonPane.add(new JButton(new AbstractAction(okButtonMessage) { @Override public void actionPerformed(ActionEvent e) { result.OK = true; dialog.dispose(); } })); } if (cancelButtonMessage != null) { buttonPane.add(new JButton(new AbstractAction(cancelButtonMessage) { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } })); } JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.setLayout(new BorderLayout()); panel.add(contents, BorderLayout.CENTER); panel.add(buttonPane, BorderLayout.SOUTH); // startup frame dialog.getContentPane().add(panel); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.pack(); // This hopefully centres the dialog even though the parameter is null // see http://stackoverflow.com/questions/213266/how-do-i-center-a-jdialog-on-screen dialog.setLocationRelativeTo(null); dialog.setVisible(true); return result.OK; }