使用滚动条动态显示面板的布局
在java中,我一直在尝试创建一个可以接受带有滚动条的其他面板的面板。
我尝试使用网格布局,这工作得很好,除了如果我只添加几个面板,它会增长这些面板以适应父面板的大小。
我尝试使用 flowlayout,但这使得面板水平流动,因为有滚动条。
我该如何制作才能将面板添加到从顶部开始的父面板,并使它们始终具有相同的尺寸(或其首选尺寸)。
此外,当我在事件发生后将面板添加到父面板时,直到我移动或调整表单大小后,它们才会出现。我该如何让它重新喷漆?对其调用 repaint() 不起作用。
In java, I have been trying to create a panel that can accept other panels with a scroll bar.
I tried using gridlayout, and this works fine, except for the fact that if I only add a few panels, it grows those panels to fit the size of the parent panel.
I tried using flowlayout, but this makes the panels flow horizontally as there is a scroll bar.
How do I make it so I can add panels to the parent panel starting at the top and make them always the same size(or their preferred size).
Also, when I add panels to the parent panel after an event, they do not appear until after I move or resize the form. How do I make it repaint? calling repaint() on it did not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设
JScrollPane
,请参阅调整滚动大小窗格。为了方便起见,可滚动客户端,例如JTable
优惠setPreferredScrollableViewportSize( )
,但您始终可以显式设置视口的大小。Assuming
JScrollPane
, see Sizing a Scroll Pane. For convenience,Scrollable
clients such asJTable
offersetPreferredScrollableViewportSize()
, but you can always set the viewport's size explicitly.