• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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: 22816
132
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: 22816
132
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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic