Originally posted by shansi raj: Hi, I want to set the size of the JDialog based on the number of components which I get only at runtime.Can anyone please tell me how to set the size of the JDialog dynamically?
Is it possible for you to use one of the JOptionPane.showXXXDialog() methods? In that case, you wont require to explicitly set the size as it internally calls a dialog.pack(). In case you are creating your own JDialog you can do the same. Call a dialog.pack() and it will correctly resize depending on the components.
Also I have a JTextfield and buttons in my dialog and when I resize the dialog only the window becomes bigger but not the components?How to achieve the same?
Looks like a layout issue to me. Are you using GridBagLayout by any chance? In principal, dialogs should not be resizable. Can you post your layout code so we can try and figure out why they are not getting resized?