0

So I've been having this little issue with this app that I'm developing for a school project and I believe my eclipse has bugged out, what happens is, whenever I set the bounds to something on the GUI it doesn't respect them and always puts whatever I implement on near the middle to the left of the GUI, if I implement more stuff it just moves it to a random place despite what bounds I set it to.

I don't really know how to fix this and I've tried deleting the class and writing the code all over again but it still happens, I've searched on google for any fixes but can't seem to find anyone with this problem, any help or insight into this issue would be much appreciated.

The issue

JFrame frame = new JFrame();

JLabel ArmaLabel = new JLabel();
JLabel BarC = new JLabel();
JLabel teste = new JLabel("teste");

ArmaP() {

    BarC.setBounds(100,100,100,30);
    BarC.setText("teste12");

    teste.setBounds(400,300,20,20);

    ArmaLabel.setBounds(325,20,200,35);
    ArmaLabel.setText("Armazenamento");
    ArmaLabel.setFont(new Font(null,Font.ROMAN_BASELINE,25));

    frame.add(ArmaLabel);
    frame.add(BarC);
    frame.add(teste);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800,600);
    frame.setVisible(true);
    frame.setLayout(null);
    frame.setResizable(false);
}
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    Eclipse is just your development environment, it is not involved when you actually run your code, that is just Java. – greg-449 May 26 '22 at 19:59
  • 1
    Oracle has a helpful tutorial, [Creating a GUI With Swing](https://docs.oracle.com/javase/tutorial/uiswing/index.html). Skip the Learning Swing with the NetBeans IDE section. Pay close attention to the [Laying Out Components Within a Container](https://docs.oracle.com/javase/tutorial/uiswing/layout/index.html) section. – Gilbert Le Blanc May 27 '22 at 00:46
  • 1
    *"bug doesn't respect the bounds set by GUI"* That's a feature, not a bug. Use layouts. `pack()` the frame. – Andrew Thompson Jun 29 '22 at 04:36

0 Answers0