Wednesday, March 17, 2010

While tinkering around at home I produce a lot of small snippets of code that aren't complete projects but come in handy in the future. A lot of times these end up in my programming notes for later (every developer should keep a TiddlyWiki). Recently I've decided that my blog is just as good as any place for some of these pieces of code. My first post will be a vertical button:

I was trying to create a hide-away panel like the project tab in IDEA:

I found several examples online, but didn't like the implementation. One overrode paint() and drew everything from scratch. Another kept a delegate component to do all the painting (which means you have to delegate all the button's properties to the delegate if you want them to apply to the button).

My implementation just rotates the graphics object before painting. The only other trick is to invert the height and width. The source is available on github.

  • All the button's view properties still work (icons, borders, margins, etc)

  • Preferred size is being mis-reported
  • Similar change might be needed for min/max size for some layouts
  • Text in the Motif look and feel doesn't seem to rotate correctly (at least on my Mac)


Subscribe to Post Comments [Atom]

<< Home