简体   繁体   English

JSplitPane仅向一侧滑动

[英]JSplitPane slide only to one side

Im not sure why, but the slider only goes to the left and even locks the new position. 我不确定为什么,但是滑块只会向左移动,甚至会锁定新位置。 It uses a modificated version of the NestedJSplitPane tutorial with JTree and JEditorPane. 它使用带有JTree和JEditorPane的NestedJSplitPane教程的改进版本。 My guess is, that the JEditorPane causes the problem... 我的猜测是,JEditorPane导致了问题...

public frameMenu(){
    JEditorPane htmlPane;
    JTree parkSelect;
    JTree triggerSelect;
    URL helpURL;

    DefaultMutableTreeNode left = new DefaultMutableTreeNode("Tree Left");
    DefaultMutableTreeNode triggerTree = new DefaultMutableTreeNode("Tree Down");
    //nNode.createNodes();

    int HORIZSPLIT = JSplitPane.HORIZONTAL_SPLIT;
    int VERTSPLIT = JSplitPane.VERTICAL_SPLIT;

    boolean continuousLayout = true;

    parkSelect = new JTree(left);
    parkSelect.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    htmlPane = new JEditorPane();
    htmlPane.setEditable(true);

    triggerSelect = new JTree(triggerTree);
    triggerSelect.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    JSplitPane splitPane1 = new JSplitPane(VERTSPLIT, continuousLayout, htmlPane, triggerSelect);
    splitPane1.setOneTouchExpandable(true);
    splitPane1.setDividerSize(2);
    splitPane1.setDividerLocation(0.5);

    JSplitPane splitPane2 = new JSplitPane(HORIZSPLIT, parkSelect, splitPane1);
    splitPane2.setOneTouchExpandable(true);
    splitPane2.setDividerLocation(0.4);
    splitPane2.setDividerSize(2);

    JFrame frame = new JFrame("Trigger Editor");
    frame.setSize(600, 400);
    frame.add(splitPane2);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

This is more of an snipped, but the problem is the same. 这更多的是被窃听,但问题是相同的。 Im not sure, how much code i could put in one post. 我不确定,我可以在一个帖子中放多少代码。

The up and down split can be slided without problems, but left and right causes problems. 向上和向下拆分可以毫无问题地滑动,但是左右会引起问题。

the slider only goes to the left and even locks the new position 滑块仅向左移动,甚至锁定新位置

A JSplitPane respects the minimums size of a component. JSplitPane遵循组件的最小尺寸。

My guess is, that the JEditorPane causes the problem... 我的猜测是,JEditorPane导致了问题...

Correct, the minimum size of the JEditorPane appears to be equal to its preferred size. 正确,JEditorPane的最小大小似乎等于其首选大小。

You will need to override the getMinimumSize() method of you JEditorPane to return a more reasonable value for your requirments: 您将需要重写JEditorPanegetMinimumSize()方法以为您的要求返回更合理的值:

htmlPane = new JEditorPane()
{
    @Override
    public Dimension getMinimumSize()
    {
        Dimension d = super.getMinimumSize();
        d.width = 100;

        return d;
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM