• 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

BoxLayout

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I want to apply a boxlayout for a JPanel.
All the examples that i have seen are for frames with this ContentPane thing. I'm not very experienced so i'm stuck here.
So i have allready a frame with layout and i want to add one Jpanel that has box layout to that.

So far i have done so, but it gives me a NullPointer Exception.




thnx
[ August 02, 2004: Message edited by: Juhan Voolaid ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see anything here that should give an NPE. The stack trace should tell you exactly which class, method, and line the NPE occurs on -- show us that code instead.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't add components to a Box. You add components to a container that has a BoxLayout specified as it's layout manager. Take a look at this tutorial on Sun's site.



And then you add components to the listPane.
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahh ... i so stupid.

After working a whole hour with this box layout, i was totally blind and didn't notice that the JPanel that i added was not been created so it is a simple NullPointer exception.

(Sombody should delete this post)
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gregg Bolinger:
You don't add components to a Box.



Actually, a Box is an alternative to JPanel that has a BoxLayout as its default layout manager, and some handy BoxLayout-related methods.

I think Box isn't very widely used because there's a nasty JDK 1.3/1.4 binary incompatibility problem: it used to be a subclass of Container, and then it became a subclass of JComponent; as a result, if you subclass Box, it's very likely that your code will only run under one JDK or another, but not both, depending on which you compile with.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ernest Friedman-Hill:


Actually, a Box is an alternative to JPanel that has a BoxLayout as its default layout manager, and some handy BoxLayout-related methods.

I think Box isn't very widely used because there's a nasty JDK 1.3/1.4 binary incompatibility problem: it used to be a subclass of Container, and then it became a subclass of JComponent; as a result, if you subclass Box, it's very likely that your code will only run under one JDK or another, but not both, depending on which you compile with.



Ahh, I didn't realize that. I thought the Box class was just used to create spacers and glue and what not. That's good to know. Thanks Ernest.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic