2

JavaでSwing UIを使用して、マウスボタンが押されている間にボタンの背景色とテキスト(前景)の色を変更しようとしています。私のメインクラスは非常にシンプルで簡単です:

public class Main {


    public static void main(String[] args) {
        SynthLookAndFeel laf = new SynthLookAndFeel();
        try {
            laf.load(Main.class.getResourceAsStream("/styles.xml"), Main.class);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        try {
            UIManager.setLookAndFeel(laf);
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

        JFrame frame = new JFrame("Not hello world");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.setSize(300, 300);
        frame.setLocation(50, 50);
        frame.setLayout(new FlowLayout());

        frame.add(new JButton("Button 1"));
        frame.add(new JButton("Button 2"));
        frame.add(new JButton("Button 3"));

        frame.setVisible(true);


    }
}

読み込まれた XML Synth スタイル ファイルは次のとおりです。

<synth>
    <style id="basicStyle">
        <font name="Verdana" size="16"/>
        <state>
            <color value="#eeeeee" type="BACKGROUND"/>
            <color value="#000000" type="FOREGROUND"/>
        </state>

    </style>
    <bind style="basicStyle" type="region" key=".*"/>

<style id ="button_style">
    <state value="PRESSED">
        <color value="#666666" type="FOREGROUND" />
        <color value="#aaaaaa" type="BACKGROUND" />
    </state>
</style>
<bind style="button_style" type="region" key="button"/>

しかし、画面に表示されるのは、黒いテキストと灰色がかった背景のボタンだけです。ボタンを押しても何も起こりません:

ここに画像の説明を入力

そのような動作を達成する方法はありますか?

4

1 に答える 1