Component: setBounds(int x,int y,int width,int height) Java Example
setBounds method is use to position swing components like JButtons,JLables or JTextFields
in a JFrame or JPanel
in a JFrame or JPanel
setBounds Example
[
import javax.swing.ButtonGroup; import javax.swing.JRadioButton; import javax.swing.JFrame; public class SetBoundsExample extends JFrame { public SetBoundsExample() { super("Setbounds Example method"); setSize(400,400); setLayout(null); setLocationRelativeTo(null); JRadioButton male = new JRadioButton("Yes?", true); JRadioButton female = new JRadioButton("No?", false); add(male); add(female); ButtonGroup gender = new ButtonGroup(); gender.add(male); gender.add(female); male.setBounds(30, 50, 50, 20); female.setBounds(30, 80, 50, 20); setVisible(true); } public static void main(String args[]) { new SetBoundsExample(); } }