I have two simple JDialog dialogs that should be small. The first has a JTextField of 5 columns and a vertical slider under it. The second has a JLabel, a JSpinner and two JButton(s). Both, after pack() and setVisible(), are too wide. For example, the first dialog has a preferred size of about 80, but shows up with width of 258.
Here are a few things that do not work: 1) a custom layout with the right preferred size computations vs. GridBagLayout; 2) overriding getPreferredSize(); 3) setSize and setBounds before or after setVisible; 4) a custom root pane UI with a custom title pane; 5) a forced constant width set on componentResized; 6) removing the slider (in case there is confusion between vertical and horizontal sliders width and height); 7) removing all controls and the dialog title.
In general, the dialogs can be resized by the user to have smaller width (by dragging the corners), but not programmatically (they can be resized programmatically with setBounds to have smaller height).
The dialogs do have the right sizes under some commercial look and feels, but not under Metal or Nimbus. Under both Metal or Nimbus, the preferred and minimum sizes of the dialog, root panes, glass panes, layered panes make sense. The size of the dialog itself doesn't.
I have tested this without setting a look and feel (which, on Windows, presumably means Metal) and it does not work.
I know that the width of 258 is set in addNotify in Dialog, on getComponentFactory().createDialog(this).
I assumed this could be related to the title portion of the dialog, but the icons there are not of some significant size.
Any ideas are appreciated.
My next move will be to create a simple standalone JDialog or a JFrame that calls a JDialog, outside of the main application with which I am working now. However, I cannot see anything special happening in the larger application.
Here is the code that will produce a dialog with the same width (looks like):
public class Main
{
public static void main(String[] args)
{
JDialog dlg = new JDialog();
dlg.pack();
dlg.setVisible(true);
}
}