私は他のみんなとは正反対の問題を抱えているようです。私の JDialog には、デフォルトで最小化ボタンと最大化ボタンの両方があります。最大化ボタンを押すと、ダイアログは最大化されますが、コンテンツは最大化されません。巨大なダイアログの中央に、同じサイズのままです。端をつかんでダイアログのサイズを変更するだけでも同じことが起こります。
WindowStateListener を追加しようとしましたが、呼び出されません。WindowListener を追加しました。それは、Open/Close/Activate/Deactivate でのみ呼び出されます。
そのため、ダイアログのコンテンツをダイアログでサイズ変更するか、最大化ボタンを削除できるようにする必要があります。(そして、最小化ボタンを取り除きたいです。)
ダイアログのコントロールはデータのブロックから動的に作成されるため、ダイアログの作成後に pack() を実行します。そのため、作業する初期サイズがありません。
さて、これがコードです。生成されたすべての UI パネルも GridBagLayouts にあります。
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 ...
}