当我切换选项卡时 JXMultiSplitPane 会变得疯狂
我正在使用 JXMultiSplitPane(来自 SwingX 1.6.2)来实现三窗格水平界面。中心窗格中是一个带有两个选项卡的 JTabbedPane
:一个带有 JTextArea
(当然在 JScrollPane
中),用于输入 Markdown 代码,另一个 JEditorPane
(同样,在滚动窗格中)用于显示渲染的 HTML 预览。当用户切换到预览窗格时,编辑器中的文本将被处理并显示在预览窗格中。
我的问题是,如果我在编辑器中输入长行文本,然后切换到预览,中心窗格将会展开。有时它只是一点点,有时它会占用比屏幕上实际显示的更多的空间。但如果我手动移动其中一个调整大小手柄,所有内容都会弹回原位。
我发现只有两种方法可以在这种情况发生之前处理它:
- 在输入任何文本之前手动调整其中一个窗格的大小。
- 在 MultiSplitLayout 模型中将中心窗格的权重设置为 1。
我无法使用第二个,因为默认情况下它会扩展中心窗格以占据几乎整个窗口。
有办法解决这个问题吗?
更新
经过更多的测试,即使技术(2)也不能保持大小不变;在两个选项卡之间切换会稍微改变中心窗格的大小。
我现在认为问题部分在于选项卡式窗格。 JTextArea
和 JEditorPane
的大小不同,当我在它们之间切换时,JTabbedPane
正在调整大小(因为我正在重置 <每次都显示 code>JEditorPane 文本,这不会是问题,除非 JXMultiSplitPane
会自动调整中心窗格的大小,直到用户通过调整大小强制指定特定大小。所以
我应该能够通过固定 JTabbedPane 的大小来解决这个问题,但仍然可以通过手柄调整大小。
I'm using JXMultiSplitPane
(from SwingX 1.6.2) to implement a three-pane horizontal interface. In the center pane is a JTabbedPane
with two tabs: one with a JTextArea
(in a JScrollPane
, of course) used for entering Markdown code and the other a JEditorPane
(again, in a scroll pane) for displaying a rendered HTML preview. When the user switches to the preview pane, the text in the editor is processed and displayed in the preview pane.
My problem is that if I enter text in the editor with long lines, and then switch to the preview, the center pane will expand. Sometimes it's just by a little bit, other times it'll take up more room than is actually on the screen. But if I move one of the resize handles manually, everything will snap back in place.
I've found only two ways to deal with this before it happens:
- Manually resize one of the panes before entering any text.
- Give the center pane a weight of 1 in the MultiSplitLayout model.
I can't use the second one since it will expand the center pane to take up almost the whole window by default.
Is there a way to fix this?
Update
After a little more testing, even technique (2) doesn't keep the size constant; switching between the two tabs changes the size of the center pane slightly.
I now believe that the problem is partly with the tabbed pane. The JTextArea
and the JEditorPane
do not have the same size and that JTabbedPane
is resizing when I switch between them (since I'm resetting the JEditorPane
text every time. This wouldn't be a problem except that JXMultiSplitPane
will keep automatically resizing the center pane until the user forces a specific size by resizing manually.
So I should be able to fix the issue by making the size of the JTabbedPane
fixed, but still able to be resized by the handle bars. Any tips on doing that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MultiSplitLayout 是 .. 一个 LayoutManager,所以你必须了解它是如何工作的(我也是,我自己也不太熟悉:-)
基本布局根据组件的 prefSize 进行,权重用于分配相对于组件的多余/缺失空间县默认情况下,分隔线是“浮动的”,即它们位于基本机制布局的组件之间。当用户触摸分隔器时,分隔器是“非浮动的”,其尺寸适合于分隔器之间。这就是您在移动分隔线一次后看不到尺寸贪婪的原因。因此,一种解决方法是
在管理器完成初始布局后修复分隔线
或者,给予权重更多的权重 - 强制布局管理器将它们用于布局本身(而不是仅用于分配多余/缺失的空间) )。副作用是可以设置组合的 prefSize(通过布局,这是不可能的,但谁是完美的;-)
不确定我更喜欢哪种方式或者是否/如何可以变得更容易在多分裂..
The MultiSplitLayout is .. a LayoutManager, so you have to understand how it works (me too, not overly familiar with it myself :-)
The basic layout happens according to the component's prefSize, the weights are for distributing excess/missing space relative to the pref. By default, the dividers are "floating", that is they are positioned between the components as layouted by the basic mechanism. The moment a user touches a divider, dividers are "not-floating", comp sized to fit in-between the dividers. That's the reason for you not seeing the size-greed after moving the divider once. So one ways out is to
fix the dividers after the manager has done its initial layout
Alternatively, give more weight to the weights - force the layoutManager to use them for the layout itself (instead of only for the distribution of excess/missing space). A side-effect is that the prefSize of the comps might be set (by the layout, which is a no-no-never, but who's perfect ;-)
Not sure which way I would prefer or if/how that could be made easier in the multisplit ..