JToggleButton - How to change the color?

房东的猫 提交于 2019-12-13 04:47:07

问题


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

}

回答1:


You can change that in UIManager:

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


来源:https://stackoverflow.com/questions/25078722/jtogglebutton-how-to-change-the-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!