JButtons don't imediatly change on mouse event
Posted
by out_sider
on Stack Overflow
See other posts from Stack Overflow
or by out_sider
Published on 2010-05-13T23:02:18Z
Indexed on
2010/05/13
23:14 UTC
Read the original article
Hit count: 146
java
|game-development
I'm using the java swing library to develop a board game called DAO.
The problem is that after the human player makes its move, by clicking on the JButton with the piece image that he wants to play, I call the computer AI routine but inside the mouse event function. By doing this only when the function returns, the computer ends its turn, do the JButtons refresh their Images (setIcon comes in).
I'd like to know how can I force the JButtons to change their image at the moment they are clicked and not only when the mouse event function ends (as I need to handle data inside it).
I've tried all of this
myButtons[i][j].setIcon(xIcon);
myButtons[i][j].revalidate();
myButtons[i][j].repaint();
myButtons[i][j].validate();
None worked.
Thx in advance
© Stack Overflow or respective owner