Java 将JscrollPane添加到另一个扩展到JPanel的类后,它将消失

Java 将JscrollPane添加到另一个扩展到JPanel的类后,它将消失,java,swing,user-interface,Java,Swing,User Interface,我有一个从JPanel扩展而来的类a,它包含一个JScrollpanel SearchTapViewImpl extends JPanel implements SearchTapView { SearchTapViewImpl(){ JPanel panel = new JPanel(); // ... add stuff to this panel JScrollPane

我有一个从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 问题是,当我添加一个SearchTapController实例(其中包含一个SearchTapViewImpl实例)时,滚动窗格不可见。 相反,当我将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() ); 
}

将构件添加到
边框布局的“北部”时,构件始终以其首选高度显示,因此无需显示scollbar

尝试将其添加到
边框布局。居中

将构件添加到
边框布局的“北部”时,构件始终以其首选高度显示,因此无需显示scollbar


尝试将其添加到
边框布局。居中

还应注意,不需要强制转换到
组件
。还应注意,不需要强制转换到
组件
add((Component)view, BorderLayout.NORTH);