Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Markus - 29 Nov 2005 15:36 GMT
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
IchBin - 29 Nov 2005 16:19 GMT
> I want to show linenumbers left of my JTextArea but I have no (good)
> idea how to implement it. :-/
[quoted text clipped - 4 lines]
>
> 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);

Signature

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

IchBin - 29 Nov 2005 16:36 GMT
> I want to show linenumbers left of my JTextArea but I have no (good)
> idea how to implement it. :-/
[quoted text clipped - 4 lines]
>
> 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.

Signature

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

IchBin - 29 Nov 2005 16:42 GMT
>> I want to show linenumbers left of my JTextArea but I have no (good)
>> idea how to implement it. :-/
[quoted text clipped - 13 lines]
> 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;
Signature


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

oulan bator - 29 Nov 2005 16:56 GMT
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
Roedy Green - 29 Nov 2005 17:41 GMT
>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.