kirill-grouchnikov / substance

A modern and high-performant Swing look-and-feel library
164 stars 109 forks source link

JTree rendering with Raven #82

Closed nroduit closed 6 years ago

nroduit commented 6 years ago

Version of Substance

8.0.1

Version of Java

8_161

Version of OS

Linux

The issue you're experiencing (expected vs actual, screenshot, stack trace etc)

Try to migrate from the version 7.0.1 to 8.0.1. I've noticed some small issues with dark themes like Raven:

Version 7.0.1: selection_013

Version 8.0.1: selection_012

  1. The selection of an element of a JTree component is not visible.
  2. The buttons on toolbar have borders and the toolbar separator is not visible. To have flat buttons, I was using button.putClientProperty("substancelaf.componentFlat", Boolean.TRUE);
utybo commented 6 years ago

For 2) look at SubstanceCortex..setFlatBackground

Everything you used to do with putClientProperty has been centralized in SubstanceCortex which imo is a much cleaner API.

kirill-grouchnikov commented 6 years ago

I'm not seeing the tree selection issue in the main Substance demo app. This maybe is a custom tree since it has checkboxes?

Can you attach a small, standalone sample app that reproduces this issue under 8.0.01 build?

As for the client properties, they have all been replaced by various scoped APIs in SubstanceCortex as pointed above. Some of them are still implemented internally by client properties, but that is an implementation detail and should not be relied on going forward.

nroduit commented 6 years ago

Thanks for your prompt reply. For 2), I just replaced by button.putClientProperty("substancelaf.internal.FlatLook", Boolean.TRUE);

I can reproduce the issue with a simple JTree. The problem is related to DefaultTreeCellRenderer:

import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

public class TreeExample extends JFrame {

    public TreeExample() {
        try {
            UIManager.setLookAndFeel("org.pushingpixels.substance.api.skin.SubstanceRavenLookAndFeel");
        } catch (Exception e) {
            e.printStackTrace();
        }

        JTree tree = new JTree();

        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
        DefaultMutableTreeNode vegetableNode = new DefaultMutableTreeNode("Vegetables");
        vegetableNode.add(new DefaultMutableTreeNode("Capsicum"));
        vegetableNode.add(new DefaultMutableTreeNode("Carrot"));
        vegetableNode.add(new DefaultMutableTreeNode("Tomato"));
        vegetableNode.add(new DefaultMutableTreeNode("Potato"));

        DefaultMutableTreeNode fruitNode = new DefaultMutableTreeNode("Fruits");
        fruitNode.add(new DefaultMutableTreeNode("Banana"));
        fruitNode.add(new DefaultMutableTreeNode("Mango"));
        fruitNode.add(new DefaultMutableTreeNode("Apple"));
        fruitNode.add(new DefaultMutableTreeNode("Grapes"));
        fruitNode.add(new DefaultMutableTreeNode("Orange"));

        root.add(vegetableNode);
        root.add(fruitNode);

        DefaultTreeModel model = new DefaultTreeModel(root, false);

        tree.setModel(model);
        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
        renderer.setOpenIcon(null);
        renderer.setClosedIcon(null);
        renderer.setLeafIcon(null);
        tree.setCellRenderer(renderer);

        tree.expandPath(new TreePath(vegetableNode.getPath()));
        tree.expandPath(new TreePath(fruitNode.getPath()));
        add(tree);

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("JTree Example");
        this.pack();
        this.setVisible(true);
    }

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeLater(TreeExample::new);
    }
}
kirill-grouchnikov commented 6 years ago

The tree renderer is due to "Tree.rendererFillBackground" -> false entry getting added to the UIManager defaults table. This is not needed. Will remove tonight for 8.0.02.