package experiments; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; public class CreateDialogFromOptionPane { public static void main(final String[] args) { final JFrame parent = new JFrame(); JButton button = new JButton(); button.setText("Click me to show dialog!"); parent.add(button); parent.pack(); parent.setVisible(true); button.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { String name = JOptionPane.showInputDialog(parent, "What is your name?", null); } }); } }
gui.add(container, BorderLayout.CENTER); container.add(tb, BorderLayout.NORTH); for (int ii=0; ii<3; ii++) { tb.add(new JButton("Button")); enable.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent ae) {
buttons.add( game ); buttons.add( highScores ); gui.add(buttons, BorderLayout.SOUTH); game.addActionListener(al); highScores.addActionListener(al);
AbstractButton b = (AbstractButton) option; removeOldListeners(b); b.addActionListener(l); JButton b = new JButton(text);
import java.awt.event.*; import javax.swing.*; public class YourDialog extends JDialog implements ActionListener { JButton button; public YourDialog() { button = new JButton("Close"); button.addActionListener(this); add(button); pack(); setVisible(true); } public void actionPerformed(ActionEvent e) { dispose(); } }
JFreeChart chart = createChart(dataset); final JButton run = new JButton(STOP); run.addActionListener(new ActionListener() { btnPanel.add(run); btnPanel.add(combo); this.add(btnPanel, BorderLayout.SOUTH);
final JFrame frame = new JFrame("Nested Layout Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); plafComponents.add(plafChooser); plafComponents.add(pack); SwingUtilities.updateComponentTreeUI(frame); if (pack.isSelected()) { frame.pack(); frame.setMinimumSize(frame.getSize()); gui.add(plafComponents, BorderLayout.NORTH); new TitledBorder("GridLayout(0,2,3,3)") ); JButton addNew = new JButton("Add Another Label"); dynamicLabels.add( addNew, BorderLayout.NORTH ); addNew.addActionListener( new ActionListener(){ frame.pack(); frame.setVisible(true);
public LogFactor5ErrorDialog(JFrame jframe, String message) { super(jframe, "Error", true); JButton ok = new JButton("Ok"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { hide(); } }); JPanel bottom = new JPanel(); bottom.setLayout(new FlowLayout()); bottom.add(ok); JPanel main = new JPanel(); main.setLayout(new GridBagLayout()); wrapStringOnPanel(message, main); getContentPane().add(main, BorderLayout.CENTER); getContentPane().add(bottom, BorderLayout.SOUTH); show(); } //--------------------------------------------------------------------------
this.panel = new JPanel(); this.panel.setLayout(new FlowLayout()); add(panel, BorderLayout.CENTER); JButton button = new JButton("CLICK HERE"); add(button, BorderLayout.SOUTH); button.addActionListener(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 500); setVisible(true); this.panel.add(new JButton("Button")); this.panel.revalidate(); validate();
private JButton copyButton = new JButton("Copy text from JTextFields"); private CopyTextControl2 control; copyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (control != null) { add(firstText); add(copyButton);
private JButton m_multiplyBtn = new JButton("Multiply"); private JButton m_clearBtn = new JButton("Clear"); content.add(new JLabel("Input")); content.add(m_userInputTf); content.add(m_multiplyBtn); content.add(new JLabel("Total")); content.add(m_totalTf); this.pack(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); m_multiplyBtn.addActionListener(mal); m_clearBtn.addActionListener(cal);
final JScrollPane scroll = new JScrollPane(panel); scroll.setPreferredSize(new Dimension(80,100)); gui.add(scroll, BorderLayout.CENTER); JButton addLabel = new JButton("Add Label"); gui.add(addLabel, BorderLayout.NORTH); ActionListener listener = new ActionListener() { int counter = 0; public void actionPerformed(ActionEvent ae) { panel.add(new JLabel("Label " + ++counter)); panel.revalidate(); int height = (int)panel.getPreferredSize().getHeight(); addLabel.addActionListener(listener); JOptionPane.showMessageDialog(null, gui);
final JFrame frame = new JFrame(); final JTextField textFieldB = new HintTextField("Another hint here"); frame.add(textFieldA, BorderLayout.NORTH); frame.add(textFieldB, BorderLayout.CENTER); JButton btnGetText = new JButton("Get text"); btnGetText.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.add(btnGetText, BorderLayout.SOUTH); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); frame.pack();
JScrollPane scroll = new JScrollPane(panel); scroll.setPreferredSize(new Dimension(80,100)); gui.add(scroll, BorderLayout.CENTER); JButton addLabel = new JButton("Add Label"); gui.add(addLabel, BorderLayout.NORTH); ActionListener listener = new ActionListener() { int counter = 0; public void actionPerformed(ActionEvent ae) { panel.add(new JLabel("Label " + ++counter)); panel.revalidate(); int height = (int)panel.getPreferredSize().getHeight(); addLabel.addActionListener(listener); JOptionPane.showMessageDialog(null, gui);
JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); JButton saveBtn = new JButton("Save"); JButton openBtn = new JButton("Open"); saveBtn.addActionListener(new ActionListener() { openBtn.addActionListener(new ActionListener() { frame.add(new JLabel("File Chooser"), BorderLayout.NORTH); frame.add(saveBtn, BorderLayout.CENTER); frame.add(openBtn, BorderLayout.SOUTH); frame.setTitle("File Chooser"); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);
JButton button = new JButton(new ImageIcon(icon)); button.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent ae) { p.add(button); } else { JLabel label = new JLabel(new ImageIcon(icon)); p.add(label); center.add(p); JOptionPane.showMessageDialog(null, center);
JFrame frame = new JFrame(); frame.setTitle("Welcome!"); frame.setSize(520, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel heroShotPanel = new JPanel(); JLabel heroShot = new JLabel(heroShotImage); heroShotPanel.add(heroShot); JButton start = new JButton("Start"); start.setToolTipText("Click to use library"); start.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { submitPanel.add(start); frame.getContentPane().add(heroShotPanel, BorderLayout.NORTH); frame.getContentPane().add(submitPanel, BorderLayout.SOUTH); frame.setVisible(true); frame.getRootPane().setDefaultButton(start); start.requestFocus();
JButton newButton = new JButton("Clear Log Table"); newButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { tb.add(new JLabel(" Font: ")); tb.add(fontCombo); tb.add(fontSizeCombo); tb.addSeparator(); tb.addSeparator();
Runnable r = new Runnable() { public void run() { final JFrame f = new JFrame("Test Screenshot"); InputEvent.CTRL_DOWN_MASK )); screenshot.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent ae) { p.add( new JScrollPane(new JTree()), BorderLayout.WEST ); p.add( new JScrollPane( new JTextArea(HELP,10,30) ), BorderLayout.CENTER ); f.pack(); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true);
JButton next = new JButton(">"); next.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent ae) { int height = table.getRowHeight()*(rows-1); JButton previous = new JButton("<"); previous.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent ae) { int height = table.getRowHeight()*(rows-1); navigation.add(previous); navigation.add(next); gui.add(scrollPane, BorderLayout.CENTER); gui.add(navigation, BorderLayout.SOUTH);