Tuesday, June 21, 2011

Annotation Failures With Hibernate & Netbeans

If you receive error messages indicating that certain class files for annotation cannot be found, such as:

com.sun.tools.javac.code.Symbol$CompletionFailure: class file for org.hibernate.annotations.Sort not found

even though the IDE has allowed you to import the annotation and has not thrown any errors until you attempt to build it, your problem is related to inter-module dependencies. Don't ask me why, but if module C uses an annotation "@Sort", via depending on (for example) your hibernate wrapper module, some, or most probably all, of your other modules in the tree (A & B) also need to depend on the hibernate wrapper module otherwise you'll get this error.

I say "some, or most probably all" because I haven't the time or inclination to do a thorough search to find out which module was causing the problem, I just know it was solved as soon as I added the library to all of my modules...

You also need to make sure you've exported all of the appropriate packages in your wrapped libraries, as this can sometimes cause similar problems.

Tuesday, January 18, 2011

JTabbedPane woes on XP LnF

I have had a lot of issues with JPanels within JTabbedPanes. The tabs and added panel body were always being displayed with a grey background, and any inner panels added to the main one would then display with the standard beige colouring, leaving me with ugly grey swathes decorated with brown rectangles. I'm not sure if it was in any way related to working within Netbeans Platform, given that I haven't tried it outside of it, but I do doubt it as the components afflicted are all standard Swing ones.

Solving this the simple but tiresome way necessitated making all of those inner panels translucent so they would display the grey background, a solution that was not ideal as the grey contrasted with the beige in the rest of the interface standing out like the proverbial.

So today I happened to stumble on a new solution whilst looking through the various bug reports on the Sun/Oracle/Java websites (which are all closed as will not fix claiming the issue is not an issue at all, but expected behaviour). All one needs to do is set the UI delegate for the JTabbedPane to BasicTabbedPaneUI or a subclass thereof and the problem is solved. Tabs and the background colour of the panels within them are now displaying as uniformly beige on the XP Look and Feel.

Just make a call like so after creating your JTabbedPane:

myTabbedPane.setUI(new BasicTabbedPaneUI());

and you should be in consistent colouring heaven!

Javadoc References (v6): JTabbedPane  BasicTabbedPaneUI