在JPanel中手动定位JComponent

ole*_*tus 7 java swing jcomponent

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

jjn*_*guy 12

这是一个很棒的教程,介绍如何在不使用布局管理器的情况下布局组件.

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

在没有布局管理器的情况下创建容器涉及以下步骤.

  1. 通过调用将容器的布局管理器设置为null setLayout(null).
  2. setbounds为每个容器的子节点调用Component类的方法.
  3. 调用Component类的repaint方法.