List of usage examples for javax.swing JButton JButton
public JButton(Action a)
Action
supplied. From source file:MainClass.java
public static void main(String[] a) { JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("Set Message"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); optionPane.setOptions(new Object[] { new JButton("Button") }); JDialog dialog = optionPane.createDialog(null, "Icon/Text Button"); dialog.setVisible(true);/*from w w w .j a v a 2s. c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTabbedPane pane = new JTabbedPane(); pane.setForeground(Color.YELLOW); pane.setBackground(Color.MAGENTA); String label = "Tab Label"; pane.addTab(label, new JButton("Button")); int index = pane.getTabCount() - 1; pane.setForegroundAt(index, Color.ORANGE); pane.setBackgroundAt(index, Color.GREEN); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(new JButton("A")); frame.add(buttonPanel);// w w w. j av a2 s .c om frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); JButton jb1 = new JButton("Hello"); ButtonModel bm = jb1.getModel(); JButton jb2 = new JButton("World"); jb2.setModel(bm);// w w w . j a v a 2 s . c o m Container c = f.getContentPane(); c.add(jb1, BorderLayout.NORTH); c.add(jb2, BorderLayout.SOUTH); jb1.addActionListener(new MessageActionListener("Selected One")); jb2.addActionListener(new MessageActionListener("Selected Two")); f.pack(); f.show(); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Bring me to top after 3 seconds"); button.addActionListener(e -> triggerBringToFront(f, 3000)); f.getContentPane().add(button);/* w w w .j a v a2 s . c o m*/ f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("DefaultButton"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Icon warnIcon = new ImageIcon("yourFile.gif"); JButton button2 = new JButton(warnIcon); frame.add(button2);// ww w .jav a2s . c o m frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel buttonPanel = new JPanel(new FlowLayout(), true); buttonPanel.add(new JButton("A")); frame.add(buttonPanel);/*w w w . ja va2s . c o m*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(); panel.add(new JTextField(10)); panel.add(new JButton("button")); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel);/*from w ww . ja v a2s . co m*/ frame.pack(); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { @Override public void windowIconified(WindowEvent wEvt) { ((JFrame) wEvt.getSource()).dispose(); } @Override public void windowDeactivated(WindowEvent wEvt) { ((JFrame) wEvt.getSource()).dispose(); } }); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl);/*from www . j a v a2 s . co m*/ JButton component = new JButton("1"); frame.add(component); frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.NONE; gbl.setConstraints(component, gbc); frame.add(component); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl);/*from www.ja v a2s .c o m*/ JButton component = new JButton("1"); frame.add(component); frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.weightx = 1; gbc.weighty = 2; gbl.setConstraints(component, gbc); frame.pack(); frame.setVisible(true); }