In our product, we have frames that are basically three inheritance levels down from what is essentially a JDialog
. This frame overrides the default pack()
method as shown:
@Override
public void pack() {
this.setSize(getMaximumSize());
validate();
super.pack();
}
@Override
public Dimension getMaximumSize(){
return super.getPreferredSize();
}
pack()
here gets called after pretty much everything is on the screen. Lots of these windows have a title bar, a couple of tool bars, a pane that holds the main content (can often be mostly empty), and a status bar at the bottom.
My problem appears to be that when it calls the getPreferredSize()
for the container, the result is just too small, i.e. the width seems okay, but the height isn't. Reading through the docs, it seems like the preferred size is computed based on the layout manager if it isn't set explicitly (which I'm pretty sure it isn't). I'm not quite sure how it calculates or if I should be doing something else first.
Anybody have any idea or thoughts as to what my problem could be here? It's not always too small, just some of the time. Please let me know what other information/code may be helpful to figuring this out. Thanks.