问题描述
界面,如图,当拉动C左边分割线时,C右边的分割线要动,拉动D下面的分割线时,E下面的分割线要动,如何做到拉动分割线时,其他分割线不动,图形及部分代码如下:packagePanel;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Component;importjavax.swing.JButton;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JScrollPane;importjavax.swing.JSplitPane;importjavax.swing.UIDefaults;importjavax.swing.UIManager;importjavax.swing.plaf.ColorUIResource;publicclassJSplitPaneA{privateJSplitPanestpA=newJSplitPane();privateJSplitPanestpAleft=newJSplitPane(JSplitPane.VERTICAL_SPLIT);privateJSplitPanestpAright=newJSplitPane();privateJSplitPanestpArightA=newJSplitPane(JSplitPane.VERTICAL_SPLIT);privateJSplitPanestpArightB=newJSplitPane(JSplitPane.VERTICAL_SPLIT);publicJSplitPaneA(){stpA.setDividerLocation(100);stpA.setDividerSize(8);stpA.setOneTouchExpandable(true);stpA.setLeftComponent(stpAleft);stpA.setRightComponent(stpAright);stpAleft.setDividerLocation(500);stpAleft.setDividerSize(8);stpAleft.setOneTouchExpandable(true);stpAleft.setContinuousLayout(true);stpAleft.setLeftComponent(newJLabel("A"));stpAleft.setRightComponent(newJLabel("B"));stpAright.setDividerLocation(1100);stpAright.setDividerSize(8);stpAright.setOneTouchExpandable(true);stpAright.setLeftComponent(newJLabel("C"));stpAright.setRightComponent(stpArightA);stpArightA.setDividerLocation(200);stpArightA.setDividerSize(8);stpArightA.setOneTouchExpandable(true);stpArightA.setContinuousLayout(true);stpArightA.setLeftComponent(newJLabel("D"));stpArightA.setRightComponent(stpArightB);stpArightB.setDividerLocation(200);stpArightB.setDividerSize(8);stpArightB.setOneTouchExpandable(true);stpArightB.setContinuousLayout(true);stpArightB.setLeftComponent(newJLabel("E"));stpArightB.setRightComponent(newJLabel("F"));//stpAright.setRightComponent(stpArightA);}publicJSplitPanegetJSplitPane(){//TODOAuto-generatedmethodstubreturnstpA;}}
解决方案
解决方案二:
小弟是自学JAVA,只是因为兴趣,麻烦大神指点!
解决方案三:
晕,我还以为这个论坛活跃,第一次提问一点反映都没有
解决方案四:
试试JSplitPane.setResizeWeight(doublevalue)