Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes validate() and repaint() troubles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "validate() and repaint() troubles" Watch "validate() and repaint() troubles" New topic
Author

validate() and repaint() troubles

Joel Christophel
Ranch Hand

Joined: Apr 20, 2011
Posts: 237
    
    1

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: 2303
    
  49
What component is 'container' - is it a Swing component? if so you should use revalidate().
Joel Christophel
Ranch Hand

Joined: Apr 20, 2011
Posts: 237
    
    1

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: 39100
    
  23
Why are you combining Swing and AWT components?
Joel Christophel
Ranch Hand

Joined: Apr 20, 2011
Posts: 237
    
    1

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: 4575
    
    5

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: validate() and repaint() troubles