I seem to have the opposite problem of everyone else. My JDialog has both minimize and maximize buttons by default. When the maximize button is pressed, the dialog maximizes - but the content doesn't. It just stays the same size, centered in a huge dialog. Same happens when you just grab the edge and re-size the dialog.
I've tried adding a WindowStateListener - but it never gets invoked. I added a WindowListener - and it's only invoked on Open/Close/Activate/Deactivate.
So, I either need to be able to get the dialog content to re-size with the dialog, OR remove the maximize button. (and I'd like to get rid of the minimize button.)
I do do a pack() after creating the dialog, as the controls in the dialog are dynamically created from a block of data, so I don't have an initial size to work with.
Okay, so here's the code. All the generated UI panels are in GridBagLayouts as well.
public class FastAccessDialog extends JDialog implements BeanActionListener {
private static final long serialVersionUID = 1L;
private static final Cursor waitCursor = new Cursor(Cursor.WAIT_CURSOR);
private Cursor oldCursor;
private JPanel cmdOutput;
private JScrollPane cmdOutputScroll;
public FastAccessDialog(Frame owner, ObjectName bean, String methodName) throws InstanceNotFoundException, IntrospectionException,
ReflectionException, IOException {
super(owner);
setResizable(true);
setModal(false);
setTitle(BeanUtil.cleanUpCamelCase(methodName));
boolean enabled = (UIHintUtil.isEnabled(bean) == EnableState.ENABLED);
// Find the BeanOperationInfo for that method.
MBeanInfo info = JMXConnectionSingleton.getInstance().getMBeanInfo(bean);
MBeanOperationInfo[] operations = info.getOperations();
JComponent comp = null;
for (MBeanOperationInfo opInfo : operations) {
if (opInfo.getName().equals(methodName)) {
comp = OperationsManager.getInstance().createControls(bean, opInfo, this, true, enabled);
break;
}
}
if (comp == null) {
throw new IllegalArgumentException("Unknown method name: " + methodName);
}
Container cont = getContentPane();
cont.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 4);
cont.add(comp, gbc);
cont.validate();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
pack();
}
});
return;
}
... other methods invoked when an operation is performed ...
... none of which are invoked before having the re-size problem ...
}