2017-06-18 91 views
0

之間的距離我寫了這個代碼實現一個盒子放到我放四個JradioButton將爪哇 - JLabel的垂直箱

JRadioButton beginner = new JRadioButton("Beginner"); beginner.setSelected(true); 
JRadioButton intermedie = new JRadioButton("Intermedie"); 
JRadioButton expert = new JRadioButton("Expert"); 
JRadioButton custom = new JRadioButton("Custom"); 

Box boxDifficulty = Box.createVerticalBox(); 
boxDifficulty.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 50)); 
boxDifficulty.add(beginner); 
boxDifficulty.add(intermedie); 
boxDifficulty.add(expert); 
boxDifficulty.add(custom); 

而且我用setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 50))方法來設置框的邊框。

而且,我創建了一個JLabel用於指示框的標題:

JLabel difficulty = new JLabel("Choose the difficulty:"); 

這是完整的代碼部分:

Box boxDifficulty = Box.createVerticalBox(); 
boxDifficulty.add(difficulty); 
boxDifficulty.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 50)); 
boxDifficulty.add(beginner); 
boxDifficulty.add(intermedie); 
boxDifficulty.add(expert); 
boxDifficulty.add(custom); 

我怎麼能增加的JLabel之間的空間一個JRadioButton?

回答

2

如何增加JLabel和JRadioButton之間的空間?

可以添加間隔組件的面板添加標籤後:

boxDifficulty.add(difficulty); 
boxDifficulty.add(Box.createVerticalStrut(...)); 

的撐杆是一個固定的高度(寬度)不可見的部件。