Skip to main content

Embedded Objects in Synth Look And Feel

Posted by xuanyun on January 28, 2009 at 6:36 AM PST

As we know, Synth look and feel can be customized with an XML file which satisfies
the Synth
XML format
. After we go through the document, we can conclude that the type
of property in the XML can be one of the following:

  • idref
  • boolean
  • dimension
  • insets
  • integer
  • string

Actually the idref is the most important one, since it is
a type that represent a reference of object, which may be the instance of any
specific class. In fact we can use idref only to specify any property, but in
order to simplify the XML data, other types are also provided.

The string type is not supported in JRE5, it is shipped with
JRE6. So please be careful, if you want to develop a look and feel that can
work under JRE5, you

Related Topics >>


Hi, Thank you for the reply. As you said, the custom renderer looks for values from the synth file. The icon issues are fixed. where should the error logs be checked... is it in java consoles? Facing another issue with the background colors to the cell. The custom renderer has a default jlabel component. i am trying to bring a different background color to parent node and leaf node. The parent node color should fill the entire width and height designated for that node, (say for eg., the parent nodes in a tree should always have a black background and the leaf node should have a grey background). tried extending SynthPainter class and overide the paintTreeCellBackground method. The parent node has a black background color set. but when the focus switches to the leaf node, the background color of the parent node is not retained. hope i am clear. Regards.

Hi, Can you please point me to documents which would help me in designing the UI with Synth L&F. While integrating the existing java application with a synth look and feel, i am encountering problems with rendering the cells of a tree. The existing application has a customized renderer that renders each cell of the tree with an icon and name. this icon to a node changes dynamically based on the data the node holds. This custom renderer does not work with synth. Can the icons be changed dynamically using the synth style? Kindly assist in this effort. Thanks.

Synth look and feel support custom renderer. In your case, may be the custom renderer depends on some values from default L&F. You may have to check the error log and the renderer source code to find out the solution.

Hello javaxplore, Synth look and feel lacks of document, but you can take a look at these: (2) WIKI: (3) Synth XML File Format: (4) Synth Component Specific Properties:

Synth L&F will automatically set the name of the tree cell renderer component to "Tree.renderer ", but it is not what you need. Since you want two renderer styles, but there is only one name. Actually I prefer not using Synth style to customze the tree cell look, instead customze the renderer with java code. Since the renderer is a JComponent, you can customize its look with java code. You can call setForeground() or setBackground() methods. You can even override the paintComponent() method of the renderer component to do what you want.

Hi, is it Tree.renderer for which the style has to be set? The component specific properties doc says "JTree sets the name of the renderer to Tree.renderer" is the understanding correct? if so, how to set styles in synth xml file? Thank you.

Hi Xuan Yun, Can you give an insight into how to set style for a renderer in the synth xml file? Thank you.

The tree cell is not a JComponent, but the renderer is. I think the most simple way is to set the style to the renderer component directly. You can call the setForeground() or setBackground() method to change the color of the tree cell, you can even override the paintComponent() method of renderder to paint anything you want on the tree cell. If you stick to use Synth to achieve this, you can get the current painting JComponent from the SynthContext in paintTreeCellBackground() method, then check its name, if it is tree1, you paint an icon, if is tree2, you paint a checkbox... It is kind of hacking and I don't really recommend this.

Hi Xuan Yun, Thank you for your response. i havent understood on how to go about it. have two renderers one an Icon Renderer and the other is a CheckBox Renderer. Say Tree1 uses the Icon renderer and Tree2 uses a checkbox renderer. Now the l&f of Tree1 is set through synth by binding it by name "Tree1" and tree2 with name "Tree2". so able to set different background style for these two trees. But the region TreeCell style definition in synth xml file is one. so the cells in both the tree take the same style. this treecell style points to paintTreeCellBackground method that is overridden. yes, you were right that treeCell is not a component. how to go about it? hope i am clear Thank you.

Hi javaxplore, since the tree cell is not a JComponent, you can not assign the name for them. Putting the name to the tree object works but thus you can not have different styles for different nodes... The solution may be using different renderer components for different nodes. You can override the getTreeCellRendererComponent() method to return the renderer object according to the painting node. Of course you can define some JLabel styles and bind them to the renderers by name.

Hi Xuan Yun, have another question on tree. how to bind style by name for the TreeCell ? Thank you.

Hi, Fixed this issue. it is the paintTreeBackground method of the SynthPainter class that should be overridden for a l&f of the tree. Thanks

Hi, Thank you. The tree with the custom renderers works fine. Regards.

You can try the "Tree.drawHorizontalLines" and "Tree.drawVerticalLines" properties.

Hi Xuan Yun, When using Synth L&F, how to hide horizontal and vertical lines between nodes? The putClientProperty("JTree.lineStyle", "None"); works only in Metal L&F. Thanks