Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

How can you resize a JScrollPane?

+14 votes
I've tried setting its preferred size with scrollPane.setPreferredSize(Dimension) with a new Dimension object, but then upon opening the program, regardless of the values in the Dimension the JScrollPane has not changed size. Is there some other way to go about this?
asked Oct 19, 2016 in CSC 285 (F16) by Blake Erquiaga (100 points)

2 Answers

+2 votes
If you try adding the ScrollPane to the center of BorderLayout, it should resize automatically:

frame.add(scrollPane, BorderLayout.center)
answered Oct 19, 2016 by Kevin Barbian (100 points)
+2 votes

I think you may need to call frame.pack() after setting the preferred size, to get Swing to redo the layout... there could be other issues though...

answered Oct 20, 2016 by Forrest Stonedahl (3,438 points)