JTextComponent question  
Author Message
IchBin





PostPosted: 2006-2-22 17:31:00 Top

java-programmer, JTextComponent question I have a Paste method that will take in a JTextComponent. I am passing
either JTextField's or JTextArea's. I need to do something differently
based on a JTextArea.

I have no problem determining if I have a JTextField or a JTextArea. The
problem I am having is that I need to know which JTextArea component I
have. What is the instance name of the JTextArea.

Example say between these two..

JTextArea jTextAreaA
JTextArea jTextAreaB

I have tried some reflection. What could I be missing?

private void paste(JTextComponent target)
{
final String method = "paste(JTextField "+target.getText()+" ): ";
if (DEBUGMODE )System.out.println(_Debugheader+ method);
appUtil.setStatus(jStatusArea, _readyMsg, _READY);
try {
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable content = cb.getContents(this);
String s = (String)content.getTransferData(DataFlavor.stringFlavor);
target.setText(s.trim());
} catch (Exception e) {
appUtil.setStatus(jStatusArea, _errorMsg, method + " " + e);
}
if (target instanceof JTextArea) {
//
// if jTextAreaA
// do something
}
}

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
IchBin





PostPosted: 2006-2-22 18:02:00 Top

java-programmer >> JTextComponent question IchBin wrote:
> I have a Paste method that will take in a JTextComponent. I am passing
> either JTextField's or JTextArea's. I need to do something differently
> based on a JTextArea.
>
> I have no problem determining if I have a JTextField or a JTextArea. The
> problem I am having is that I need to know which JTextArea component I
> have. What is the instance name of the JTextArea.
>
> Example say between these two..
>
> JTextArea jTextAreaA
> JTextArea jTextAreaB
>
> I have tried some reflection. What could I be missing?
>
> private void paste(JTextComponent target)
> {
> final String method = "paste(JTextField "+target.getText()+" ): ";
> if (DEBUGMODE )System.out.println(_Debugheader+ method);
> appUtil.setStatus(jStatusArea, _readyMsg, _READY);
> try {
> Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
> Transferable content = cb.getContents(this);
> String s = (String)content.getTransferData(DataFlavor.stringFlavor);
> target.setText(s.trim());
> } catch (Exception e) {
> appUtil.setStatus(jStatusArea, _errorMsg, method + " " + e);
> }
> if (target instanceof JTextArea) {
> //
> // if jTextAreaA
> // do something
> }
> }
>
> Thanks in Advance...
> IchBin, Pocono Lake, Pa, USA
> http://weconsultants.servebeer.com/JHackerAppManager
> __________________________________________________________________________
>
> 'If there is one, Knowledge is the "Fountain of Youth"'
> -William E. Taylor, Regular Guy (1952-)

I can work around this problem in other parts of my code. But, I really
would like to know why I can not determine if I have jTextAreaA or
jTextAreaB.. Or how I can do it.

--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
Bart Cremers





PostPosted: 2006-2-22 18:38:00 Top

java-programmer >> JTextComponent question JTextArea a = new JTextArea();
a.setName("I'm a");
JTextArea b = new JTextArea();
b.setName("I'm b");

...

Bart

 
 
IchBin





PostPosted: 2006-2-22 21:41:00 Top

java-programmer >> JTextComponent question Bart Cremers wrote:
> JTextArea a = new JTextArea();
> a.setName("I'm a");
> JTextArea b = new JTextArea();
> b.setName("I'm b");
>
> ...
>
> Bart
>
Thanks Bart..

--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)