I'm trying to add my own implementation of jpanel to another jpanel, in a scrollpane, so that as it adds more it will make a list of them down the screen. Unfortunately I can't seem to put space between my jpanels; when I set the second two gridlayout parameters, parts of them get cut off (so that they appear shorter vertically). Any idea why this is happening or how to get around it?
Your CustomDrawing instance never paints itself on the screen. You've overridden the paint method to draw to the BufferedImage's graphics object instead. That object will never be null though, as it's created in the CustomDrawing constructor and never set to null afterwards.
I suggest you change your code:
1) Call drawStuff() in the constructor. There is no need to do it in any painting method, as the painting methods may be called several times a minute. The contents will never change though, so once is enough.
2) Do not override update(Graphics).
3) Do not override paint(Graphics).
4) Override paintComponent(Graphics) like this:
The preferred size issue probably still applies as well.
setPreferredSize does fix my issue, thanks! The reason for all the overridden methods in CustomDrawing is that I'm actually using a much larger, more complicated class that frequently updates instead, I just wrote this one to have something simple to represent the problem I was having without tons of irrelevant code.