Search code examples
javaswingiconsjbuttonselected

Why is unselected JButton showing highlighted icon?


I've created a solution to the classic eight queens chess problem. The Java Swing image below shows the solution, and I've verified programatically that none of the squares, which are JButtons, are selected (isSelected = false for each button). Why then is the first button showing a white square around the image icon? If I click on any empty square, the white outline around the image icon on the first square disappears. I've tried iterating each button after the board is displayed, and for each button, calling button.setSelected(false), but still no luck. Any suggestions? Thanks.

Eight Queens solution


Solution

  • did you try removing the focus.

    myButton.setFocusPainted(false);
    

    if this doesn't work read this question