[英]JLabel's position changes to weird location when resizing the frame
I'm just doing my personal project that draws a basic map using Swing. 我正在做我的个人项目,使用Swing绘制基本地图。
I have many issues but the worst one is that the position of JLable
s changes every time I 我有很多问题,但最糟糕的是
JLable
的位置每次都会改变
JTabbedPane
) JTabbedPane
) It's sad that I don't have enough reputation to upload images :( 很遗憾我没有足够的声誉来上传图片:(
all the JLable
s are located on the top of the JPanel
. 所有
JLable
都位于JPanel
的顶部。
It's like 就像是
Before 之前
.----------------------------------------------- .-----------------------------------------------
.----------------------------------------------- .-----------------------------------------------
.---------Label1----------------------------- .---------的Label1 -----------------------------
.----------------------------------------------- .-----------------------------------------------
.------------------Label2-------------------- .------------------ Label2的--------------------
.----------------------------------------------- .-----------------------------------------------
.-------------------------------Label3------- .------------------------------- LABEL3 -------
.----------------------------------------------- .-----------------------------------------------
.----------------------------------------------- .-----------------------------------------------
.----------------------------------------------- .-----------------------------------------------
After 后
.----------------------------------------------- .-----------------------------------------------
.---------Label1 Label2 Label3----------- .--------- Label1 Label2 Label3 -----------
.----------------------------------------------- .-----------------------------------------------
.----------------------------------------------- .-----------------------------------------------
.----------------------------------------------- .-----------------------------------------------
.----------------------------------------------- .-----------------------------------------------
.----------------------------------------------- .-----------------------------------------------
.----------------------------------------------- .-----------------------------------------------
.----------------------------------------------- .-----------------------------------------------
.----------------------------------------------- .-----------------------------------------------
I also tried using setLocation(new Point(x,y));
我也尝试过使用
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 for JPanel
, causes the layout you see in after . 在存在
FlowLayout
( JPanel
的默认设置)的情况下刷新显示会导致您在之后看到的布局。 Using setLayout(null)
may work, but the preferred approach is to use the intended layout manager . 使用
setLayout(null)
可能有效,但首选方法是使用预期的布局管理器 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.