JSplitPane 仅向一侧滑动

JSplitPane slide only to one side

我不知道为什么,但是滑块只会向左移动,甚至会锁定新位置。 它使用带有 JTree 和 JEditorPane 的 NestedJSplitPane 教程的修改版本。 我的猜测是,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);
}

这更像是一个片段,但问题是一样的。 我不确定,我可以在一个 post.

中放入多少代码

上下拆分滑动没问题,左右滑动就出问题

the slider only goes to the left and even locks the new position

A JSplitPane 遵守组件的最小尺寸。

My guess is, that the JEditorPane causes the problem...

正确,JEditorPane 的最小大小似乎等于其首选大小。

您需要将 JEditorPanegetMinimumSize() 方法重写为 return 更符合您要求的值:

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

        return d;
    }
};