无滚动条 - JScrollPane 与 JPanel
我有一个 JSplitPane,
JSplitPane jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, movieSearchResultTableScrollPane, movieSearchInfoScrollPane);
我已经设置了:
jSplitPane.setOneTouchExpandable(true);
movieSearchResultTableScrollPane 有一个 JTable,如果将分割窗格拖动到左侧,水平滚动条将在一定长度后可见。
movieSearchInfoScrollPane
有一个附加的 JPanel movieSearchInfoPanel
:
movieSearchInfoScrollPane.setViewportView(movieSearchInfoPanel);
movieSearchInfoPanel
有一些标签组件。我没有为 MovieSearchInfoPanel 指定任何类型的大小。但是,如果我将分割窗格拖到右侧,我就不会得到水平滚动条movieSearchInfoScrollPane
。
我该如何解决这个问题?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为 movieSearchInfoPanel 调用 setPreferredSize()。
但最好使用为面板设置的LayoutManager。然后,所有子组件的首选项大小都用于计算容器的首选项大小,并且滚动会自动出现。
You can call setPreferredSize() for the movieSearchInfoPanel.
But it's better to use LayoutManager set for the panel. Then all the children componnets' pref sizes are used to calculate pref size of container and scroll appear automatically.