tags:

views:

62

answers:

3

Hi ,

I need to add some invisible component into a JPanel to avoid the issues with grid bag lay out.Which is the best way to add these kind of invisible components?

+2  A: 

You can use the helper methods of the Box class to create such components:

Adding them is done in exactly the same way as you add any other component.

Joey
A: 

My first question would be "why are you using a GridBayLayout?", have you looked at the alternatives, like GroupLayout?

ninesided
(I wasn't the downvoter) GroupLayout is not very helpful as it's primarily intended for software GUI builders. It therefore plays nice with software that produces code but not so with humans that write it.
Joey
yes i am agree with Johannes Rössel ...
Sidharth
I disagree completely, GroupLayout and SpringLayout were both written with GUI builders in mind but are both significantly easier to work with than GridBagLayout when hand coding. If I could -1 your -1, I would.
ninesided
can u give some good and easy to understand code samples to work with Group layout ....since i used this layout from NetBeans and it fails with some platforms (Metal/Windows)
Sidharth
Sun has an excellent example: http://java.sun.com/docs/books/tutorial/uiswing/layout/groupExample.html
ninesided
A: 

Erhmmm you just add them?

Like in:

  jpanel.add( youInvisibleComponent );

???

If you are having problems with the GridBagLayout, you should probably consider using another layout manager :(

OscarRyz
can u suggest those kind of layouts and it shouldn't be commercial ..
Sidharth
Yeap, take a look here in the "Know implementing classes" section: http://java.sun.com/javase/6/docs/api/java/awt/LayoutManager.html
OscarRyz