1

Could you please tell me how to change the position of my JButton? I tried all the functions that I found on web, like setLocation() and more, but I'm still stuck.

    JButton b3 = new JButton();
    f.setSize(600,500); 
    b3.setVisible(true);
    b3.setText("admin area");
    f.setLayout(new FlowLayout());
    f.add(b3);
    f.setVisible(true);

enter image description here

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Did you try this? https://stackoverflow.com/questions/5646929/changing-position-of-a-button – C4mps Dec 06 '18 at 07:22

1 Answers1

-1

f.setLayout(new FlowLayout()); :

A flow layout arranges components in a directional flow, much like lines of text in a paragraph

-- https://docs.oracle.com/javase/7/docs/api/java/awt/FlowLayout.html

If you don't want to have your buttons in one row, you should use another layout manager. The GridBagLayout is my favorite for complex layout but is not the easiest to use. If you want to position your buttons with absolute coordinates, then you can just apply a null layout.

f.setlayout(null);
button.setBounds(...);
f.add(button);
Community
  • 1
  • 1
gervais.b
  • 2,294
  • 2
  • 22
  • 46