List of usage examples for javax.swing JButton setBounds
public void setBounds(int x, int y, int width, int height)
From source file:Absolute.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setLayout(null);/* ww w . j a v a 2 s . c om*/ JButton ok = new JButton("OK"); ok.setBounds(50, 150, 80, 25); JButton close = new JButton("Close"); close.setBounds(150, 150, 80, 25); f.add(ok); f.add(close); f.setSize(300, 250); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JButton component = new JButton(); JPanel panel = new JPanel(null); component.setBounds(1, 1, 100, 100); panel.add(component);// w w w. ja va 2 s. c o m }
From source file:Main.java
public static void main(String... args) { JFrame f = new JFrame(); JButton button; JPanel p = new JPanel(); button = new JButton("Button"); p.setLayout(null);//from w w w. j a v a 2 s . c o m button.setBounds(40, 100, 100, 60); p.add(button); f.add(p); // setLayout(null); f.setDefaultCloseOperation(3); f.setSize(400, 400); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(null);/*www . j a v a 2 s .c o m*/ JButton b1 = new JButton("Button"); JButton b2 = new JButton("2"); contentPane.add(b1); contentPane.add(b2); b1.setBounds(10, 10, 100, 20); b2.setBounds(120, 10, 150, 40); frame.setBounds(0, 0, 350, 100); frame.setVisible(true); }
From source file:ButtonModel.java
public static void main(String[] args) { final JButton ok = new JButton("ok"); JCheckBox cb = new JCheckBox("Enabled", true); ok.setBounds(40, 30, 80, 25); ok.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { DefaultButtonModel model = (DefaultButtonModel) ok.getModel(); if (model.isEnabled()) System.out.println("Enabled: true"); else/*from w w w. j a v a 2 s . c o m*/ System.out.println("Enabled: false"); if (model.isArmed()) System.out.println("Armed: true"); else System.out.println("Armed: false"); if (model.isPressed()) System.out.println("Pressed: true"); else System.out.println("Pressed: false"); } }); cb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (ok.isEnabled()) ok.setEnabled(false); else ok.setEnabled(true); } }); JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.add(ok); f.add(cb); f.setSize(350, 250); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:AbsoluteLayoutDemo.java
public static void addComponentsToPane(Container pane) { pane.setLayout(null);//from w ww. j a va2 s .c o m JButton b1 = new JButton("one"); JButton b2 = new JButton("two"); JButton b3 = new JButton("three"); pane.add(b1); pane.add(b2); pane.add(b3); Insets insets = pane.getInsets(); Dimension size = b1.getPreferredSize(); b1.setBounds(25 + insets.left, 5 + insets.top, size.width, size.height); size = b2.getPreferredSize(); b2.setBounds(55 + insets.left, 40 + insets.top, size.width, size.height); size = b3.getPreferredSize(); b3.setBounds(150 + insets.left, 15 + insets.top, size.width + 50, size.height + 20); }
From source file:NullLayoutPane.java
public NullLayoutPane() { // Get rid of the default layout manager. // We'll arrange the components ourselves. this.setLayout(null); // Create some buttons and set their sizes and positions explicitly for (int i = 1; i <= 9; i++) { JButton b = new JButton("Button #" + i); b.setBounds(i * 30, i * 20, 125, 30); // use reshape() in Java 1.0 this.add(b); }// ww w .j a va 2 s . c om }
From source file:Main.java
public Main() { setSize(200, 150);//from www . j a v a2 s . c o m setDefaultCloseOperation(EXIT_ON_CLOSE); JLayeredPane lp = getLayeredPane(); JButton top = new JButton(); top.setBackground(Color.white); top.setBounds(20, 20, 50, 50); JButton middle = new JButton(); middle.setBackground(Color.gray); middle.setBounds(40, 40, 50, 50); JButton bottom = new JButton(); bottom.setBackground(Color.black); bottom.setBounds(60, 60, 50, 50); lp.add(middle, new Integer(2)); lp.add(top, new Integer(3)); lp.add(bottom, new Integer(1)); setVisible(true); }
From source file:Main.java
public Main() { super("LayeredPane"); setSize(200, 150);/*from w w w. java2 s . co m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); JLayeredPane lp = getLayeredPane(); // Create 3 buttons JButton top = new JButton(); top.setBackground(Color.white); top.setBounds(20, 20, 50, 50); JButton middle = new JButton(); middle.setBackground(Color.gray); middle.setBounds(40, 40, 50, 50); JButton bottom = new JButton(); bottom.setBackground(Color.black); bottom.setBounds(60, 60, 50, 50); // Place the buttons in different layers lp.add(middle, new Integer(2)); lp.add(top, new Integer(3)); lp.add(bottom, new Integer(1)); }
From source file:SimpleLayers.java
public SimpleLayers() { super("LayeredPane Demonstration"); setSize(200, 150);//from w w w . j av a 2s .c o m setDefaultCloseOperation(EXIT_ON_CLOSE); JLayeredPane lp = getLayeredPane(); // Create 3 buttons JButton top = new JButton(); top.setBackground(Color.white); top.setBounds(20, 20, 50, 50); JButton middle = new JButton(); middle.setBackground(Color.gray); middle.setBounds(40, 40, 50, 50); JButton bottom = new JButton(); bottom.setBackground(Color.black); bottom.setBounds(60, 60, 50, 50); // Place the buttons in different layers lp.add(middle, new Integer(2)); lp.add(top, new Integer(3)); lp.add(bottom, new Integer(1)); }