More Synth Subtleties

Quique asked, in the previous story, why the following style doesn't style JTrees properly:

<style id="tree">
  <imageIcon id="treeCollapsedIcon" path="/resources/img/synth/collapsed.png" />
  <property key="Tree.collapsedIcon" value="treeCollapsedIcon" />
  <imageIcon id="treeExpandedIcon" path="/resources/img/synth/expanded.png" />
  <property key="Tree.expandedIcon" value="treeExpandedIcon" />
  <imageIcon id="treeLeafIcon" path="/resources/img/synth/leaf.png" />
  <property key="Tree.leafIcon" value="treeLeafIcon" />
  <imageIcon id="treeOpenIcon" path="/resources/img/synth/open.png" />
  <property key="Tree.openIcon" value="treeOpenIcon" />
  <imageIcon id="treeClosedIcon" path="/resources/img/synth/closed.png" />
  <property key="Tree.closedIcon" value="treeClosedIcon" />
  <property key="Tree.leftChildIndent" type="integer" value="4" />
  <property key="Tree.rightChildIndent" type="integer" value="12" />
  <property key="Tree.scrollsHorizontallyAndVertically" type="boolean" value="true" />
  <property key="Tree.rowHeight" type="integer" value="-1" />
  <property key="Tree.drawHorizontalLines" type="boolean" value="false" />
  <property key="Tree.drawVerticalLines" type="boolean" value="false" />
</style>
<bind style="tree" type="region" key="Tree" />

At a first glance, nothing seems to be wrong here. Unfortunately nodes icons doesn't show. Are all these properties the right ones? They sure are. Are they all in the right place? Nope. The properties Tree.openIcon, Tree.closedIcon and Tree.leafIcon actually belong to UIDefaults and not to the TreeUI. I told you you'd better know Swing internals to use Synth :)

Here is the fix:

  <imageIcon id="treeLeafIcon" path="/resources/img/synth/leaf.png" />
  <defaultsProperty key="Tree.leafIcon" value="treeLeafIcon" />
  <imageIcon id="treeOpenIcon" path="/resources/img/synth/open.png" />
  <defaultsProperty key="Tree.openIcon" value="treeOpenIcon" />
  <imageIcon id="treeClosedIcon" path="/resources/img/synth/closed.png" />
  <defaultsProperty key="Tree.closedIcon" value="treeClosedIcon" />

Note you can also set Tree.expandedIcon and Tree.collapsedIcon with <defaultsProperty />. Synth is very easy to use… when you know where to look.

Comments are closed.