Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6182947

Trees get wrong color with Synth

XMLWordPrintable

    • b14
    • x86
    • linux_redhat_9.0

      Try the following code:

      import java.awt.*;
      import java.awt.image.*;
      import javax.swing.*;
      import javax.swing.plaf.synth.*;
      import javax.swing.tree.*;

      public class TreeBug {
          public static void main(String[] args) throws Throwable {
              SynthLookAndFeel lookAndFeel = new SynthLookAndFeel();
              lookAndFeel.load(TreeBug.class.getResourceAsStream("treebug.xml"),
                               TreeBug.class);
              UIManager.setLookAndFeel(lookAndFeel);
              JTree tree = new JTree();
              tree.setSize(100, 100);
              DefaultTreeCellRenderer dRenderer = new DefaultTreeCellRenderer();
              tree.setCellRenderer(dRenderer);
              BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_IN\T_RGB);
              tree.paint(image.getGraphics());

              if (!Color.RED.equals(dRenderer.getBackgroundNonSelectionColor())) {
                  throw new RuntimeException("Unexpected color, got: " +
                                             dRenderer.getBackgroundNonSelectionColor\());
              }
          }
      }

      with the following xml file:
      <synth>
        <style id="backingStyle">
          <!-- Make all the widgets that use this skin opaque-->
          <opaque value="TRUE"/>
          <font name="Dialog" size="12"/>
          <state>
            <!-- Provide default colors -->
            <color value="YELLOW" type="BACKGROUND"/>
            <color value="GREEN" type="FOREGROUND"/>
            <color value="YELLOW" type="TEXT_BACKGROUND"/>
            <color value="YELLOW" type="TEXT_FOREGROUND"/>
          </state>
        </style>
        <bind style="backingStyle" type="region" key=".*"/>

        <style id="treeCellStyle">
          <opaque value="TRUE"/>
          <state>
            <color value="WHITE" type="TEXT_FOREGROUND"/>
            <color value="RED" type="TEXT_BACKGROUND"/>
          </state>
          <state value="SELECTED">
            <color value="RED" type="TEXT_FOREGROUND"/>
            <color value="WHITE" type="BACKGROUND"/>
          </state>
        </style>
        <bind style="treeCellStyle" type="region" key="TreeCell"/>
      </synth>

      Notice that null is returned from the renderer, the expected color is red.
      ###@###.### 10/21/04 23:18 GMT

            svioletsunw Scott Violet (Inactive)
            svioletsunw Scott Violet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: