Re: Swing Text components
Uncle Sam wrote:
I have to create an application which consists of various text fields
and text areas. Due to layout concerns, the various text components
are distributed between multiples JPanels in a somewhat complex
layout. The hierarchy is as follows:
JFrame
|
JSplitPane
/ \
JPanel JSplitPane
/ \ / \
TextArea JPanel
|
Multiple text fields
Now I have to implement the normal paste functionality for the text
fields. I have created an ActionListener class which can perform the
required operations. However, to perform paste operation, I need to
know which components owns the focus currently. I tried to use the
Component.hasFocus() method on the text areas but the function always
returns false. I tried to call JFrame.getFocusOwner() method but
returns something like:
javax.swing.JRootPane[,
3,23,676x486,invalid,layout=javax.swing.JRootPane$RootLayout,
alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,
preferredSize=]
(Nothing of the above changes no matter which text field has focus)
The paste operation is requested on an action event generated by some
button somewhere in the JFrame. As a result I am not able to paste the
clipboard contents into the proper component.
There's your problem...
Can someone please help me with this? Thank you in advance!
As soon as you press your button the button takes focus (the text field loses
focus before the actionEvent is invoked).
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555