user3868442
user3868442

Reputation: 117

JToggleButton - How to change the color?

I could to set the color of the button, but once the button is pressed its color is blue - standard. I want to be black. How do I change it?

Below is the current code:

    public JPanel gameBoard(){

        JPanel pBoard = new JPanel();
        pBoard.setSize(5*horizontalOptions,5*verticalOptions);
        pBoard.setLayout(new GridLayout(horizontalOptions,verticalOptions));
        jb = new JToggleButton[verticalOptions*horizontalOptions];
        int k=0;
        for(int i=0;i<verticalOptions;i++){
            for(int j=0;j<horizontalOptions;j++){
                jb[k]=new JToggleButton ("", false);
                jb[k].setPreferredSize(new Dimension(100, 100));
                jb[k].setBackground(Color.white);
                jb[k].setBorder(BorderFactory.createLineBorder(Color.black));
                jb[k].setForeground(Color.black);
                pBoard.add(jb[k]);
                k++;
            }
        }
        return pBoard;
    }

}

Upvotes: 0

Views: 3044

Answers (1)

alex2410
alex2410

Reputation: 10994

You can change that in UIManager:

UIManager.put("ToggleButton.select", Color.BLACK);

Upvotes: 2

Related Questions