Container / Layout question in Java

Started by
5 comments, last by Metal Typhoon 20 years, 5 months ago
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
Metal Typhoon
Advertisement
In swing, there is an AbsoluteLayout, though I''m not sure if that is the exact name.
My Page : http://acidbase.computed.net
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
My Page : http://acidbase.computed.net
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
Metal Typhoon
If it''s in there, it''ll be in the "org.netbeans.lib.awtextra" package.
My Page : http://acidbase.computed.net
quote:Original post by Timbatron
If it''s in there, it''ll be in the "org.netbeans.lib.awtextra" package.


are u sure it''s the right package.. cuz it''s not being found
Metal Typhoon
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.

This topic is closed to new replies.

Advertisement