JScrollPane 内的 JPanel
我有一个 JPanel,我在里面动态创建 JCheckBox。 这些必须始终并排添加 JCheckBox。如果侧面有更多空间需要插入,则会创建新的 JCheckBox 行,就像在简单的文本编辑器中一样。
这一切正在完美地发生。但是...
我将此 JPanel 上的布局设置为 FlowLayout,这正是我想要的。
明显的问题是窗口的空间有限。因此,一个好的解决方案是:将此 JPanel 插入 JScrollPane,l 并使其仅在垂直滚动中发生。 但我有问题。尽管您只能显示垂直滚动条,但项目始终“永远”并排添加。而且垂直滚动根本不起作用,只能水平滚动。
我已经尝试了很多方法来使滚动仅垂直,但没有任何效果(如果它有效我就不会在这里:])。
那么,有没有人遇到过类似的问题,可以帮助我吗?
我将非常感谢那些帮助过我的人。
不再。
I have a JPanel and I create, dynamically, JCheckBoxes inside.
These have to be added JCheckBoxes always a side by side. In case there is more space to be inserted in the side, a new line of JCheckBoxes is created, as in a simple text editor.
This is happening perfectly. But ...
I set the layout on this JPanel to FlowLayout, exactly what I want.
The obvious problem is that a window has limited space. So a good solution to this is: Insertion of this JPanel in a JScrollPane,l and making that happen only in the vertical scrolling.
But I have problems. Although you can make only a vertical scroll bar to appear, the items are always added "forever" side by side. And the vertical scroll simply does not work, only horizontally.
I've tried many ways to make the scroll only vertically, but nothing worked (if it had worked I would not be here:]).
So, has anyone had any similar problem, and can help me?
I shall be very grateful to those who help me.
No more.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 ScrollPanes 和 FlowLayouts 处理了同样的问题。我发现最好的解决方案是使用 FlowLayout 的修改版本,该版本考虑了垂直变化。这是此类布局的代码。您可以将它包含在您的项目中并像 FlowLayout 一样调用它,但它实际上可以与滚动窗格配合使用。
I dealt with the same issue with ScrollPanes and FlowLayouts. I found the best solution is to use a modified version of FlowLayout that takes into account vertical changes. Here is the code for such a layout. You can include it in your project and call it just like a FlowLayout, however it will actually work nice with a scrollpane.