This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BoxLayout

 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic