 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Dr. Len Guest
|
Posted: Thu Jun 17, 2004 12:17 pm Post subject: Associating user data with AWT/Swing component? |
|
|
Hi NG,
Do Swing/AWT components have a simple facility for associating user
data (Integer) with the component?
I have multiple JTextFields in my JPanel, with the panel being their
keylistener. In the KeyPressed, I would like to get component's user
data like so: event.getComponent().getUserData();
TIA.
|
|
| Back to top |
|
 |
ak Guest
|
Posted: Thu Jun 17, 2004 12:35 pm Post subject: Re: Associating user data with AWT/Swing component? |
|
|
| Quote: | Do Swing/AWT components have a simple facility for associating user
data (Integer) with the component?
I have multiple JTextFields in my JPanel, with the panel being their
keylistener. In the KeyPressed, I would like to get component's user
data like so: event.getComponent().getUserData();
|
JComponent#getClientProperty(Object key)
JComponent#putClientProperty(Object key, Object value)
--
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Thu Jun 17, 2004 12:38 pm Post subject: Re: Associating user data with AWT/Swing component? |
|
|
On Thu, 17 Jun 2004 15:17:14 +0300, Dr. Len wrote:
| Quote: | Do Swing/AWT components have a simple facility for associating user
data (Integer) with the component?
|
What the heck are you talking about?
What is the purpose of this 'Integer'?
--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
|
|
| Back to top |
|
 |
Dr. Len Guest
|
Posted: Fri Jun 18, 2004 8:08 am Post subject: Re: Associating user data with AWT/Swing component? |
|
|
On Thu, 17 Jun 2004 14:35:12 +0200, "ak" <spam (AT) imagero (DOT) com> wrote:
| Quote: | Do Swing/AWT components have a simple facility for associating user
data (Integer) with the component?
I have multiple JTextFields in my JPanel, with the panel being their
keylistener. In the KeyPressed, I would like to get component's user
data like so: event.getComponent().getUserData();
JComponent#getClientProperty(Object key)
JComponent#putClientProperty(Object key, Object value)
|
Thanks, this is exactly what I was looking for.
|
|
| Back to top |
|
 |
Frank D. Greco Guest
|
Posted: Sun Aug 15, 2004 9:50 pm Post subject: Re: Associating user data with AWT/Swing component? |
|
|
Dr. Len <len (AT) wohoo (DOT) org> sez:
| Quote: | Hi NG,
Do Swing/AWT components have a simple facility for associating user
data (Integer) with the component?
I have multiple JTextFields in my JPanel, with the panel being their
keylistener. In the KeyPressed, I would like to get component's user
data like so: event.getComponent().getUserData();
|
Why not subclass your component and put the data within your subclass?
Frank G.
+==========================================+
| Quote: | Crossroads Technologies Inc. |
www.CrossroadsTech dot com |
fgreco at REMOVE!cross!roads!tech!dot!com|
+=========================================+ |
|
|
| Back to top |
|
 |
zoopy Guest
|
Posted: Sun Aug 15, 2004 11:34 pm Post subject: Re: Associating user data with AWT/Swing component? |
|
|
On 17-6-2004 14:38, Andrew Thompson wrote:
| Quote: | On Thu, 17 Jun 2004 15:17:14 +0300, Dr. Len wrote:
Do Swing/AWT components have a simple facility for associating user
data (Integer) with the component?
What the heck are you talking about?
What is the purpose of this 'Integer'?
It's useful, for example, for the popup menu of a JTable with a JMenuItem to copy contents of a |
cell. The table's mouselistener updates, just before showing the popup menu, the menu item with the
row and column on which was clicked [ copyMenuItem.putClientProperty(PROP_SEL_ROW, new
Integer(selRow)); ...]. The menu item's action listener retrieves, if and when it is executed, their
values [ copyMenuItem.getClientProperty(PROP_SEL_ROW); ... ], and thus knows which cell to copy. So,
its a sort of parameter passing... (and it avoids declaring and "misusing" member variables for this
purpose)
Regards,
Z.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|