2
I’d like to define the location of color1
according to the size of a Jpanel, the same way I did with the fundo
public static void janelaPrincipal()
{
//FRAME
JFrame janela = new JFrame();
janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
janela.pack();
janela.setResizable(false);
janela.setVisible(true);
janela.setSize(new Dimension(WIDTH, HEIGHT));
janela.setLocation((SCREEN.width / 2) - (WIDTH / 2), (SCREEN.height / 2) - (HEIGHT / 2));
Container c = janela.getContentPane();
c.setLayout(new FlowLayout());
//PAINEIS
JPanel fundo = new JPanel();
fundo.setPreferredSize(new Dimension(WIDTH, HEIGHT));
fundo.setBackground(background);
//BOTOES
JButton color1 = new JButton();
JButton color2 = new JButton();
color1.setPreferredSize(new Dimension(WIDTHBUTTON, HEIGHTBUTTON));
color1.setLocation(HEIGHT / 2, WIDTH /2);
color1.setBackground(RED);
//ADICIONAR NO FRAME
c.add(fundo);
fundo.add(color1);
}
You want to keep your Jbutton always in the center of your Jpanel and you’re not getting it, that’s it?
– Math
No, the center was just an example, I want to position by "pixels" the same way I positioned Jframe on the screen
– Lucas Caresia