aspose file tools*
The moose likes Beginning Java and the fly likes Swing components not updating with current values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Swing components not updating with current values" Watch "Swing components not updating with current values" New topic
Author

Swing components not updating with current values

Bert Deville
Greenhorn

Joined: Oct 10, 2008
Posts: 8
Hello,

I'm writing a game that has an Advert class. At the start of the game, an ArrayList<Advert> will be deserialized from file, containing all the adverts. I'm also writing an Advert Editor to create/edit an ArrayList<Advert> and serialize it to file. The Editor looks like this :



The problem I'm having : when you push the "Previous", "Next" or "New Advert" button, everything goes fine except the values in the fields are only updated when they are related to a String (Title & Description). The fields related to an int (Bonus, Penalty, Minimum Viewers, ...) or boolean (XRated Mandatory & Forbidden) always keep their value. My guess is that I must be overlooking something in the following 2 methods that are called from the button's actionlisteners. The first one updates the text of the Swing components using the getters of the active advert in the ArrayList. The second one does just the opposite : it calls the setters of the active advert in the ArrayList with the values from the Swing components.




Anyone who could give me a hint what I might be doing wrong ?
[ October 25, 2008: Message edited by: Bert Deville ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Please show us the ActionListeners you are using for the buttons.
Bert Deville
Greenhorn

Joined: Oct 10, 2008
Posts: 8
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Difficult to see what's wrong; it is something very subtle.

Set up a print buttonAnd make sure the Advert class has a decent toString method. See what it prints. And try adding a print statement to print the current Advert to the next and previous buttons. That should allow you to see whether the data are actually being recorded in the Buttons.

You can always remove the print button and print statements later.

When you click the "new" button, do you get 0s in the number fields? Does the Advert 1/1 bit update correctly?

I am afraid I can't see the error. Sorry.
Anybody else got an idea, please?
Bert Deville
Greenhorn

Joined: Oct 10, 2008
Posts: 8
Very strange, I added all the print-stuff but now it actually works correctly. I can't remember changing anything besides adding a print-button and print-statements in refresh(), updateList() and all 3 actionlisteners for the buttons.

So thanks for your help, I still don't know what was wrong, but at least I got it working now. ;-)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
You're welcome ( ) . . . to whatever I didn't do that helped!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Swing components not updating with current values