JSplitPane只向一个方向移动

时间:2014-03-26 02:34:25

标签: java swing nested direction jsplitpane

我有一个嵌套的JSplitPane,底部的拆分窗格只会向左移动。即使我把它移到左边,它也不会移动到该位置的右侧。

    dataEntry=new JTabbedPane();
    formformat=new JPanel();
    dataEntry.addTab("Table Entry", tableScroll);
    dataEntry.setMnemonicAt(0, KeyEvent.VK_1);
    dataEntry.addTab("Form Entry", formformat);
    dataEntry.setMnemonicAt(0, KeyEvent.VK_2);

    utils=new JTabbedPane();
    helphtml=new JEditorPane();
    utils.addTab("Field Help", helphtml);
    utils.setMnemonicAt(0, KeyEvent.VK_3);
    microImage=new JLabel();
    utils.addTab("Image Navigation", microImage);
    utils.setMnemonicAt(0, KeyEvent.VK_4);

    //leftright=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
    //        new JPanel().add(dataEntry), new JPanel().add(utils));
    leftright=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    leftright.add(dataEntry);
    leftright.add(utils);
    leftright.setContinuousLayout(true);
    leftright.setOneTouchExpandable(true);
    try {
        System.out.println("divx loc"+sa.getXDivider(username));
        leftright.setDividerLocation(sa.getXDivider(username));
    } catch (Exception e1) {
        leftright.setDividerLocation(750);
    }
    createImage();
    if(!imgurl.equals("NONE"))
        topbot=new JSplitPane(JSplitPane.VERTICAL_SPLIT,imgpnl, leftright);
    else
        topbot=new JSplitPane(JSplitPane.VERTICAL_SPLIT,batchImage, leftright);

    topbot.setOneTouchExpandable(true);
    try {

        System.out.println("divy loc"+sa.getYDivider(username));
        topbot.setDividerLocation(sa.getYDivider(username));
    } catch (Exception e) {
        topbot.setDividerLocation(600);
    }

注释掉的构造函数也不起作用,我已经尝试了两种方法,两种方法都没有改变任何东西。

为什么水平分割板只朝一个方向移动?垂直分割窗格没有问题,可以上下移动而没有任何问题。

1 个答案:

答案 0 :(得分:3)

分割窗的灵活性将受到其所包含组件的最小尺寸的限制。

  

要使拆分窗格正常工作,通常需要在拆分窗格中设置组件的最小大小,以及拆分窗格或其包含的组件的首选大小。选择您应该设置的尺寸是一项艺术,需要了解如何确定分割窗格的首选大小和分隔符位置。

来自http://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html#divider

相关问题