Q: I couldnt set location of components in Java for usinf JFrame and contentPane? I want to create a simple profile information page with JFrame and contentPane. I added all the components correctly. But I cant set their location. How can i set it? I used setBoundary() method bur it doesnt work.
My Anket.java class is:
import java.awt.*;
import javax.swing.*;

 

public class Anket {
    public static void main(String[] args) {
        
        
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(new Dimension(600, 300));
        frame.setTitle("Profile Information");
        
        
        Container contentPane = frame.getContentPane();
        contentPane.setBackground(Color.GRAY);

 

       
        
        JRadioButton rdbtnNewRadioButton = new JRadioButton("Age(10-20)");
        rdbtnNewRadioButton.setBounds(412, 50, 50, 20);
        frame.getContentPane().add(rdbtnNewRadioButton);
        
        JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("Age(21-30)");
        rdbtnNewRadioButton.setBounds(412, 20, 50, 20);
        frame.getContentPane().add(rdbtnNewRadioButton_1);
            
        JRadioButton rdbtnNewRadioButton_2 = new JRadioButton("Age(31-40)");
        rdbtnNewRadioButton.setBounds(412, 30, 50, 20);
        frame.getContentPane().add(rdbtnNewRadioButton_2);
                
        JRadioButton rdbtnNewRadioButton_3 = new JRadioButton("Age(41-50)");
        rdbtnNewRadioButton.setBounds(412, 40, 50, 20);
        frame.getContentPane().add(rdbtnNewRadioButton_3);
        
        JLabel lblNewLabel = new JLabel("PLEASE ENTER YOUR INFORMATION");
        lblNewLabel.setBounds(149, 0, 182, 14);
        frame.getContentPane().add(lblNewLabel);
        
        JLabel lblNewLabel_1 = new JLabel("Enter Your Name");
        lblNewLabel_1.setBounds(127, 25, 86, 14);
        frame.getContentPane().add(lblNewLabel_1);
        
        JLabel lblNewLabel_2 = new JLabel("Enter Your Lastname");
        lblNewLabel_2.setBounds(272, 25, 100, 14);
        frame.getContentPane().add(lblNewLabel_2);
        
        JLabel lblNewLabel_3 = new JLabel("Enter Your Height");
        lblNewLabel_3.setBounds(127, 103, 86, 14);
        frame.getContentPane().add(lblNewLabel_3);
        
        
        
        JTextField textField = new JTextField();
        textField.setBounds(216, 100, 86, 20);
        frame.getContentPane().add(textField);
        textField.setColumns(10);
        
        JTextField textField_1 = new JTextField();
        textField_1.setBounds(127, 48, 86, 20);
        frame.getContentPane().add(textField_1);
        textField_1.setColumns(10);
        
        JTextField textField_2 = new JTextField();
        textField_2.setColumns(10);
        textField_2.setBounds(412, 48, 86, 20);
        frame.getContentPane().add(textField_2);
        

 

        JLabel lblNewLabel_4 = new JLabel(new ImageIcon("C:/Users/PC/eclipse-workspace/Project/src/Berguzar.jpg"));
        lblNewLabel_4.setBounds(10, 21, 100, 85);
        frame.getContentPane().add(lblNewLabel_4);
        
        
        frame.setLayout(new FlowLayout());
        frame.setVisible(true);
    }

 

}

The program doesnt have any error. How can i fix this problem?
My output screen is:
output

A: You should replace
Container contentPane = frame.getContentPane();
contentPane.setBackground(Color.GRAY);  

with
JPanel contentPane = new JPanel(null); // The null is important
contentPane.setBackground(Color.GRAY);
frame.setContentPane(contentPane); // each time you change the content pane you need to revalidate the jframe (frame.setVisible(true) also revalidate the jframe so in this case it is not needed to revalidate the jframe)

