Java:jscrollpane禁用水平滚动
我想在 jscrollpane 上添加 Jpanel;我也只想垂直滚动。我想设置 jPanel“flowLaout”的布局,并通过 jpanel.add(component) 方法将多个组件添加到我的代码中的 jPanel 中。结果是所有组件都放置在超出 jpanel 宽度的一行中并且未显示。我已经使用了这个技巧,但都失败了:
jScrollPane1.setHorizontalScrollBar(null);
jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
I want to add a Jpanel on a jscrollpane; also I want to have only vertical scrolling. I want to set layout of my jPanel "flowLaout" and add several components to my jPanel in my code by jpanel.add(component) method. The result is that all components are placed in just one row that excide width of jpanel and are not shown. I have used this tricks and both failed:
jScrollPane1.setHorizontalScrollBar(null);
jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
换行布局应该适合您。
Wrap Layout should work for you.
我不确定您当前项目的详细信息,但我会推荐 MigLayout。它从来没有给我带来过错。
我目前正在编写一个触摸屏界面,其中嵌套的 MigLayout 面板深度可达 4 或 5 层,并且没有遇到任何问题。
I am unsure of the particulars for your current project, but i would recommend MigLayout. It has never served me wrong.
I am currently writing a touchscreen interface with nested MigLayout panels up to 4 or five layers deep, and have not had a single problem.
请使用以下策略打开垂直滚动并关闭水平滚动(适用于 Java SE 7):
Please use the below policy to turn on vertical scrolling and turn off horizontal scrolling(Works with Java SE 7):