It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes ActionEvent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ActionEvent" Watch "ActionEvent" New topic
Author

ActionEvent

Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
Hi everyone!

Where can I find a full list of all the Strings that ActionEvent throws?

For example, in the Sun online tutorial on ComboBox, the string "comBoxChanged" is used. I had no idea this is the exact strings ActionEvent throws for comboBox events.


amerzil co-ed student<br />"Praise be the Code"
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
I don't really understand what you're asking here. The ActionEvent class doesn't "throw" anything. Events, in Java, are typically referred to as "fired" and exceptions are "thrown."


James Carman, President<br />Carman Consulting, Inc.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.

Note: The Java Tutorial example appears to be here:
http://java.sun.com/docs/books/tutorial/uiswing/learn/example5.html


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Well, using the actionCommand string to decide what to do is quite rare in my experience, with anonymous inner classes.
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
Just to clarify, Strings don't get thrown, exceptions do. And ActionEvent could throw just about anything depending on how you're using it.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by James Carman:
Well, using the actionCommand string to decide what to do is quite rare in my experience, with anonymous inner classes.

Yeah, I was surprised to see this (although maybe I shouldn't have been, since Sun's Swing Tutorial is a strangely jumbled concoction). But I'm still curious about the apparent lack of documentation.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

I wouldn't count on this default -- counting on undocumented things is always a bad idea. Besides, there's a setActionCommand() method, so the default is just that -- a changeable default.


[Jess in Action][AskingGoodQuestions]
Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
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?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
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.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Moving to Swing/AWT...


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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ActionEvent
 
Similar Threads
Dynamic JList generation in Swing
JTable and combobox as the cellEditor
JComboBox (again!!)
Changing Combo box Model
swing(JComboBox)urgent