File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validate() and repaint() troubles

 
Joel Christophel
Ranch Hand
Posts: 249
1
Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What component is 'container' - is it a Swing component? if so you should use revalidate().
 
Joel Christophel
Ranch Hand
Posts: 249
1
Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47253
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you combining Swing and AWT components?
 
Joel Christophel
Ranch Hand
Posts: 249
1
Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic