| Author |
validate() and repaint() troubles
|
Joel Christophel
Ranch Hand
Joined: Apr 20, 2011
Posts: 122
|
|
|
In my JFrame, I have a Container of JButtons in a grid. Each JButton has an icon assigned to it. When a button is pressed, it is assigned to a new JButton with a new icon. How do I get the GUI to change after the JButton variables are set to new values when clicked? I've tried putting this: right after I change the button, but when I click on the buttons, they appear to be unchanged.
|
 |
Tony Docherty
Bartender
Joined: Aug 07, 2007
Posts: 1217
|
|
|
What component is 'container' - is it a Swing component? if so you should use revalidate().
|
 |
Joel Christophel
Ranch Hand
Joined: Apr 20, 2011
Posts: 122
|
|
Tony Docherty wrote:What component is 'container' - is it a Swing component? if so you should use revalidate().
container is an AWT Container.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32827
|
|
|
Why are you combining Swing and AWT components?
|
 |
Joel Christophel
Ranch Hand
Joined: Apr 20, 2011
Posts: 122
|
|
Campbell Ritchie wrote:Why are you combining Swing and AWT components?
Should I be using JPanel instead? And would that fix my problem...?
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4199
|
|
That's right, you shouldn't combine heavyweight (AWT) and lightweight (Swing) components in the same GUI hierarchy. JPanel is a good choice here.
As for this:
Joel Christophel wrote:When a button is pressed, it is assigned to a new JButton with a new icon.
Variables are assigned values. Buttons aren't assigned, so that statement of yours is open to all kinds of interpretation.
To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.
|
luck, db
There are no new questions, but there may be new answers.
|
 |
 |
|
|
subject: validate() and repaint() troubles
|
|
|