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

DefaultTreeCellRenderer icons and colors aren't updated in updateUI()

XMLWordPrintable

    • b03
    • x86
    • windows_2000
    • Verified

        Name: sv35042 Date: 10/09/2002


        FULL PRODUCT VERSION :
        java version "1.4.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
        Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)


        Microsoft Windows 2000 [Version 5.00.2195]

        A DESCRIPTION OF THE PROBLEM :
        DefaultTreeCellRenderer icons and colors aren't updated in
        updateUI() . So when one changes the look and feel and
        calls SwingUtilities.updateComponentTreeUI(), the tree
        icons and colors don't change.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run attached program.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        I expected the icon to change to the windows icon but it
        didn't.

        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.*;
        import javax.swing.*;
        import javax.swing.tree.*;
        import java.net.*;


        class TreeBug3 {
        public static void main(String[] args) throws Exception {
        final JFrame frame = new JFrame();
        JTree tree = new JTree(new String[]{"cell"});
        tree.setCellRenderer(new DefaultTreeCellRenderer()
        /*
        // Here is the fix.
        {
        // should be called by the
        DefaultTreeCellRenderer constructor
        protected void init() {
        setLeafIcon(UIManager.getIcon
        ("Tree.leafIcon"));
        setClosedIcon(UIManager.getIcon
        ("Tree.closedIcon"));
        setOpenIcon(UIManager.getIcon
        ("Tree.openIcon"));

        setTextSelectionColor(UIManager.getColor
        ("Tree.selectionForeground"));
        setTextNonSelectionColor
        (UIManager.getColor("Tree.textForeground"));
        setBackgroundSelectionColor
        (UIManager.getColor("Tree.selectionBackground"));
        setBackgroundNonSelectionColor
        (UIManager.getColor("Tree.textBackground"));
        setBorderSelectionColor
        (UIManager.getColor("Tree.selectionBorderColor"));

        // drawsFocusBorderAroundIcon is private
        but should be protected
        // Object value = UIManager.get
        ("Tree.drawsFocusBorderAroundIcon");
        // drawsFocusBorderAroundIcon = (value !=
        null && ((Boolean)value).
        //
        booleanValue());
        }

        public void updateUI() {
        super.updateUI();
        init();
        }
        }
        */
        );
        frame.getContentPane().add(tree,BorderLayout.CENTER);
        frame.pack();
        frame.show();
        UIManager.setLookAndFeel
        ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        SwingUtilities.invokeLater(new Runnable(){public void run(){
        SwingUtilities.updateComponentTreeUI(frame);
        }});
        }
        }

        ---------- END SOURCE ----------
        (Review ID: 146024)
        ======================================================================

              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: