0

I am trying to make a bunch of buttons go into a JScrollPane. However the scroll pane won't seem to fit all of the buttons. The scroller only goes just a bit bigger than the screen. You can see in this image.

There should be lots more buttons but the scroll pane just doesn't contain them.

Also, the scroll pane seems to lag and causes the java program to use lots of memory. Why is that?

Here is my code.

    for (int i = 0; i < lst_Buttons.size(); i++){
       pnl_Main.add(lst_IssuesButtons.get(i));
    }

...

    JScrollPane jsp_Main = new JScrollPane(pnl_Main);
    jsp_Main.setPreferredSize(new Dimension(frm_Main.getWidth(), frm_Main.getHeight()));
    jsp_Main.setSize(frm_Main.getWidth(), frm_Main.getHeight());
    frm_Main.add(jsp_Main);

    pnl_Main.setSize(frm_Main.getSize());
    pnl_Main.setPreferredSize(frm_Main.getSize());

    frm_Main.setPreferredSize(new Dimension(400, 600));
    frm_Main.pack();

Thank you so much ahead of time. If you need more information just comment me.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
ikhaliq15
  • 143
  • 1
  • 12
  • 1
    Please edit your question to include a [mcve] that exhibits the problem you describe. Also, [don't use `setPreferredSize()` when you really mean to override `getPreferredSize()`](http://stackoverflow.com/q/7229226/230513). – trashgod Sep 11 '16 at 10:22
  • 1
    @trashgod I made small example and know it didn't do anything stated above. It just worked. Could it be that I have to many buttons on the frame. I have like over 1000 buttons. – ikhaliq15 Sep 11 '16 at 10:29
  • 1
    Set `N = 10` in this [example](http://stackoverflow.com/a/16733710/230513) to test 1000 buttons; no problem here, but increase the value to see where it starts to lag on your platform. – trashgod Sep 11 '16 at 10:45

0 Answers0