Results 1 to 3 of 3
  1. #1
    Dinesh_rockz is offline Member
    Join Date
    Jan 2011
    Location
    India
    Posts
    22
    Rep Power
    0

    Post JTextArea How To get one Line only..?

    hi to all..!

    how to get the current cursor line text only in jtextarea..?:(

    Java Code:
    import javax.swing.*;
    import java.awt.event.*;
    
    class demo extends JFrame implements ActionListener
    {
    
    JTextArea txt=new JTextArea();
    JButton but=new JButton("Get Current Cursor Line Text Only..");
    
    demo()
    {
    super("demo");
    setLayout(null);
    
    txt.setBounds(0,0,450,450);
    
    but.setBounds(0,455,300,30);
    but.addActionListener(this);
    
    add(txt);
    add(but);
    
    
    
    }
    
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource().equals(but))
    {
    //  HERE I NEED CURRENT CURSOR LINE TEXT ONLY..
    //JOptionPane.showMessageDialog(this,"");
    
    }
    
    }
    
    public static void main(String args[])
    {
    
    demo obj=new demo();
    obj.setBounds(0,0,600,600);
    obj.setDefaultCloseOperation(2);
    obj.setVisible(true);
    }
    
    }
    Last edited by Dinesh_rockz; 01-13-2011 at 02:41 AM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    Retrieve the location of the cursor, then increment up and down until a newline (or the end of text) is encountered.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. JtextArea autoamtic update the last line
    By sircurse in forum NetBeans
    Replies: 1
    Last Post: 10-28-2010, 08:08 PM
  2. Replies: 2
    Last Post: 07-02-2010, 03:20 PM
  3. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 08:51 PM
  4. [SOLVED] Last line in JTextArea wont display
    By Chris.Brown.SPE in forum Advanced Java
    Replies: 5
    Last Post: 04-11-2008, 02:52 PM
  5. How to always show the last line in my JTextArea?
    By Ashley in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 02:01 PM

Posting Permissions

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