• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Example almost straight out of book doesn't display image

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic