• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDialog and JTextField

 
shansi raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
shansi raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic