Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JTree: wide cell render support #922

Closed
VISTALL opened this issue Nov 27, 2024 · 2 comments
Closed

JTree: wide cell render support #922

VISTALL opened this issue Nov 27, 2024 · 2 comments
Milestone

Comments

@VISTALL
Copy link

VISTALL commented Nov 27, 2024

Hello I'm working on adapting IDEA like code (fork named Consulo), found some different in cell render for tree:

JetBrains implementation TreeUI (DefaultTreeUI) Flat implementation TreeUI
image image

It's simple Border panel where icon placed at east.
https://github.com/consulo/consulo/blob/master/modules/desktop-awt/desktop-awt-ide-impl/src/main/java/consulo/desktop/awt/settings/OptionsTree.java

https://github.com/consulo/consulo/blob/master/modules/base/ui-ex-awt-api/src/main/java/consulo/ui/ex/awt/CellRendererPanel.java

    private class MyRenderer extends CellRendererPanel implements TreeCellRenderer {
        final NodeRenderer myTextLabel = new NodeRenderer();
        final JLabel myNodeIcon = new JLabel();
        final JLabel myProjectIcon = new JLabel();

        MyRenderer() {
            setLayout(new BorderLayout());
            add(BorderLayout.CENTER, myTextLabel);
            add(BorderLayout.WEST, myNodeIcon);
            add(BorderLayout.EAST, myProjectIcon);
            setBorder(JBUI.Borders.empty(1, 0, 3, 10));
        }

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            myTextLabel.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
            myTextLabel.setFont(tree.getFont());
            myProjectIcon.setIcon(null);

            Base baseNode = extractNode(value);
            if (baseNode instanceof ConfigurableNode) {
                Configurable configurable = baseNode.getConfigurable();

                if (OptionsEditor.isProjectConfigurable(configurable)) {
                    myProjectIcon.setIcon(TargetAWT.to(PlatformIconGroup.generalProjectconfigurable()));
                }
            }

            return this;
        }
    }
@DevCharly
Copy link
Collaborator

See PR #935

@VISTALL
Copy link
Author

VISTALL commented Dec 9, 2024

Tested patch from PR, and works as expected. Thanks you ;)

@DevCharly DevCharly added this to the 3.6 milestone Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants