基於http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/size.html,目的是創建一個適合JTabbedPane的一個選項卡的按鈕How to add close button to a JTabbedPane Tab?我構建了以下代碼。它應該在java文檔中顯示一個迷你按鈕,但即使如此,我改變了大小的結果是相同的。請問我做錯了什麼?在此先感謝按鈕大小以微型結算
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class buttontest {
public static void main (String[] args){
buttontest t = new buttontest();
}
public buttontest(){
JFrame test = new JFrame();
JPanel pnlTab = new JPanel();
JButton btnClose = new JButton("x");
btnClose.putClientProperty("JComponent.sizeVariant", "mini");
pnlTab.add(btnClose);
test.add(pnlTab);
test.setVisible(true);
}
}
編輯一個:
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (UnsupportedLookAndFeelException e) {
// handle exception
} catch (ClassNotFoundException e) {
// handle exception
} catch (InstantiationException e) {
// handle exception
} catch (IllegalAccessException e) {
// handle exception
}
您只能將該屬性與支持該屬性的LAF一起使用。 Nimbus LAF支持該財產。 – camickr
請參閱['TabComponentsDemo'](http://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html#eg)。 – trashgod
@camickr可以使用編輯一個更新來調用代碼,但是我沒有看到任何重大差異,那真的有用嗎? –