问题
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