javaswingsetbounds

ignored setbounds


I simply would like to place my JButton by the setBounds method. But whatever the parameters of this method, the button is on the middle at the top.

This is my code :

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

class Panneau_fenetre1A extends JPanel                      
{ 
    JButton boutonOK = new JButton ("OK");


    public Panneau_fenetre1A(int Na)
    {
        boutonOK.setBounds(300,300,30,30);
        add(boutonOK);

    }

}

Solution

  • The placement of the button would also depend on the layout that you are currently using. Here's a Vusual Guide to Layout to help you out decide on the best layout for your requirement.