0

I'm trying to create a simple Border layout template and I'm using frame.pack() to determine frame size. I have an invisible label in the centre region and the pack method doesn't seem to be taking the label into account so it doesn't show. I know it does work initially because the frame is initially the right size for the other components. So how can I get the frame to take the invisible label into account? The label is only visible when the button in the centre region is selected. Everything works, apart from you have to manually increase the frame size to see the label.

liloka
  • 1,016
  • 4
  • 14
  • 29

1 Answers1

1

I think that it depends on the layout manager of the container containing the label. Some layout managers compute the preferred size based on the visible components only, and others take invisible components into consideration. GroupLayout, for example, has the setHonorsVisibility method.

Anyway, the easiest way is probably to make the label invisible after having called pack.

See also SetVisible(false) changes the layout of my components within my Panel

Community
  • 1
  • 1
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • I'm using the Border layout manager, and I did try calling pack before turning the label invisible but I'm using frame.pack() which I'm guessing is setting the size of the returned JPanel to the frame. So I'm unsure as to where to put the frame.pack(). – liloka Oct 18 '11 at 21:01