在JXMultiSplitPane中链接垂直和水平分隔线?

时间:2019-09-11 08:29:50

标签: java jxmultisplitpane

我正在尝试使用JXMultiSplitPane创建2 * 2网格。例如

left.top | right.top

left.bottom | right.bottom

创建网格很简单。问题是,如果垂直分隔线从左向右拖动或水平分隔线向上或向下拖动,我需要一种可以调整所有面板大小的解决方案。

似乎,当我定义布局定义时,它在行或列分隔符上链接为2 * 2网格将具有一个垂直分隔符和2个水平分隔符,反之亦然。我还用代码创建了布局,但是在将子节点添加到左右列时尝试使用相同的水平分隔符实例。这种方法确实链接了水平分隔线,并且通过向上或向下拖动右水平分隔线也移动了,但是由于某种原因,可见的左水平分隔线无法与之交互。我认为是因为无法将同一AWT组件添加到多个组件中?

下面的代码是我尝试过的。如果我不使用相同的Divider实例,而是对每个列分隔符使用new Divider()。可以向上或向下拖动两个分隔线,但是它们完全相互独立,没有用。

final Split main = new Split();

/** Left column **/
final Split leftColumn = new Split();
leftColumn.setWeight(0.5);
leftColumn.setRowLayout(false);

/** Right column **/
final Split rightColumn = new Split();
rightColumn.setWeight(0.5);
rightColumn.setRowLayout(false);

/** Shared horizontal divider **/
final Divider sharedDivider = new Divider();

main.setChildren(leftColumn, new Divider(), rightColumn);

final Leaf leftTop = new Leaf("left.top");
leftTop.setWeight(0.5);
final Leaf leftBottom = new Leaf("left.bottom");
leftBottom.setWeight(0.5);

final Leaf rightTop = new Leaf("right.top");
rightTop.setWeight(0.5);
final Leaf rightBottom = new Leaf("right.bottom");
rightBottom.setWeight(0.5);

/** Add the leafs and the shared horizontal divider **/
rightColumn.setChildren(rightTop, sharedDivider, rightBottom);
leftColumn.setChildren(leftTop, sharedDivider, leftBottom);

JXMultiSplitPane splitPane = new JXMultiSplitPane();
MultiSplitLayout layout = new MultiSplitLayout(main);

0 个答案:

没有答案