Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

SubstanceDefaultTreeCellRenderer issues with HTML #112

Open
bobbylight opened this issue Jan 22, 2013 · 0 comments
Open

SubstanceDefaultTreeCellRenderer issues with HTML #112

bobbylight opened this issue Jan 22, 2013 · 0 comments

Comments

@bobbylight
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant