aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes BoxLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "BoxLayout" Watch "BoxLayout" New topic
Author

BoxLayout

Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179
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

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179
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

Joined: Jul 08, 2003
Posts: 24184
    
  34

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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BoxLayout