7

I want to programmatically move my JLabel to a specific location inside my JPanel. I have tried setLocation(int x, int y), but it doesn't work. I am trying to not use any layout manager.

4

1 に答える 1

12

これは、レイアウト マネージャーを使用せずにコンポーネントをレイアウトする方法に関する優れたチュートリアルです。

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

レイアウト マネージャーを使用せずにコンテナーを作成するには、次の手順を実行します。

  1. を呼び出して、コンテナーのレイアウト マネージャーを null に設定しますsetLayout(null)
  2. setboundsコンテナの各子に対してComponent クラスのメソッドを呼び出します。
  3. Component クラスのrepaintメソッドを呼び出します。
于 2010-06-21T13:50:11.813 に答える