【发布时间】:2016-05-25 14:48:05
【问题描述】:
我有一个从 JPanel 扩展而来的 A 类,它包含一个 JScrollpanel。
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);
}
}
现在我有一个控制器类,它也从 JPanel 扩展而来,它只添加了一个 SearchTapViewImpl 的实例
public class SearchTapController extends JPanel{
view = new SearchTapViewImpl();
// stuff
add((Component)view, BorderLayout.NORTH);
}
现在我有一个从 JFrame 扩展并包含 JTabbedPane 的类 问题是当我添加一个包含 SearchTapViewImpl 实例的 SearchTapController 实例时,滚动窗格不可见。 相反,当我将 SearchTapViewImpl 添加到 Jframe 类时,滚动是可见的。 为什么我通过 SearchTapController 添加时不可见?
// NOT WORKING EXAMPLE
public class StartGUI extends JFrame {
tabbedPane = new JTabbedPane();
tabbedPane.addTab("Search", new SearchTapController() );
}
// WORKING EXAMPLE
public class StartGUI extends JFrame {
tabbedPane = new JTabbedPane();
tabbedPane.addTab("Search", SearchTapViewImpl() );
}
【问题讨论】:
标签: java swing user-interface