0

I am a newbie to using Netbeans for Java Swing. I created a new JFrame form and just dragged a name label and text field to the frame.

enter image description here

Now, the label and text field at the center side of my label. When I am Maximize the frame, the order (arrangements of JLabel and JTextField) will be changing.

enter image description here

What is the reason?

How can I solve it?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Possible duplicate of [Centering a JLabel in a JPanel](http://stackoverflow.com/questions/9829319/centering-a-jlabel-in-a-jpanel) – Jezor Sep 01 '16 at 02:56
  • 1
    Consider adding a [Minimal, Complete and Verifable code example](http://stackoverflow.com/help/mcve) to your question. – Jezor Sep 01 '16 at 02:58
  • 1
    You really need to learn how to use Layout Mangers, possible duplicate http://stackoverflow.com/questions/21375255/jpanel-positions-and-sizes-changes-according-to-screensize – Dev. Joel Sep 01 '16 at 03:04
  • 1
    *"What is the reason?"* The code, which by the sounds of it, does **not** use layout managers (properly). *"How can I solve it?"* **Use** layout managers (properly). – Andrew Thompson Sep 01 '16 at 07:56

1 Answers1

2

I see that you are using NetBeans GUI builder. You need to edit the gaps to the left and top of the two components.

Matisse screenshot

There need to be those strings on all the four sides.

Matisse screenshot 2

When you click on the shaded area, a window pops up. There you can edit the type of the gap you have. By default, the gaps to the left and top are not resizable. So click on the resizable check button.

I recommend you to start learning Swing without using the GUI Builder. In my opinion, it is the best way to learn Swing. Later, when you already know something, you can start using the NetBeans GUI Builder.

Here are two Swing tutorials (The second one was created by yours truly):

Oracle Swing tutorial

ZetCode Swing tutorial

Jan Bodnar
  • 10,969
  • 6
  • 68
  • 77