簡體   English   中英

如何將這些 JPanel 對齊到周圍 JPanel 的底部?

[英]How can I align these JPanels on the bottom of the surrounding JPanel?

我正在學習使用 Swing,所以請耐心等待。 看看附加的屏幕截圖:

JFrame

這些是 JFrame 中 JLabel 中的 JLabel。 我想將這些內部 JLabel(在運行時的大小和顏色隨機生成)移動到最底部,就好像它們是書架上的書一樣。 我了解布局管理器,但我似乎無法找到合適的管理器來做我想做的事。 此屏幕截圖顯示了指定 none 的結果,因此它應該默認為 FlowLayout。

內部 JLabel 只是 .add() ed,沒有完成任何放置。 SetLocation 似乎什么都不做。

你能幫我嗎?

如果我是你,我會添加將這些 JLabels 放在帶有 boxlayout 的 JPanel 內,然后將其與邊框布局對齊。 這里有一些代碼可以幫助你:

JLabel outer = new JLabel();
outer.setLayout(new BorderLayout(0,0));
/** Add inner JLabels here. The other you add them is the order they will appear from to right**/
JPanel bookshelf = new JPanel();
bookshelf.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
//Add your jlabels to the bookshelf
outer.add(bookshelf, BorderLayout.SOUTH);

是一個關於布局管理器的很棒的教程。 這里還有一個我設計的 UI,它類似於我認為你想要的。

希望這可以幫助你。

暫無
暫無

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

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