Archived

This topic is now archived and is closed to further replies.

Container / Layout question in Java

This topic is 5150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

this is kinda pissin me off by now.. i''ve been looking for so long. OK my problem is that i just need to SIMPLY get a type of layout in which I put the buttons wherever i want to.. i''m trying to use BoxLayout at the moments.. but it''s givin me problems.. thx in advance

Share this post


Link to post
Share on other sites
You know you''re programming in java when you have to use: org.netbeans.lib.awtextra.AbsoluteLayout.

I have no idea if this is a standard Java thing. The fact that it''s in netbeans makes me wonder, but I''m no java guru. Hope it works for you.

Enjoy

Share this post


Link to post
Share on other sites
quote:
Original post by Timbatron
In swing, there is an AbsoluteLayout, though I''m not sure if that is the exact name.


somehow it doesnt know what Absolutelayout is..

Container Contain = getContentPane ();
Contain.setLayout (new AbsoluteLayout ()); ???

or

new AbsoluteLayout (Contain); ???

this class extend from JFrame ...
thx in advance

Share this post


Link to post
Share on other sites
You have to be using Netbeans, or at least have the Netbeans package installed, in order to use that AbsoluteLayout class. It''s not part of standard Java.

Another trick you can use is to set the layout to null. This will allow you to position the components precisely where you want them. However, this is poor programming practice. Using a null layout means there is no way to ensure the components are positioned correctly across different platforms or different look and feels.

The best way to layout a container is to use a combination of panels or boxes and stack them as needed. For example, you might group some buttons in a Box, postion that Box in a Panel with another Box, then put the Panel in the root container. Having a solid understanding of how layouts affect various containers and which layouts to use when is key to laying out Java components in code. Using a visual layout tool makes this somewhat easier, but you still need to know what you''re doing. I promise you can get almost any layout you want without positioning components absolutely.

Share this post


Link to post
Share on other sites