我有一个从JPanel扩展的A类,它包含一个JScrollpanel。
style
现在我有一个从JPanel扩展的控制器类,它只添加了一个SearchTapViewImpl实例
SearchTapViewImpl extends JPanel implements SearchTapView {
SearchTapViewImpl(){
JPanel panel = new JPanel();
// ... add stuff to this panel
JScrollPane scrollPane = new JScrollPane(panel)
//create stuff
add(anotherPanel, BorderLayout.NORTH);
add(scrollpanel, BorderLayout.CENTER);
}
}
现在我有一个从JFrame扩展并包含JTabbedPane的类 问题是当我添加一个SearchTapController实例时,它包含一个SearchTapViewImpl实例,滚动窗格是不可见的。 相反,当我将SearchTapViewImpl添加到Jframe类时,滚动条是可见的。 当我通过SearchTapController添加它时为什么不可见?
public class SearchTapController extends JPanel{
view = new SearchTapViewImpl();
// stuff
add((Component)view, BorderLayout.NORTH);
}
答案 0 :(得分:5)
add((Component)view, BorderLayout.NORTH);
当您将组件添加到BorderLayout
的“NORTH”时,组件始终显示在其首选高度,因此不需要显示scollbar。
尝试将其添加到BorderLayout.CENTER
。