基于http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/size.html,目的是创建一个适合 JTabbedPane 中的一个选项卡的按钮如何将关闭按钮添加到 JTabbedPane 选项卡?我构建了下面的代码。它应该像 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
}