I have a JScrollPane with a JPanel in it that works perfectly, except for one flaw. When I run the program, the JScrollPane is added and shows up on its parent panel just fine, however the content inside it does not show up.
If I resize the window or if I scroll on the JPanel the content shows up immediately. I have also checked and the dimensions are correct for both the JPanel and the JScrollPane. Repaint is also called so I don't think I'm missing anything there.
I did also look at this question but it didn't help: JScrollPane doesn't show scroll bars when JPanel is added
Null layouts being used are intentionally, I'm doing my own formatting instead to account for multiple size screens. Thank you ahead of time!
class FilesPanel extends JPanel
{
public JScrollPane scroller;
private FileHolderPanel holder;
public FilesPanel()
{
//setLayout(null);
setBackground(extraLight);
holder = new FileHolderPanel();
System.out.println(holder.getWidth() + " " + holder.getHeight() + " " + holder.getX() + " " + holder.getY() + " " + holder.getBounds());
scroller = new JScrollPane();
JViewport viewport = new JViewport();
viewport.add(holder);
scroller.setViewport(viewport);
scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scroller.setBorder(BorderFactory.createEmptyBorder());
scroller.setBackground(blue);
add(scroller);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
scroller.setLocation(0, 0);
scroller.setSize(filesWidth, frame.getHeight() - 40);
}
class FileHolderPanel extends JPanel
{
public FileHolderPanel()
{
setBackground(extraLight);
setLayout(null);
setVisible(true);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
}
}
}

paintComponent, this is NOT how custom painting should be used, nor is it a good idea. The "main" problem, as near as I can tell is failure of theFileHolderPanelto provide appropriate sizing hints for theJScrollPaneto use - MadProgrammerviewport.add(holder);is also not required - MadProgrammer