Results 1 to 3 of 3
- 01-12-2011, 04:24 PM #1
Member
- Join Date
- Jan 2011
- Location
- India
- Posts
- 22
- Rep Power
- 0
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 01:41 AM.
- 01-12-2011, 05:20 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Retrieve the location of the cursor, then increment up and down until a newline (or the end of text) is encountered.
-
JTextArea has useful methods too in addition to getCarotPosition such as getLineOfOffset, getLineStartOffset and getLineEndOffset
Similar Threads
-
JtextArea autoamtic update the last line
By sircurse in forum NetBeansReplies: 1Last Post: 10-28-2010, 07:08 PM -
Formatting java command line output - Multi line string
By dricco in forum New To JavaReplies: 2Last Post: 07-02-2010, 02:20 PM -
JTextArea on PopUp -JTextArea isn't editable
By Richy76 in forum AWT / SwingReplies: 3Last Post: 02-01-2010, 07:51 PM -
[SOLVED] Last line in JTextArea wont display
By Chris.Brown.SPE in forum Advanced JavaReplies: 5Last Post: 04-11-2008, 01:52 PM -
How to always show the last line in my JTextArea?
By Ashley in forum New To JavaReplies: 1Last Post: 05-26-2007, 01:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks