• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

HTMLEditorKit and JEditorpane Sizing!!

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a unique situation in which I need to pop up a JWindow when the user brings the mouse over a specific area of my application. Inside this JWindow I need to display text with HTML formatting. I've employed the JEditorPane with an HtmlEditorKit. The text displays well, but I'm having serious problems sizing the window appropriately. Here is what I�ve tried so far:

1. Nothing. No explicit sizing logic, added the JEditorPane to the JWindow using BorderLayout.CENTER. This doesn�t work because there isn�t any word wrap in the JEditorPane, so the window is pretty much a single line of text across the screen. The text I�m using as a test is the preamble to the US Constitution, and with out sizing logic, the window�s pref size is: java.awt.Dimension[width=1774,height=44]!

2. I started to play with the javax.swing.text.View class. I created a subclass of JEditorPane and overrode the setText() method to include the following logic:



I�m hardcoding the value of 160 as the width and trying to determine the height based on that width. This seems to work for small pieces of text, but as the length of the text increases, the values returned aren�t reliable. In the case of the preamble, the last word, �America� is on its own line, but is not visible because the view is returning the wrong value.

Now in the code above, right after �//Comment #1�, I�m using the getMinimumSpan () method. I�ve noticed that in all of my tests that the getMinimumSpan() and getPreferredSpan() methods return the same value � a value that is too small. The getMaximumSpan returns some astronomically large number.

Has anyone had any experience with trying to size a JEditorPane with HTML?? If this was inside my main frame I could use layout managers and other components to size the JEditorPane correctly, but since this is a JWindow that only contains the JEditorPane, I�m sort of stuck!

Thanks in advance,

scott
 
Scott Presley
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one more quick thing...

here is the test text I'm using:

<b>PREAMBLE</b><hr>We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defense, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic