2

I need to make a scroll box that can contain an unknown number of elements. Namely it needs to be able to scroll. I'm not quite sure how to do this. Please help.enter image description here

if_zero_equals_one
  • 1,716
  • 4
  • 17
  • 30

2 Answers2

6

Use a JScrollPane with a JPanel wraped inside it. That way, you can add any number of elements to the JPanel without exceeding the panel's physical size using the JScrollPane.

Here is one part of the very famous oracle tutorial that explains the JScrollPane element: http://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.html

I hope this helps!

krs013
  • 2,799
  • 1
  • 17
  • 17
Sam
  • 2,398
  • 4
  • 25
  • 37
4

You want to use a JList with a custom renderer.

Here's a similar question.

Community
  • 1
  • 1
Reverend Gonzo
  • 39,701
  • 6
  • 59
  • 77