Article View: aus.computers.java
Article #1174Help needed using textArea
From: Michael Rowlands
Date: Tue, 29 Jun 1999 00:00
Date: Tue, 29 Jun 1999 00:00
40 lines
2112 bytes
2112 bytes
Hi,
I wondered if anyone could tell me how to capture a users selection in the
textArea
i.e. when they want to cut and paste. As my methods currently overwrite all
text in the textArea, how do you get where the cursor is currently
positioned and paste the text there. i.e.
else
if (cmd.equals(cutText))
{
StringSelection data = new StringSelection(textArea.getText());
clipboard.setContents(data, data);
textArea.setText("");
// Think about select selection etc as setText does the lot
}
else
if (cmd.equals(pasteText))
{
Transferable clipData = clipboard.getContents(this);
String s;
try
{
s =
(String)(clipData.getTransferData(DataFlavor.stringFlavor));
}
catch (Exception evtt)
{
s = evtt.toString();
}
textArea.setText(s);
// I HAVE TRIED THE FOLLOWING
// need anotrher var "int" textArea.insert(s);
// try insert from that Aussie "StringBuffer.insert(int, String);"
// testing paste from editMan, doesnt work
// textArea.paste(s);
}
Cheers
Michael Rowlands
Technical Details
Message-ID:
<930613456.245685@Chaos.es.co.nz>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10fd6d,4a09a47064db3461,start X-Google-Attributes: gid10fd6d,public X-Google-Thread: 113ae9,4a09a47064db3461,start X-Google-Attributes: gid113ae9,public X-Google-Thread: 10a146,4a09a47064db3461,start X-Google-Attributes: gid10a146,public X-Google-Thread: 10d6db,4a09a47064db3461,start X-Google-Attributes: gid10d6db,public From: "Michael Rowlands" <michaelrowlands@bigfoot.com> Subject: Help needed using textArea Date: 1999/06/29 Message-ID: <930613456.245685@Chaos.es.co.nz> X-Deja-AN: 494964924 Cache-Post-Path: Chaos.es.co.nz!unknown@p56-max5.dun.ihug.co.nz Organization: The Internet Group (Dunedin) X-MSMail-Priority: Normal X-Priority: 3 X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/) X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Newsgroups: aus.computers.java,comp.lang.java.gui,comp.lang.java.help,comp.lang.java.programmer