7

我想以编程方式将我的 JLabel 移动到我的 JPanel 内的特定位置。我试过setLocation(int x, int y)了,但它不起作用。我试图不使用任何布局管理器。

4

1 回答 1

12

这是一个关于如何在不使用布局管理器的情况下布局组件的精彩教程。

http://java.sun.com/docs/books/tutorial/uiswing/layout/none.html

创建没有布局管理器的容器涉及以下步骤。

  1. 通过调用将容器的布局管理器设置为空setLayout(null)
  2. 为容器的每个子级调用 Component 类的setbounds方法。
  3. 调用 Component 类的repaint方法。
于 2010-06-21T13:50:11.813 回答