1
例如,我有兩個單選按鈕,我想要一個邊框,以便界面看起來更清晰?嘗試搜索,但沒有發現任何有用的東西。 謝謝!如何在使用GroupLayout時向組件添加邊框?
例如,我有兩個單選按鈕,我想要一個邊框,以便界面看起來更清晰?嘗試搜索,但沒有發現任何有用的東西。 謝謝!如何在使用GroupLayout時向組件添加邊框?
下面將在您的單選按鈕周圍創建一個邊框。您可以創建不同類型的邊界,檢查BorderFactory API的一個關於不同的邊框
JRadioButton yesButton = new JRadioButton("Yes", true);
JRadioButton noButton = new JRadioButton("No", false);
ButtonGroup bgroup = new ButtonGroup();
bgroup.add(yesButton);
bgroup.add(noButton);
JPanel radioPanel = new JPanel();
radioPanel.setLayout(new GridLayout(2, 1));
radioPanel.add(yesButton);
radioPanel.add(noButton);
radioPanel.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "BorderTitle"));
說明創建面板,把那些單選按鈕在面板..並圍繞面板創建邊框
我希望有另一種方式,不使用面板,哦,謝謝。 – MustSeeMelons 2013-05-08 13:36:09
這是'JComponent' API推薦的方法, – trashgod 2013-05-08 15:31:52