i have a class A which extends from JPanel which contains 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);
}
}
now i have a controller class which extends from JPanel too which only adds an instance of SearchTapViewImpl
public class SearchTapController extends JPanel{
view = new SearchTapViewImpl();
// stuff
add((Component)view, BorderLayout.NORTH);
}
now i have a class which extends from JFrame and contains a JTabbedPane The thing is when i add a instance of SearchTapController, which contains an instance of SearchTapViewImpl, the scrollpane is not visible. Instead when i add SearchTapViewImpl to the Jframe class the scrolls are visible. Why is not visible when i add it through the 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() );
}
add((Component)view, BorderLayout.NORTH);
When you add a component to the "NORTH" of the BorderLayout
, the component is always displayed at its preferred height so there is no need for the scollbar to appear.
Try adding it to the BorderLayout.CENTER
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.