2015-10-09 15 views
1

我不知道为什么,但滑块只能左移,甚至锁定新的位置。 它使用带有JTree和JEditorPane的NestedJSplitPane教程的修改版本。 我的猜测是,JEditorPane中引起该问题...JSplitPane只滑到一边

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); 
} 

这更多的是一个文档片断的,但问题是一样的。 林不知道,我可以在一个职位多少代码。

向上和向下拆分可以滑动没有问题,但左侧和右侧会导致问题。

+0

setDividerLocatin(双)是没有意义的,当意识到组件上未显示的组件,如0.5/0根本不算什么 – MadProgrammer

+0

好主意,但那不是我的问题。滑块只能到一边并粘在那里。 –

回答

1

滑块只进行到左,甚至锁定在新的位置

JSplitPane方面的部件的最小值的大小。

我的猜测是,JEditorPane中引起该问题...

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

你需要重写你JEditorPanegetMinimumSize()方法来回报您的质量要求更合理的值:

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

     return d; 
    } 
}; 
+0

太棒了!花了一些时间弄清楚,我必须用你的覆盖来替换'htmlPane = new JEditorPane();'。谢谢。 –