I have a JPanel with a custom LayoutManager and trying to get it inside a JScrollPane, however, the scroll pane doesn’t seem to know it’s supposed to enable scrolling. No matter how I set preferred size of the components (that is what the javadoc for JScrollPane says it needs), it makes absolutely no difference. Here is the code:
canvas = new JPanel();
JScrollPane scroll = new JScrollPane();
scroll.setViewportView(canvas);
scroll.setPreferredSize(new Dimension(924,700));
canvas.setPreferredSize(new Dimension(2000,2000));
The scrollbars don’t appear. The container of the JScrollPane is set to respect its preferred size. I have checked through the debugger that the preferred size of the canvas is indeed 2000 x 2000 at all times (the LayoutManager ensures this), so what might be going on here?
This is not really an answer, but is a demo sscce that shows that again, your code works fine for me:
This suggests to me that your error lies elsewhere in code that you’ve not posted.