A
Alan Williams
I would like to create a text editor that displays its line numbers on
the left hand side. The line numbers will need to scroll with the
document and handle lines being added or removed.
I'm trying the approach of using one JTextPane within a JScrollPane to
handle the main document. A second non-editable JTextPane is being
used as the RowHeaderView of the JScrollPane. It starts with the same
number of lines as the main document and simply has the text 1, 2, 3
etc...
This works quite well and the line numbers scroll with the main
document. But if you add new rows then I'm having trouble updating the
list of line numbers. When I insert an extra line number (using
setText) at the end the whole list scrolls to the bottom, so it's out
of synch with the main document. I've tried to scroll the line numbers
to be aligned in the correct position immediately afterwards (using
scrollRectToVisible) but this isn't working. I need some way to force
it to re-align itself.
Can anyone help, or have a different approach altogether that I can
use?
Thanks.
Alan
the left hand side. The line numbers will need to scroll with the
document and handle lines being added or removed.
I'm trying the approach of using one JTextPane within a JScrollPane to
handle the main document. A second non-editable JTextPane is being
used as the RowHeaderView of the JScrollPane. It starts with the same
number of lines as the main document and simply has the text 1, 2, 3
etc...
This works quite well and the line numbers scroll with the main
document. But if you add new rows then I'm having trouble updating the
list of line numbers. When I insert an extra line number (using
setText) at the end the whole list scrolls to the bottom, so it's out
of synch with the main document. I've tried to scroll the line numbers
to be aligned in the correct position immediately afterwards (using
scrollRectToVisible) but this isn't working. I need some way to force
it to re-align itself.
Can anyone help, or have a different approach altogether that I can
use?
Thanks.
Alan