Insubstantial / insubstantial

Swing look-and-feel library and assorted widgets
193 stars 58 forks source link

SubstanceDefaultTreeCellRenderer issues with HTML #112

Open bobbylight opened 11 years ago

bobbylight commented 11 years ago

When displaying HTML in a JTree, SubstanceDefaultTreeCellRenderer has issues. I think it's related to the rollover effect.

It's difficult to explain in words, but I'll try. When "rolling over" several tree nodes displaying HTML, varying the speed of the rollover, the text using the "default" color in HTML seems to end up a random color in the range [unselected - selected/armed]. Further, on rollover, the "default" color for HTML text is entirely incorrect; it still uses the "unselectedText" color, or something close to it, instead of the color used for rollover text that isn't HTML. However, in some circumstances it'll end up the "correct" color. It seems to have to do with the state of the previously rolled-over item (selected or not).

In other words, it's very strange. :) This looks pretty bad, and makes HTML unusable in tree nodes.

This happens in all skins, but it's most noticeable in skins with drastically different colors used for selected and unselected tree items, such as Graphite Glass. Try the example below, and roll over all tree nodes, up and down, at varying speeds:

import java.awt.*;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;

import org.pushingpixels.substance.api.skin.SubstanceGraphiteGlassLookAndFeel;

public class SubstanceProblem {

   public static TreeModel createTreeModel() {
      DefaultMutableTreeNode root = new DefaultMutableTreeNode("Stuff with HTML");
      root.add(new DefaultMutableTreeNode("<html>This is <font color=red>red</font>"));
      root.add(new DefaultMutableTreeNode("<html>This is <font color=green>green</font>"));
      root.add(new DefaultMutableTreeNode("<html>This is <font color=blue>red</font>"));
      DefaultTreeModel model = new DefaultTreeModel(root);
      return model;
   }

   public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
            try {
               UIManager.setLookAndFeel(new SubstanceGraphiteGlassLookAndFeel());
            } catch (Exception e) { e.printStackTrace(); }
            JFrame frame = new JFrame();
            JPanel cp = new JPanel(new BorderLayout());
            JTree tree = new JTree(createTreeModel());
            cp.add(tree);
            frame.setContentPane(cp);
            frame.pack();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLocationByPlatform(true);
            frame.setVisible(true);
         }
      });
   }

}

I'd assume that color or state is being cached somewhere where it shouldn't be.

In my trees, I typically return the text with the HTML stripped when an item is selected, so you don't see problems there per-se, but the issue with HTML text on rollover is always there.