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 rendering is off #39

Open
DalgEllal opened this issue Jul 14, 2017 · 1 comment
Open

JTree rendering is off #39

DalgEllal opened this issue Jul 14, 2017 · 1 comment

Comments

@DalgEllal
Copy link

See image - the tree is cropped and too little indentation
darculajtree

Obtained by this code

package Tools.DarkculaTest;

import com.bulenkov.darcula.DarculaLaf;

import javax.swing.;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import java.awt.
;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DarkculaTest extends JFrame
implements ActionListener
{
public DarkculaTest() throws HeadlessException
{
JTree jTree = new JTree();
Container contentPane = this.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(jTree, BorderLayout.CENTER);
this.setSize(200, 300);
CustomTreeNode root = new CustomTreeNode(0);
jTree.setModel(new DefaultTreeModel(root));

    JButton lookAndFeelSwitchButton = new JButton("Switch lookAndFeel");
    lookAndFeelSwitchButton.addActionListener(this);
    contentPane.add(lookAndFeelSwitchButton, BorderLayout.SOUTH);
}

public void actionPerformed(ActionEvent actionEvent)
{
    switchLookAndFeel();
    SwingUtilities.updateComponentTreeUI(this);
}

private class CustomTreeNode extends DefaultMutableTreeNode
{
    boolean areChildrenDefined = false;
    int level;

    private final int [] counts = new int []{5,7,4,7};

    public CustomTreeNode(int level)
    {
        this.level = level;
    }

    public int getChildCount()
    {
        if(level == 4)
            return 0;

        if (!areChildrenDefined)
            defineChildNodes();

        return (super.getChildCount());
    }

    private void defineChildNodes()
    {
        areChildrenDefined = true;

        for(int index = 0; index < counts[level]; index++)
            add(new CustomTreeNode(level+1));
    }

}

static boolean darculaOn = false;
public static void main(String[] args)
{
    switchLookAndFeel();
    new DarkculaTest().setVisible(true);
}

private static void switchLookAndFeel()
{
    try
    {
        if(darculaOn)
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        else
            UIManager.setLookAndFeel(new DarculaLaf());

        darculaOn = !darculaOn;
    }
    catch (Exception e)
    {
        System.out.println("Unable to set look and feel");
    }
}

}

@DalgEllal
Copy link
Author

The problem seems to be related to the code below in DarculaTreeUI - returning false instead in isSkinny fixes the problem.

@OverRide
public int getRightChildIndent() {
return isSkinny() ? 8 : super.getRightChildIndent();
}

private static boolean isSkinny() {
return true;
}

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

1 participant