How to make JScrollBar to scroll?

85 views Asked by At

I am working on a project in Netbeans for which I need to use a scrollbar (Swing controls). I have added the same in the JFrame but it is not scrolling. I don't know what is the code to be given to make it scrollable and under which event. I'm new to Java and I would be very grateful if somebody could help and give me the answer.

UI DESIGN

1

There are 1 answers

0
SRM Kumar On

Try to take a Panel and add components to that Panel and set the JScrollPane to that panel and add that to your Frame.

JScrollPane scrollPane = new JScrollPane(yourPanel);
yourFrame.add(scrollPane, BorderLayout.CENTER);

Better to add the scrollpane to the CENTER, so that it will get all the space available to yourFrame.