[英]How to set the J components size to the content they are set i have two components jlabel and jtextarea
[英]Java JTextArea, JLabel, and other Components: How to set Location
例如,如果我有一个JLabel
,并且我调用了setLocation()
方法,则没有任何反应。 与所有其他JComponent
相同。 我该如何指定位置? 能够在任何我想要的地方移动这些Component
会很高兴。
布局管理器将为您定位组件。 可以不使用布局管理器并自己定位组件,但不建议这样做。 请阅读oracle http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html上的以下教程。
我猜你的面板或框架的LayoutManager
为你设置标签的位置。
您需要做的是将布局设置为null
(这将使框架不会尝试自行布局组件):
public GUI()
{
setLayout(null);
}
但是,我并不宽恕这种解决方法,因为LayoutManager
在映射组件应该去的地方非常有用。 此外,当LayoutManager
为null
,您必须每次都跟踪新组件,在窗口移动缩小时自己执行布局计算等。请阅读本教程以获取有关LayoutManager
的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.