Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

rich text format line spacing in JEditorPane

 
robyn byrd
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Situation:
JFrame contains a JPanel having box layout
JPanel contains JList on left, JEditorPane on right
JList is created to show a column of integers, 0...99, which must be selectable (that's why they're in a JList)
JEditorPane display lines of rich text format read from a file

Intent:
to align each integer in the JList with each line of text in JEditorPane

Problem:
even when font sizes are adjusted, the spacing between lines of text doesn't match the spacing between integers in the JList. Is there a way to adjust the line spacing of the rich text read into the JEditorPane? Is there any other way of achieving the above intent?

Thanks in advance.
 
Brian Cole
Author
Ranch Hand
Posts: 924
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a reason you have to use a JEditorPane?
You could use a JList (perhaps with a custom
renderer) on the right side too. Or you could
use a JTable.
 
robyn byrd
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to be able to color individual words in a line of text (syntax highlighting). This can be done with JEditorPane because it supports rich text format, but I was unable to find a way to do this using an ordinary JList. Could this be done with a custom JList renderer?
 
Brian Cole
Author
Ranch Hand
Posts: 924
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Custom renderers can do just about anything. They return an
arbitrary Component that is used as a "rubber stamp" to paint
the list item. You could return a Component that draws fractal
images if you wanted.

In fact, you could even return a JTextPane or a JEditorPane.
It could go something like this
[ November 04, 2005: Message edited by: Brian Cole ]
 
Fire me boy! Cool, soothing, shameless self promotion:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!