Hello I got two Jpanels on top of each other, the upper panel has a TitledBorder(EtchedBorder) and the lower one has simply an EtchedBorder. The thing is that because the upper has a title the margins are wider than the lower one. I want them to have the same margins. the same size, not as in the picture below
Has this something to do with Insets? any good solution? [ March 21, 2002: Message edited by: Alex Sanchez ]
Hi Alex, Yes you are correct. The titledBorder adds an insets value of 2 to the normal border on the non title edges. You could place your panels into a GridBagLayout and set the insets to 2 to the untitled panel. The code below shows a simple example.
Thanks Manfred! It worked perfect! By the way, does this only work with GridBagLayout? Because right now i'm adding the two panels to a panel that has a BorderLayout(the upper to "North", and the lower to "Center").. Thanx again.
Hi Alex, Unfortunately, I don't know of any other layout that allows the setting of insets. When I have needed it on a BorderLayout I have had to extend the BorderLayout and override the getInsets method. Then I could place anything I wanted into the insets and also create a setInsets method similar to the GridBagConstraints class already has done. If you are going to make a habbit of adjusting the insets you might want to take this approach and create a InsetBorderLayout or something like that. You could also use a FlowLayout which allows you to directly set margins. Each panel would then need to be placed into a FlowLayout so that you could adjust the margins (i.e., 0 for titled and 2 for untitled). Regards, Manfred.
Post by:autobot
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
a bit of art, as a gift, that will fit in a stocking