I have a simple application that has a JFrame and a JPanel-derived component. In the JFrame I read a data file and pass an object to the Panel. I would like to cause the panel and the Frame to resize to fit the data I want to display. Currently I have a method on the Panel object that takes the data object and does:
Dimension prefSize = new Dimension();
prefSize.height = newObj.numRows()*50;
prefSize.width = newObj.numCols()*50;
setPreferredSize(prefSize);
setSize(prefSize);
However, this does not result in the panel and frame being resized to accomodate the new preferred size of the panel. However, if I put that same code in the frame object (where it calls the above method on the panel) then the frame (and presumably the panel) *do* resize. But that just doesn't seem right to me. The panel is a child of the frame and setting its size should cause a renegotiation of all the components up the chain, right?
Bookmarks