2016-05-25 5 views
1

私はJScrollPanelを含むJPanelから継承するクラスAを持っています。JScrollPaneはJPanelに拡張された別のクラスに追加した後に消えます

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); 
      } 
} 

今私が唯一SearchTapViewImpl

public class SearchTapController extends JPanel{ 

     view = new SearchTapViewImpl(); 
     // stuff 
     add((Component)view, BorderLayout.NORTH); 
} 

のインスタンスを追加しすぎたJPanelから延びコントローラクラスは、今私はJFrameのから拡張するクラスを持っているとJTabbedPaneの が含まれているものがありますSearchTapViewImplのインスタンスを含むSearchTapControllerのインスタンスを追加すると、スクロールペインは表示されません。 代わりに、JframeクラスにSearchTapViewImplを追加すると、スクロールが表示されます。 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()); 
} 

enter image description here enter image description here

答えて

5
add((Component)view, BorderLayout.NORTH); 

あなたがBorderLayoutの「NORTH」にコンポーネントを追加するとscollbarが表示されるために必要はありませんので、コンポーネントは常にその好ましい高さで表示されます。

BorderLayout.CENTERに追加してください。

+0

また、「コンポーネント」にキャストする必要はありません。 – Marv

+0

日食がほしい – Pero

+0

ありがとう – Pero

関連する問題