Whenever you need to understand the difference between the Java JTextArea, JTextPane, and JEditorPane, check out this Sun/Oracle link.
I haven’t tested this with other Java components, but if you want/need to get the “system font”, this code gets the default system font from a
val outputArea = new JEditorPane val fontFamily = outputArea.getFont.getFamily
That code is written in Scala, but as you can see, it converts easily to Java. On Mac OS X 10.10,
fontFamily ends up being “Lucida Grande”.
If you ever need to display an image in a Java JEditorPane, where that
JEditorPane contains HTML content, this solution should work:
I took a little time today to add some new features to my "JustWrite" text editor, and one of the features I'm experimenting with is an animation similar to the current horizontal scrolling area shown at the top of Apple's Mac web page. When you first hit that page the scrolling area is offset a little bit, and then in an animation the scrollbar moves more to the center of the scrolling display area.
Java image FAQ: How can I place an image in the background of a Java text component, such as creating a background image for a
JEditorPane? (i.e., How do I create a Java background or watermark image.)
I'm currently writing a customized text editor in Java, and as part of that, I want to make it easy for the user to increase or decrease the font size in the text editing area (technically a JTextPane). I didn't expect this to be easy, but I've been pleasantly surprised that the following approach seems to work just fine:
I had a problem this weekend with the JEditorPane line wrap (word wrap), where it was wrapping lines on the right margin right in the middle of words. Wherever my sentence hit the right margin, that's where the line wrapped (with no consideration for word boundaries), leaving me with lines that looked like this:
Summary: A simple Java JScrollPane source code example.
When you're first learning how to use Java Swing components, like a JScrollPane it can be a little hard to figure out how to get started. To that end I am trying to share several complete Java source code examples that demonstrate how to work with components like these.