Java Look-and-Feel with 'Synth'

| No Comments | No TrackBacks

I have been experimenting with developing a custom look-and-feel for a large-scale Java project that I am working on. The custom look-and-feel is in Synth, which loads an XML file defining the styles (and images) for each defined element. Essentially, it really acts like a skin on top of the existing Java Swing interface. Documentation on this is pretty scarce and not in-depth, and I have picked up a lot of inconsistencies and bugs on the way.

In theory, each component consists of different states, such as DEFAULT, MOUSE_OVER, DISABLED, PRESSED, FOCUSED, SELECTED, and ENABLED. (To use more than one state for a style, use the AND keyword between them.) Insets are defined to determine how much space is needed on each side of the element; sourceInsets are used to prevent the area from being stretched. The 'bind style' element is provided to set the defined style. (To determine the key, programmers need to look at Java documentation, which is appended to the end of this entry.) An example of a button element Synth style is below:

<style id="buttonStyle">

   <insets top="15" left="20" right="20" bottom="15"/>

   <state>

      <imagePainter method="buttonBackground" path="images/button.png" sourceInsets="10 10 10 10"/>

   </state>

</style>

<bind style="buttonStyle" type="region" key="button"/>


Another important note is that each Java Swing element may inherit attributes from other Java Swing elements. For example, a JList is also made up of a JLabel. This opens up several annoying inconsistencies that I have had to work through with little documentation. The more complex the Swing component, the more likely it inherits from several different Swing components, which will need to be restyled. A range of different components can also be used per component, depending on the state of the component. 

Another issue with Synth is that once you use it, you need to create a style for every element. Some of these are very in-depth and require a lot of graphical design work. So, if you just want to change all of your buttons to be a certain colour and theme, Synth is not for you. 

Overall, I like the idea of being able to change the visual aspect to suit the branding of the application and to avoid the use of the ugly Java themes. I've also created custom elements to take on their own brand, much like the way web developers do with CSS. For example, the 'wizard' areas of the application I am developing contain a different theme with a background colour, and the headings are the same style. I simply code the application to use this style when the Swing elements are set up.

In my opinion, there is a major problem with the use of Synth. Not so long ago and before CSS was used, websites suffered from the similar problem. The problem with Synth is that most programmers cannot create good graphics, and most graphical artists cannot program. This is one area where, I believe, Synth has failed. Because of this, there are very few good designs based on the Synth look-and-feel. The introduction of CSS for web development made creating good designs easily and without the need for programming and nesting tables. There are also several tools that enable web designs to be quickly implemented into CSS, and there's nothing similar in the world of Java. 
 
Another issue with Synth is the lack of documentation. There is limited documentation on the Java Sun website, and the documentation is incomplete. Resources that do exist and will provide some help with developing styles in Synth are listed below.
 

Synth Component Properties: http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/plaf/synth/doc-files/componentProperties.html

Synth File Format:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/plaf/synth/doc-files/synthFileFormat.html

Synth: The Region Class:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/plaf/synth/Region.html

Related Entries

No TrackBacks

TrackBack URL: http://jenikya.com/cgi-bin/mt5/mt-tb.cgi/55

Leave a comment

Archives

OpenID accepted here Learn more about OpenID