List of usage examples for javax.swing JButton JButton
public JButton(Action a)
Action
supplied. From source file:RelativeXY.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 1;// w ww .j a va 2 s . c o m gbc.gridy = GridBagConstraints.RELATIVE; pane.add(new JButton("First row, first column"), gbc); pane.add(new JButton("Second row"), gbc); pane.add(new JButton("Third row"), gbc); gbc.gridx = GridBagConstraints.RELATIVE; pane.add(new JButton("First row, second column"), gbc); f.setSize(500, 300); f.setVisible(true); }
From source file:AnEtchedBorder.java
public static void main(String args[]) { JFrame frame = new JFrame("Etched Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED); Border loweredBorder = new EtchedBorder(EtchedBorder.LOWERED); JButton raisedButton = new JButton("Raised"); raisedButton.setBorder(raisedBorder); JButton loweredButton = new JButton("Lowered"); loweredButton.setBorder(loweredBorder); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(1, 2, 5, 5)); contentPane.add(raisedButton);/* w w w . j a v a2 s .c o m*/ contentPane.add(loweredButton); frame.setSize(300, 100); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Justified Titled Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border myRaisedBorder = BorderFactory.createBevelBorder(BevelBorder.RAISED, Color.PINK, Color.RED); JButton myRaisedButton = new JButton("My Raised"); myRaisedButton.setBorder(myRaisedBorder); Container contentPane = frame.getContentPane(); contentPane.add(myRaisedButton);//from www. j ava2 s. c o m frame.setSize(300, 200); frame.setVisible(true); }
From source file:ButtonListener.java
public static void main(String[] a) { JFrame frame = new JFrame("Popup JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton source = new JButton("Ring the bell!"); source.addActionListener(new ButtonListener()); frame.add(source, BorderLayout.SOUTH); source.addActionListener(new ButtonListener()); frame.setSize(300, 200);//w ww . j a v a 2s. c o m frame.setVisible(true); }
From source file:GridBagLayoutFill.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0;//from w w w . j av a2 s . co m gbc.gridy = GridBagConstraints.RELATIVE; pane.add(new JButton("This button's preferred width " + "is large because its text is long"), gbc); pane.add(new JButton("Small centered button"), gbc); gbc.fill = GridBagConstraints.HORIZONTAL; pane.add(new JButton("Expands to fill column width"), gbc); f.setSize(400, 300); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("GroupLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); GroupLayout groupLayout = new GroupLayout(contentPane); contentPane.setLayout(groupLayout);/* w ww . j a v a2s. c om*/ JLabel label = new JLabel("Label"); JButton b2 = new JButton("Second Button"); groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup().addComponent(label).addComponent(b2)); groupLayout.setVerticalGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label).addComponent(b2)); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Soft Bevel Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = new SoftBevelBorder(SoftBevelBorder.RAISED); Border loweredBorder = new SoftBevelBorder(SoftBevelBorder.LOWERED); JButton raisedButton = new JButton("Raised"); raisedButton.setBorder(raisedBorder); JButton loweredButton = new JButton("Lowered"); loweredButton.setBorder(loweredBorder); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(1, 2)); contentPane.add(raisedButton);/*from w ww .j a va 2s. c o m*/ contentPane.add(loweredButton); frame.setSize(300, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("GroupLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); GroupLayout groupLayout = new GroupLayout(contentPane); contentPane.setLayout(groupLayout);/*from w ww .j a va 2s .c o m*/ JLabel label = new JLabel("Label"); JButton b2 = new JButton("Second Button"); groupLayout.setHorizontalGroup( groupLayout.createSequentialGroup().addComponent(label).addGap(5, 10, 50).addComponent(b2)); groupLayout.setVerticalGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label).addComponent(b2)); frame.pack(); frame.setVisible(true); }
From source file:ButtonListener.java
public static void main(String[] args) { JPanel panel = new JPanel(); JButton close = new JButton("Close"); close.addActionListener(new ButtonListener()); JButton open = new JButton("Open"); open.addActionListener(new ButtonListener()); JButton find = new JButton("Find"); find.addActionListener(new ButtonListener()); JButton save = new JButton("Save"); save.addActionListener(new ButtonListener()); panel.add(close);//from ww w . j a va 2s . c o m panel.add(open); panel.add(find); panel.add(save); JFrame f = new JFrame(); f.add(panel); f.setSize(400, 300); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int x = 5;//from ww w . j ava2 s.co m int y = 5; JPanel panel = new JPanel(); panel.setLayout(new GridLayout(x, y)); for (int i = 0; i < x * y; i++) { JButton button = new JButton(String.valueOf(i)); button.setPreferredSize(new Dimension(100, 100)); panel.add(button); } JPanel container = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)); container.add(panel); JScrollPane scrollPane = new JScrollPane(container); f.getContentPane().add(scrollPane); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }