Java Swing setbounds

ww‮tual.w‬turi.com
Java Swing setbounds

setbounds method in Swing is used to set the position and the size of a component.

setBounds(int x-coordinate, int y-coordinate, int width, int height)

Example:

Setting the button size and position

public static void main(String[] args) {
		
		JFrame frame = new JFrame("Java Swing - lautturi");

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(500, 300);
		frame.setLocationRelativeTo(null);
		frame.setLayout(null);
		
    	JButton button1 = new JButton("button1");
    	button1.setBounds(50,100,80,40);
    	frame.add(button1);
		
		frame.setVisible(true);
	}
Created Time:2017-10-08 22:23:15  Author:lautturi