This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I don't know the answer, but I believe I can clarify the question.
A JComboBox has a protected String field called actionCommand. The accessor and mutator methods are getActionCommand() and setActionCommand(String s).
When a new JComboBox is created, the default value of actionCommand is "comboBoxChanged". This can be observed by simply creating a new JComboBox using the no-args constructor, then printing out the value of getActionCommand().
So I believe Karen's question is: Where does this default value come from?
I would expect this field to be null. I've searched the API, but can't find anything that explains how it's initialized.
Originally posted by Karen Baog: ... Where does this default value come from?
These "magic values" bother me. But as Ernest pointed out, the best approach here is to use setActionCommand("My String") so that you know what the field contains. Avoid using a default value that you cannot predict or depend on.
Joined: Feb 20, 2001
Originally posted by Karen Baog: Hi everyone,
I shouldn't have used the keyword "throw" here. I used it on a general term. Sorry, guys.
Anyway, I just am at a loss how I could figure out that the word "comboBoxChanged" is a default value without printing the value of getActionCommand().
How would I know that, in this instance, not to use setActionCommand()?
So, I'll just repeat marc webber's : Where does this default value come from?
I would say, don't worry about it. You probably won't ever really use actionCommand Strings in your "real" development anyway. I wouldn't lose any sleep over this. But, their previous advice about actually setting the actionCommand String so that you know what it is sounds good to me too.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus