我正在尝试创建一个应用程序,其中有一个 JSplitPane,其中包含左侧的文档树和右侧的当前编辑器 Pane 。编辑器 Pane 有一个工具栏作为编辑 Pane 的一部分。我的问题是,当拆分 Pane 的右侧组件达到工具栏的大小后,调整包含 JSplitPane 的 JFrame 的大小时,右 Pane 开始“挤压”左 Pane 。
我想知道是否有人知道一种方法,可以使分割 Pane 的两个组件保持相同的比例,并让工具栏停止显示其中的项目,或者有一个“更多”按钮。我在框架工具栏中提供了“更多”功能的底格里斯工具栏,但它似乎不会在 JScrollpane 中调整大小。
感谢您的帮助。
最佳答案
如果我理解正确,您希望在调整父框架大小时让分割 Pane 以相同的优先级对待两侧。如果是这种情况,您可能需要查看方法 JSplitPane.setResizeWeight(double)
.
Specifies how to distribute extra space when the size of the split pane changes. A value of 0, the default, indicates the right/bottom component gets all the extra space (the left/top component acts fixed), where as a value of 1 specifies the left/top component gets all the extra space (the right/bottom component acts fixed). Specifically, the left/top component gets (weight * diff) extra space and the right/bottom component gets (1 - weight) * diff extra space.
考虑到这一点,我会尝试 0.5。
编辑
查看BasicSplitPaneUI的代码,在调整大小时,无论重量如何,它都会考虑左右组件的最小尺寸。请注意,重量仍然很重要。它只是被最少的组件所击败。考虑到这一点,尝试在工具栏或包含它的滚动 Pane 上设置最小尺寸。
关于java - 在 JSplitPane 内调整 JToolbar 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1095575/