Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Example almost straight out of book doesn't display image  RSS feed

 
apchar boiir
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
apchar boiir
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
apchar boiir
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
netbeans doesn't give us access to the layout manager

Not so. Check the context menu in the Visual Designer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!