2

http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/size.htmlに基づいて、JTabbedPane から 1 つのタブに収まるボタンを作成する目的で、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);
            }
}

編集 1:

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
    }
4

1 に答える 1