Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2008, 04:11 AM
Member
 
Join Date: May 2008
Posts: 11
bachtoutou is on a distinguished road
How to manipulate JtextArea
Hi,
I use the type JtextArea and I do not know too how to manipulate it.J've created 2 JtexArea one of them contains values and the other is empty.When I clic on a button,the selected item will be moved to the empty JtextArea.
j've developed this code but it does not automatically selects the items(it can be done only manually).And when i want to move an item,it travels but a copy remains in the first JtextArea while i want to move it squarely from the first JtxtArea.Here is my code:
Code:
private void jButton1_actionPerformed(ActionEvent e) { String sel=jTextArea1.getSelectedText(); if (sel!="") { jTextArea2.append(sel+"\n"); jTextArea1.removeAll(); } else if(sel=="") ; }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-21-2008, 06:50 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
How about splitting the texts from the first textArea?

eg. String temp[] = text.split(the selected text);

it will return an array of Strings,

temp[0] is the text from 0 to the last character before the selected text
temp[1] is the text from the first character after the selected text to the last last character of the content...

and by using concat() method, you can retrieve the new text without the current selected text now....

That implementation is applicable if no other text that is similar to the selected text, else all of them will be cutted...

will you post the content of the first textArea?
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-21-2008, 11:57 AM
Member
 
Join Date: May 2008
Posts: 11
bachtoutou is on a distinguished road
Sorry but i don't understand you well.what i want to do is selecting of the hole of the line when i clique by the mouse.My jTextArea contains a list of files's names which are stocked in a database,for exemple:
test.txt
list_client.fmb
bib.pll

is this possible or not?

thank you in advance
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-21-2008, 03:29 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Quote:
J've created 2 JtexArea one of them contains values and the other is empty.
uhuh?!!!

Quote:
When I clic on a button,the selected item will be moved to the empty JtextArea.
There is no item you can get from textArea, only texts...

Quote:
j've developed this code but it does not automatically selects the items(it can be done only manually).
Ahhhh.... so you mean that when you just click that item, it automatically selects, and when you click the button, it will transfer that filenames to the other textArea?and automatically remove the selected filename?

JTextArea is not a good component for that implementation...
JList may fit your needs...

try it,
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-21-2008, 03:47 PM
Member
 
Join Date: May 2008
Posts: 11
bachtoutou is on a distinguished road
Thanks for your suggestion but i d'ont know how to user Jlist.I've tried to insert into a JList but i could not reach.I dont know what are the methods that i need to add and remoove items in JList.
I've found complicated documentation and i did not understand anything.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-21-2008, 03:59 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Ahhh, ok, here is a sample,

Code:
import javax.swing.JList; import javax.swing.DefaultListModel; import javax.swing.JScrollPane; public class test extends javax.swing.JFrame{ DefaultListModel dm = new DefaultListModel(); JList list = new JList(dm); JScrollPane jp = new JScrollPane(); public test(){ this.getContentPane().setLayout(null); this.setBounds(40,40,50,60); jp.setBounds(0,0,50,50); jp.add(list); this.getContentPane().add(jp); addItemToList(); } //This will add some items to your list void addItemToList(){ dm.addElement((Object)"Your file name1"); dm.addElement((Object)"Your file name2"); dm.addElement((Object)"Your file name3"); } public static void main(String args[]){ new test().setVisible(true); } }
Please try to compile it, i've not tested it yet....
Update us,
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-21-2008, 05:01 PM
Member
 
Join Date: May 2008
Posts: 11
bachtoutou is on a distinguished road
Thank you for replying.I tried to compile it but the list did not appear into the frame.There is nor List nor items.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-21-2008, 09:03 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Here is the updated one,

Code:
import javax.swing.JList; import javax.swing.DefaultListModel; import javax.swing.JScrollPane; public class test extends javax.swing.JFrame{ DefaultListModel dm = new DefaultListModel(); JList list = new JList(dm); JScrollPane jp = new JScrollPane(list); public test(){ this.getContentPane().setLayout(null); this.setBounds(100,100,130,100); jp.setBounds(0,0,130,100); this.getContentPane().add(jp,null); addItemToList(); this.setDefaultCloseOperation(3); } //This will add some items to your list void addItemToList(){ dm.addElement((Object)"Your file name1"); dm.addElement((Object)"Your file name2"); dm.addElement((Object)"Your file name3"); } public static void main(String args[]){ new test().setVisible(true); } }
try to have an experiment on it....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-22-2008, 11:36 AM
Member
 
Join Date: May 2008
Posts: 11
bachtoutou is on a distinguished road
It wokrs perfectly!!!!!Thanks a lot for your help
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to manipulate a BitSet Java Tip java.lang 0 04-15-2008 09:37 PM
JTextArea setting newtojava7 New To Java 1 01-29-2008 04:57 AM
How to add a shortcut key from JTextArea sukatoa Advanced Java 2 01-28-2008 10:39 AM
JTextArea saytri New To Java 0 01-13-2008 03:07 AM


All times are GMT +3. The time now is 04:39 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org