Does anybody know a simple way to show linenumbers in a JTextArea?

M

Markus

I want to show linenumbers left of my JTextArea but I have no (good)
idea how to implement it. :-/

Has anybody a (simple) solution for this "problem"?

kind regards

Markus
 
I

IchBin

Markus said:
I want to show linenumbers left of my JTextArea but I have no (good)
idea how to implement it. :-/

Has anybody a (simple) solution for this "problem"?

kind regards

Markus
Guess you cold just prefix a line, ala a loop, concat the prefix and
text line into the TextArea with insert(concat(loopIndex+" "+text,
loopIndex).

You may want to do some formatting on the index before the concat.

Or with out a look..

int lineNum = getRows();
insert(concat((lineNum+1)+" "+text, lineNum+1);

--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
I

IchBin

Markus said:
I want to show linenumbers left of my JTextArea but I have no (good)
idea how to implement it. :-/

Has anybody a (simple) solution for this "problem"?

kind regards

Markus
Guess you could do something this..

String separator = " ";
inserRow = textArea.getRow( )+1;
textArea.insert( inserRow + seperator + lineData ), inserRow );

You may want to format the separator field to manage it's size to be
consistent.



--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
I

IchBin

IchBin said:
Guess you could do something this..

String separator = " ";
inserRow = textArea.getRow( )+1;
textArea.insert( inserRow + seperator + lineData ), inserRow );

You may want to format the separator field to manage it's size to be
consistent.
Sorry for two msg's. I am running SeaMonkey and it blows up now when I
send a response to the newsgroups.

Also
inserRow = textArea.getRow( )+1;
should be
inserRow = textArea.getRows( )+1;
--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
O

oulan bator

you can build a Ruler object (that shows line number, based on line
height).
stick together in a panel, this ruler and the JTextArea, add this panel
into a JScrollPane.
1- Maybe you'll need a bit of hack to make the jscrollpane works well
(as in a JTable)
2- je row height can be retreived through the JTextArea font !

BR
 
R

Roedy Green

I want to show linenumbers left of my JTextArea but I have no (good)
idea how to implement it. :-/

Has anybody a (simple) solution for this "problem"?

Use a JTable with a column for the numbers.

Use a Canvas and render the line number and text yourself as I do in
JDisplay to display Java listings on my website.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top