JScrollpane 需要缩小宽度
我有一个 JScrollpane
,里面有一个 JPanel
(面板包含一些 JLabel
)。
我希望调整滚动窗格的大小以实际更改其大小(可能低于内部组件的首选大小),而不仅仅是视口的大小。
目标是当用户将滚动窗格缩小得太小时,内部面板会优雅地消失(在我的 miglayout 中使用特定的缩小优先级等)。
I have a JScrollpane
that has a JPanel
on the inside (and the panel contains some JLabel
s).
I want resizing the scroll pane to actually change its size (possibly below the preferred size of the inner components), not just the size of the viewport.
The goal is for the inner panel to gracefully disappear (using specific shrink priorities and the like in my miglayout) when the user shrinks the scrollpane too small.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许最好的方法是让包含的组件始终与视口具有相同的宽度。为此,第一个包含的组件(作为
JViewPort
的子组件,传递到JScrollPane
构造函数或设置为viewportView
)需要实现javax.swing.Scrollable。关键方法是getScrollableTracksViewportWidth
,它应该返回true
。这是一个快速但肮脏的可滚动 JPanel :
Probably the best method is to have the contained component always be the same width as the viewport. To do this the first contained component (the one that is the child to
JViewPort
, passed into theJScrollPane
constructor or set as theviewportView
) needs to implementjavax.swing.Scrollable
. The key method isgetScrollableTracksViewportWidth
, which should returntrue
.Here's a quick and dirty scrollable JPanel :