This little bit of code is almost straight out of "Core Java2" except it's Netbeanified. I know it gets the image because it prints the right width. But the frame is blank. Where did I go wrong?
The problem appears to be in the layout manager. If I uncomment the call to "getContentPane().setLayout(layout);" I get the image.
I haven't used GroupLayout myself but its Javadoc page seems to require you to add the components through the layout manager, not directly through the content pane.
Rob Spoor wrote:The problem appears to be in the layout manager. If I uncomment the call to "getContentPane().setLayout(layout);" I get the image.
I haven't used GroupLayout myself but its Javadoc page seems to require you to add the components through the layout manager, not directly through the content pane.
Yikes! But netbeans doesn't give us access to the layout manager! It's in the protected code block. You can unlock the code block but that breaks the GUI builder. Surely I'm not the only person to run into this. Gadzillions of people use Netbeans day & night (or at least a few hundred for a few hours a day).
Turns out it was a panel size issue. I just assumed imagePanel would automatically fill the frame. It doesn't. When I set it to the size of the image it works fine.
apchar boiir wrote:But netbeans doesn't give us access to the layout manager! It's in the protected code block. You can unlock the code block but that breaks the GUI builder.
Which is exactly why many people prefer to write GUI code by hand instead of using a GUI designer.