簡體   English   中英

在JPanel中手動定位JComponent

[英]Manually position JComponent inside JPanel

我想以編程方式將我的JLabel移動到JPanel中的特定位置。 我嘗試過setLocation(int x, int y) ,但它不起作用。 我試圖不使用任何布局管理器。

這是一個很棒的教程,介紹如何在不使用布局管理器的情況下布局組件。

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

在沒有布局管理器的情況下創建容器涉及以下步驟。

  1. 通過調用setLayout(null)將容器的布局管理器設置為null。
  2. 為每個容器的子setbounds調用Component類的setbounds方法。
  3. 調用Component類的repaint方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM