簡體   English   中英

JPanel - GridLayout

[英]JPanel - GridLayout

我目前創建了GridLayout:它有4列,前兩列是進度條,另外兩列是開始/停止按鈕。 如何將最后兩個按鈕放在彼此旁邊?

我多么想要:
進度條
進度條
開始停止

怎么樣:
進度條
進度條
開始

即使我將布局更改為:panel.setLayout(new GridLayout(3,2,3,3)); 它不起作用,任何人都可以幫助我嗎?

只需將兩個JProgressBar JPanel say centerPanel帶有BridLayout(0, 1, 5, 5) JPanel say centerPanelJPanel say centerPanel BridLayout(0, 1, 5, 5)

並將2 JButtonSTART and STOP放到另一個JPanel say buttonPanel ,即布局,即FlowLayout(FlowLayout.LEFT, 5, 5) (這將使JButton START與JProgressBar的左側對齊,但是如果你想要JButton的話來到同一個地方的某個地方,然后根本就不要使用 setLayout(FlowLayout.LEFT, 5, 5) JPanel的默認布局可以)。

現在使用將centerPanel添加到JFrame

frameReference.add(centerPanel, BorderLayout.CENTER) 

並使用添加buttonPanel

frameReference.add(buttonPanel, BorderLayout.PAGE_END)

那樣做:-)

編輯1:

為這件東西使用Border 喜歡

centerPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK))

這將在centerPanel周圍創建一個Box 請看一下這個答案 ,雖然我在這個例子中使用的是TitledBorder

暫無
暫無

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

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