List of usage examples for javax.swing JButton JButton
public JButton(Action a)
Action
supplied. From source file:TabbedPaneTest.java
public static void main(String args[]) { JFrame frame = new JFrame("JTabbedPane"); final Container contentPane = frame.getContentPane(); JTabbedPane jtp = new JTabbedPane(); contentPane.add(jtp, BorderLayout.CENTER); for (int i = 0; i < 5; i++) { JButton button = new JButton("Card " + i); jtp.add("Btn " + i, button); }//from w ww. ja v a2 s. c om frame.setSize(300, 200); frame.show(); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setSize(300, 200);//from w ww .ja v a 2s . co m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton redButton = new JButton("Red"); JButton greenButton = new JButton("Green"); JButton blueButton = new JButton("Blue"); class Listener extends JPanel implements ActionListener { public void actionPerformed(ActionEvent event) { Color color; if (event.getSource() == redButton) { color = Color.red; redButton.setBackground(color); panel.setBackground(color); } else if (event.getSource() == greenButton) { color = Color.green; greenButton.setBackground(color); panel.setBackground(color); } else { color = Color.blue; blueButton.setBackground(color); panel.setBackground(color); } setBackground(color); repaint(); } } redButton.addActionListener(new Listener()); greenButton.addActionListener(new Listener()); blueButton.addActionListener(new Listener()); panel.add(redButton); panel.add(greenButton); panel.add(blueButton); frame.add(panel); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Color Matted Border"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border solidBorder = new MatteBorder(10, 5, 2, 20, Color.RED); JButton solidButton = new JButton("10x5x2x20"); solidButton.setBorder(solidBorder);//from w w w .j a v a 2s . c o m Container contentPane = frame.getContentPane(); contentPane.add(solidButton, BorderLayout.CENTER); frame.setSize(300, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JScrollPane sPane = new JScrollPane(); sPane.setPreferredSize(new Dimension(200, 150)); JButton button = new JButton(new AbstractAction("Create Table") { public void actionPerformed(ActionEvent arg0) { DefaultTableModel model = new DefaultTableModel(new Integer[][] { { 1, 2 }, { 3, 4 } }, new String[] { "A", "B" }); JTable table = new JTable(model); sPane.getViewport().add(table); }//from w w w . j a v a 2 s .co m }); JPanel panel = new JPanel(); panel.add(sPane); panel.add(button); JOptionPane.showMessageDialog(null, panel); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JButton counterButton = new JButton("Clicked #0"); JButton closeButton = new JButton("Close"); frame.setLayout(new FlowLayout()); contentPane.add(closeButton);/*from ww w.ja v a 2s .c om*/ contentPane.add(counterButton); counterButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { counterButton.setText("Clicked #" + counter++); } }); closeButton.addActionListener(e -> System.exit(0)); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { final JFrame frame = new JFrame("GridBagLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridBagLayout()); JButton button;/*from w ww . j ava2 s. c o m*/ button = new JButton("One"); addComponent(frame, button, 0, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE); button = new JButton("Two"); addComponent(frame, button, 1, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE); button = new JButton("Three"); addComponent(frame, button, 0, 1, 2, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE); button = new JButton("Four"); addComponent(frame, button, 0, 2, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE); frame.setSize(500, 200); frame.setVisible(true); }
From source file:JSplitPaneVerticalSetTopBottom.java
public static void main(String[] a) { JFrame horizontalFrame = new JFrame(); horizontalFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComponent topButton = new JButton("Left"); JComponent bottomButton = new JButton("Right"); final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); HierarchyListener hierarchyListener = new HierarchyListener() { public void hierarchyChanged(HierarchyEvent e) { long flags = e.getChangeFlags(); System.out.println(e.getSource()); if ((flags & HierarchyEvent.SHOWING_CHANGED) == HierarchyEvent.SHOWING_CHANGED) { splitPane.setDividerLocation(.75); }/* www .j a va 2s . c om*/ } }; splitPane.addHierarchyListener(hierarchyListener); splitPane.setTopComponent(topButton); splitPane.setBottomComponent(bottomButton); horizontalFrame.add(splitPane, BorderLayout.CENTER); horizontalFrame.setSize(150, 150); horizontalFrame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JDesktopPane dp = new JDesktopPane(); JInternalFrame inf = new JInternalFrame("Help", true, true, true, true); inf.setSize(200, 200);//from ww w.jav a 2s . c o m inf.setVisible(true); dp.add(inf); JButton btn = new JButton("Click"); btn.addActionListener(e -> JOptionPane.showInternalInputDialog(inf, "Hit me")); inf.add(btn); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new BorderLayout()); f.add(dp); f.setSize(400, 400); f.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("DefaultButton"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(2, 2, 10, 10)); JButton button1 = new JButton("Text Button"); button1.setMnemonic(KeyEvent.VK_B); frame.add(button1);// ww w .jav a2 s . c o m JButton button2 = new JButton("warn"); frame.add(button2); JButton button3 = new JButton("Warning"); frame.add(button3); String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>" + "<font color=\"#FF0080\"><u>Multi-line</u></font>"; JButton button4 = new JButton(htmlButton); frame.add(button4); JRootPane rootPane = frame.getRootPane(); rootPane.setDefaultButton(button2); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String title = "GridBagLayout"; JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridBagLayout()); for (int i = 1; i <= 9; i++) { contentPane.add(new JButton("Button " + i)); }//w ww .j av a2 s . com frame.pack(); frame.setVisible(true); }