| | |
JLabel image isn't updating when JComboBox selection changes.
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2008
Posts: 3,828
Reputation:
Solved Threads: 501
When I first ran your program, before I realized what I had to do, I stuck this line at the top of actionPerformed:
so it would display every time I selected from the Drop-Down. Have you done this, and does it display?
Java Syntax (Toggle Plain Text)
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?
•
•
Join Date: Aug 2008
Posts: 207
Reputation:
Solved Threads: 13
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:
I'm pretty sure that should get things working. =)
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:
java Syntax (Toggle Plain Text)
class RatingLabel extends JPanel{ ImageIcon stars; RatingLabel(int stars){ switch(stars){ // Go through cases to load images... } this.add(new JLabel("Rating")); this.add(nww JLabel(stars)); } public void setRating(int stars){ //same as switch above } // Other methods to add/remove stars, ect }
I'm pretty sure that should get things working. =)
![]() |
Similar Threads
- updating JComboBox in JTable (Java)
- Stretch Image in JLabel (Java)
- Help with Problem > <' (Java)
- updating jlabel (Java)
- Java program cd player need some help please (Java)
- Display an image using java GUI (Java)
- Adding an Image to a JPanel (Java)
- I lack focus... (Java)
Other Threads in the Java Forum
- Previous Thread: What is the easiest and most efficient vision library...
- Next Thread: Java swing gui
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component data database derby design draw eclipse encryption error event exception fractal game givemetehcodez graphics gui html ide if_statement image inheritance input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception open-source oracle print printing problem program programming project property recursion reference ria scanner screen search server set size sms sort sourcelabs splash sql static stop string swing testautomation threads time tree ui unicode validation windows






