JPanel 内的 JScrollPane JPanel 内的 JPanel 忽略水平换行
我有一个 JPanel,它包含一个 JScrollPane,它包含一个 JPanel:
masterPanel.add(buttonPanel, BorderLayout.NORTH);
inner.setLayout(new BorderLayout());
inner.add(infoPanel, BorderLayout.NORTH);
inner.add(writingPanel, BorderLayout.CENTER);
beholder = new JScrollPane(inner);
masterPanel.add(beholder, BorderLayout.CENTER);
我希望 beholder 成为一个 JScrollPane,以便在滚动 beholder(内部滚动窗格)时,按钮面板将始终显示。这一切都工作正常,但问题是观察者内部的面板不换行。因此,我在 infoPanel 中有一长行文本,导致非常长的、不受欢迎的水平滚动。
如果我只是更改最后一行以添加内部而不是旁观者,它可以正常工作(正确换行),但是当用户向下滚动时按钮面板不会停留在顶部。
我完全被困住了。基本上我的问题是如何使 JScrollPane 内的面板正常自动换行。
问题是水平包裹。即使我将 beholder.setPreferredSize() 设置为非常低的 x 和 y 维度,它也会完全忽略 x 维度,即使它似乎通常遵循 y 维度。
I have a JPanel that holds a JScrollPane that holds a JPanel as such:
masterPanel.add(buttonPanel, BorderLayout.NORTH);
inner.setLayout(new BorderLayout());
inner.add(infoPanel, BorderLayout.NORTH);
inner.add(writingPanel, BorderLayout.CENTER);
beholder = new JScrollPane(inner);
masterPanel.add(beholder, BorderLayout.CENTER);
I want beholder to be a JScrollPane so that the button panel will display at all times while scrolling the beholder (inner scroll pane). This all works fine, but the problem is the panels inside of beholder do not line wrap. So I have a long line of text in infoPanel that causes a very long, undesirable horizontal scroll.
If I just change the last line to add inner instead of beholder, it works fine (wraps correctly), but then the button panel won't stay at the top when the user scrolls down.
I'm totally stuck. Basically my question is how to get the panels inside of the JScrollPane to word wrap normally.
The problem is wrapping horizontally. Even if I set beholder.setPreferredSize() to a very low x and y dimension, it will ignore the x dimension entirely even though it seems to obey the y dimension normally.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 可滚动面板 会帮助你。
I think the Scrollable Panel will help you out.
由于某种原因,这个问题可以通过调用来解决:
这将导致发生换行。
For some reason, this problem is resolved by calling:
This will cause the wrap to occur.