how to add jscrollpane to jframe?

后端 未结 1 1836
小蘑菇
小蘑菇 2020-12-02 01:40

I have following source code...Can someone please give me an advice how to add jscrollpane onto jframe? I tried several time to add it to jframe but without any progress. I

相关标签:
1条回答
  • 2020-12-02 01:50

    JFrame uses a BorderLayout by default. It's default position (if you don't specify one) is CENTER.

    BorderLayout will only allow one component to occupy any of it's 5 available positions.

    So when you do...

    jframe.add(scrollFrame);
    jframe.add(container);
    

    It adds the scrollFrame to the center position and effectively removes it when you add container (it doesn't actually remove it, but the result is just about the same).

    Try supplying a position constraint. For example...

    jframe.add(scrollFrame);
    jframe.add(container, BorderLayout.SOUTH);
    

    See How to use BorderLayout for more details

    0 讨论(0)
提交回复
热议问题