i am using the following code :
JDialog d=new JDialog();
JInternalFrame i=new JInternalFrame("HI",false,false,false,false);
i.setPreferredSize(new Dimension(100,100));
d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
d.setTitle("Wait dialog");
d.add(i);
d.pack();
d.setPreferredSize(new Dimension(100,100));
d.setLocation(300,300);
d.setAlwaysOnTop(true);
d.setVisible(true);
but instead of getting a jdialog of size 100*100, i am getting a small window with the default width and height , why is this happening?
note: I did the same with a JFrame , and i got the result.But i want it on a JDialog.
Thanks in advance
You need to call pack() on the JDialog after adding all components to it but before displaying it with setVisible(true).
On an unrelated note, it would be a good idea to associate your JDialog with its parent window (possibly a JFrame) via one of the JDialog constructor overloads.
Edit: you don’t want to add JInternalFrames directly to a JDialog or other top-level window. Instead create a JDesktopPane, set its preferredSize, add THAT to the JDialog’s contentPane and then add the JInternalFrame to the JDesktopPane.
Edit 2: You’ll also need to set the size and position of the internal frame (setBounds will work well for this) and call setVisible(true) on the internal frame. The Swing tutorial on using internal frames and desktop panes will tell you all about this.
Edit 3: e.g.,