简体   繁体   中英

how to change the colour of a button on pressing it in java

I have around 50 buttons .some are green(selected),some are grey(deselected). If i press the green buttons ,they should change their colour to red and back to green on pressing again. If i press the grey buttons ,they should change their colour to green and back to grey on pressing again. All buttons have some text in black.On pressing the buttons,the colour of the text remains unchanged. Suggest a solution or tutorial for same...

Don't use a JButton for this but instead use a JToggleButton. Consider giving them ImageIcons for their state.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM