• Post Reply Bookmark Topic Watch Topic
  • New Topic

Properties & Actions

 
Randall Twede
Ranch Hand
Posts: 4519
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to use the Properties class to save settings to apply when the app is run again. i have it mostly. i wrote a window listener to save them and i can restore them, but they don't get applied. so far it is just two JComboBox's. when you run the app they display the saved settings but that is all. i originally thought setSelectedItem() would fire an action event but it doesn't. so i tried using the same code i used in the action listener for the combo boxes. that didn't work(though it works in the action listener). then i noticed that JComboBox has a method fireActionEvent() but that method is protected so that doesn't help. here is the code:
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randall Twede wrote:thought setSelectedItem() would fire an action event but it doesn't.

From the API docs for this method
ActionListeners added to the combo box will be notified with an ActionEvent when this method is called.

Maybe you are setting the values before adding an action listener? Best you post your SSCCE

 
Randall Twede
Ranch Hand
Posts: 4519
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it works when i select the item manually(with the mouse).
i add the actionListener in initToolbar() which is called from the constructor.
lines 232-236
the calls to setSelectedItem() there don't work either. they change the selection but do not affect the font or size.
getProperties() is also called from initToolbar() line 256
hmmm...the class has not been fully instantiated yet....but what to do if that is the problem?
i will post the entire class. please ignore all the commented out code.
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still don't see a SSCCE. You question is about a combo box and window closing.

What do all the editor Action have to do with that? What does the toolbar have to do with that? What does the reading/writing of the text file have to do with this? What does all the commented out code have to do with this?

We are not here to read your 330 line program to decide what code is or isn't relative to the problem. That is your job to do when you create the SSCCE.
 
Randall Twede
Ranch Hand
Posts: 4519
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't have 2 weeks to create one.
i edited the beginning of that post and you probably didn't see it yet. look again. i explain what might be going on and that it is basically in the constructor.
i don't expect anyone to read it all that is why i say what line numbers.
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it works in one place, it should work in all places. If it doesn't then you have a programming problem.

I am not going to read through 300+ lines of code to guess what the problem might be.

Creating the SSCCE is a way for you to do some basic debugging. Most times you find the problem while attempting to replicate the problem.

What is so hard for YOU to understand?
 
Randall Twede
Ranch Hand
Posts: 4519
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
calling it from the constructor is different from calling it at runtime(by clicking). i think that might be the problem.
you must not believe anything anyone says, therefore you always want an SSCE.
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think that might be the problem.


Then test it and post the code proving what you think the problem is. Then we can offer a solution (if we know one).

you must not believe anything anyone says


No, because too many people say one thing and then code another.

Unless you can prove what you say with a SSCCE, then it isn't a problem.

You only have to go back to your question about the "setLocationRelativeTo(null)" method being broken in JDK7 for proof of this. It was a silly programming mistake on your part.

i don't need the aggravation


Neither do we. I respond to your postings to let other members of the forum know that you have been continuously asked to post a SSCCE because frankly most of your questions don't contain enough information for use to properly solve the problem and we don't have time to waste by guess exactly what you are trying to do or how you are attempting to do it. The only other person to respond to this question also asked for a SSCCE. So maybe we know better than you what information we need in order to answer a question.
 
Randall Twede
Ranch Hand
Posts: 4519
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then test it and post the code proving what you think the problem is

that is exactly what i did
this is the last time i reply to anything you say rob
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you did not post a SSCCE demonstrating your problem. You posted your entire program.

You can't solve the problem because there are to many trees in the forest for you to see your mistakes

And we don't have the time to look at all the trees in the forest to see the mistake either.

The SSCCE should contain, your combo box and a save button. That is all. It will take 10 minutes to create which you could easily have done instead of wasting your time (and ours) with all these silly messages.

You obviously don't want help, since you can't listen to the suggestions given by two senior members of the forum, so I don't know why you post the questions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!