I’m just doing my personal project that draws a basic map using Swing.
I have many issues but the worst one is that the position of JLables changes every time I
- Resize the frame
- Set them invisible and visible again (setvisible(false)->setvisible(true))
- Move the screen to another tab ‘Map 2’ and come back to Map 1 (The frame has
JTabbedPane)
It’s sad that I don’t have enough reputation to upload images 🙁
all the JLables are located on the top of the JPanel.
It’s like
Before
.———————————————–
.———————————————–
.———Label1—————————–
.———————————————–
.——————Label2——————–
.———————————————–
.——————————-Label3——-
.———————————————–
.———————————————–
.———————————————–
After
.———————————————–
.———Label1 Label2 Label3———–
.———————————————–
.———————————————–
.———————————————–
.———————————————–
.———————————————–
.———————————————–
.———————————————–
.———————————————–
I also tried using setLocation(new Point(x,y)); after resizing happens but nothing came out.
Any tips will be appreciated. 🙂


You have used absolute positioning without setting the layout accordingly. Refreshing the display in the presence of
FlowLayout, the default forJPanel, causes the layout you see in after. UsingsetLayout(null)may work, but the preferred approach is to use the intended layout manager.