JLabel image isn't updating when JComboBox selection changes.

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 33
Reputation: gotm is an unknown quantity at this point 
Solved Threads: 0
gotm gotm is offline Offline
Light Poster

Re: JLabel image isn't updating when JComboBox selection changes.

 
0
  #11
Aug 12th, 2009
Originally Posted by VernonDozier View Post
I assume you have no messages like this:
nope no errors it just doesnt change
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,828
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: JLabel image isn't updating when JComboBox selection changes.

 
0
  #12
Aug 12th, 2009
When I first ran your program, before I realized what I had to do, I stuck this line at the top of actionPerformed:

  1. System.out.println ("Inside actionPerformed");

so it would display every time I selected from the Drop-Down. Have you done this, and does it display?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 207
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training

Re: JLabel image isn't updating when JComboBox selection changes.

 
0
  #13
Aug 12th, 2009
Okay, here's what I've found.

1) DON'T USE PACK()!
JFrame.pack() is good some times, but NOT here. Use JFrame.setSize(int, int) (I set it to 250 x 135, and it looks great). using pack here makes it look squished (which it is!).

2) Set the default recipe
In your constructor (after creating the test recipe, and adding it to the JComboBox), set the selected index/item to 0 or test respectively. (that will ensure that the ratings show up at creation)

3) Don't use 2 JLabels for the rating!
Find a way to use one, and show the word "Rating: ", and the stars, or create a class that can display them horizontaly:
  1. class RatingLabel extends JPanel{
  2. ImageIcon stars;
  3.  
  4. RatingLabel(int stars){
  5. switch(stars){
  6. // Go through cases to load images...
  7. }
  8. this.add(new JLabel("Rating"));
  9. this.add(nww JLabel(stars));
  10. }
  11. public void setRating(int stars){
  12. //same as switch above
  13. }
  14. // Other methods to add/remove stars, ect
  15. }

I'm pretty sure that should get things working. =)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC