aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JDialog and JTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDialog and JTextField" Watch "JDialog and JTextField" New topic
Author

JDialog and JTextField

shansi raj
Greenhorn

Joined: Jul 05, 2006
Posts: 25
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?

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?

Thanks in advance
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

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?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
shansi raj
Greenhorn

Joined: Jul 05, 2006
Posts: 25
Thanks!I used JOptionPane and it worked.Am using GridbagLayout.

for (int i = 0; i < 10; i++) {

jTextField[i].setText("");
jTextField[i].setHorizontalAlignment(javax.swing.JTextField.LEFT);
jTextField[i].setMinimumSize(new java.awt.Dimension(250, 20));
jTextField[i].setPreferredSize(new java.awt.Dimension(250, 20));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = gridx + 2;
gridBagConstraints.gridy = gridy;
gridBagConstraints.insets = new java.awt.Insets(0, 0, bottom, right);
jPanel1.add(jTextField[i], gridBagConstraints);

}
 
 
subject: JDialog and JTextField
 
Similar Threads
coding a texteditor: want to open a separate option window
Two different font sizes for the text in titlebar
Getting Jdialog reference from AppletContext
If swing is betters graphics handler than awt, why do we need to use awt at all?
How can I get the feature ALWAYS_ON_TOP with the swing JFrames.