|
|
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.
|
|

05-21-2008, 04:11 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 11
|
|
|
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:
private void jButton1_actionPerformed(ActionEvent e) {
String sel=jTextArea1.getSelectedText();
if (sel!="")
{
jTextArea2.append(sel+"\n");
jTextArea1.removeAll();
}
else if(sel=="")
;
}
|
|

05-21-2008, 06:50 AM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
|
|
|
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.
|
|

05-21-2008, 11:57 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 11
|
|
|
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
|
|

05-21-2008, 03:29 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
|
|
J've created 2 JtexArea one of them contains values and the other is empty.
uhuh?!!!
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...
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.
|
|

05-21-2008, 03:47 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 11
|
|
|
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.
|
|

05-21-2008, 03:59 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
|
|
Ahhh, ok, here is a sample,
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.
|
|

05-21-2008, 05:01 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 11
|
|
Thank you for replying.I tried to compile it but the list did not appear into the frame.There is nor List nor items.  
|
|

05-21-2008, 09:03 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
|
|
Here is the updated one,
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.
|
|

05-22-2008, 11:36 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 11
|
|
|
It wokrs perfectly!!!!!Thanks a lot for your help
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|