Results 1 to 9 of 9
  1. #1
    bachtoutou is offline Member
    Join Date
    May 2008
    Posts
    11
    Rep Power
    0

    Default 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:
    Java Code:
        private void jButton1_actionPerformed(ActionEvent e) {
         
            String sel=jTextArea1.getSelectedText();
            if (sel!="")
            {
            jTextArea2.append(sel+"\n");
            jTextArea1.removeAll();
           
            }
            else if(sel=="")
            ;
        
        }

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    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?
    freedom exists in the world of ideas

  3. #3
    bachtoutou is offline Member
    Join Date
    May 2008
    Posts
    11
    Rep Power
    0

    Default

    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

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    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,
    freedom exists in the world of ideas

  5. #5
    bachtoutou is offline Member
    Join Date
    May 2008
    Posts
    11
    Rep Power
    0

    Default

    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.

  6. #6
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Ahhh, ok, here is a sample,

    Java 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,
    freedom exists in the world of ideas

  7. #7
    bachtoutou is offline Member
    Join Date
    May 2008
    Posts
    11
    Rep Power
    0

    Default

    Thank you for replying.I tried to compile it but the list did not appear into the frame.There is nor List nor items.:(:(

  8. #8
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Here is the updated one,

    Java 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....
    freedom exists in the world of ideas

  9. #9
    bachtoutou is offline Member
    Join Date
    May 2008
    Posts
    11
    Rep Power
    0

Similar Threads

  1. How to manipulate a BitSet
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-15-2008, 07:37 PM
  2. JTextArea setting
    By newtojava7 in forum New To Java
    Replies: 1
    Last Post: 01-29-2008, 02:57 AM
  3. How to add a shortcut key from JTextArea
    By sukatoa in forum Advanced Java
    Replies: 2
    Last Post: 01-28-2008, 08:39 AM
  4. JTextArea
    By saytri in forum New To Java
    Replies: 0
    Last Post: 01-13-2008, 01:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •