我不知道为什么,但滑动条只到左边,甚至锁定新的位置。它使用了带有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);
}
这更像是一个片段,但问题是一样的。我不知道我能在一篇文章里放多少代码。
上下分条滑动没有问题,但左右分条滑动就有问题了
滑块只向左移动,甚至锁定新位置
JSplitPane
满足组件的最小尺寸。
我猜是JEditorPane导致了这个问题…
正确,JEditorPane的最小大小似乎等于它的首选大小。
你需要重写你的JEditorPane
的getMinimumSize()
方法来返回一个更合理的值来满足你的需求:
htmlPane = new JEditorPane()
{
@Override
public Dimension getMinimumSize()
{
Dimension d = super.getMinimumSize();
d.width = 100;
return d;
}
};