Friday, June 20, 2008

JScrollPane - Beer Challenge

Ok, I am fed up and I give up. JScrollPane is ridiculous in its behaviour. Therefore, I challenge you to solve the problem I will describe in a second. The winner gets
  • a bottle of beer of his/her choosing
  • inclusion of his/her code in the open source project (Atlassian IDE plugin). With big-ass comment praising the individual as my personal hero
So, the problem to solve is:
  • take JEditorPane, set it up to display random HTML. The string to display may be empty, may be long, may be whatever
  • set the editor to read-only (this is an optional step)
  • wrap the editor in the JScrollPane (or do whatever you wish to make its contents scrollable if necessary)
  • put the above edit panel in the GridBagLayout in a container that has a variable width and height (is resizeable)
  • put some other controls in the same panel, both above and below the edit pane
  • the resulting edit pane should be at most 200 pixels high, regardless of container's dimensions
  • if the text rendered by the edit pane is "naturally" smaller than 200 pixels, the pane should display at its "natural" height (i.e. whatever component is below the edit pane, should appear immediately below it, not 200 pixels below it)
  • the edit pane should not show scrollers if this is not necessary to fit its contents in by 200 pixels area
  • scrollers should be the "right" size (i.e. not aloowing you to scroll 100000 by 100000 pixels, but just enough to see the whole text of the edit pane)
  • the above should work in the DescriptionPanel class in the Atlassian IDE plugin ( you are welcome to take a look at this code, but you have to register your user name in JIRA Studio to get access (free registration)
  • code must not be an ass-ugly hack only known to Swing voodoo masters after 10 years of initiation in a buddhist monastery in Tibet (i.e. computing size of the JEditPane by parsing rendered HTML and calculating average font sizes, then rendering everything in a temporary, invisible container, then pasting this back to a visible form - like some folks in some forums suggest - is bullshit that I refuse to use. There *must* be a better way)

0 comments:

Post a Comment