fatcodeguy
Programmer
I'm trying to create an Error dialog with three components, a small JLabel for an Icon, a textfield for the error message and an OK button. I want the icon on the far left of the first row, and the message to take the rest of the space for the error message. On the bottom row, I want the OK button alone, in the exact center of the row. The problem is that the message is sometimes larger or shorter, so the OK button is never EXACTLY centered. This is what I have been using:
c.weightx=0.5;
c.weighty=0.5;
c.insets = new Insets(10,10,10,10);
c.anchor=GridBagConstraints.CENTER;
c.gridx=0;
c.gridy=0;
gb.setConstraints(icon,c);
icon.setIcon(new ImageIcon("icons/error.gif"
);
contentPane.add(icon);
c.gridx=1;
c.gridwidth=3;
error.setText(errorMessage);
gb.setConstraints(error,c);
contentPane.add(error);
c.gridx=4;
c.gridwidth=1;
gb.setConstraints(fake,c);
contentPane.add(fake);
c.gridy=2;
c.gridx=2;
c.gridwidth=1;
gb.setConstraints(btnOK,c);
contentPane.add(btnOK);
Appreciate any help. thanks
c.weightx=0.5;
c.weighty=0.5;
c.insets = new Insets(10,10,10,10);
c.anchor=GridBagConstraints.CENTER;
c.gridx=0;
c.gridy=0;
gb.setConstraints(icon,c);
icon.setIcon(new ImageIcon("icons/error.gif"
contentPane.add(icon);
c.gridx=1;
c.gridwidth=3;
error.setText(errorMessage);
gb.setConstraints(error,c);
contentPane.add(error);
c.gridx=4;
c.gridwidth=1;
gb.setConstraints(fake,c);
contentPane.add(fake);
c.gridy=2;
c.gridx=2;
c.gridwidth=1;
gb.setConstraints(btnOK,c);
contentPane.add(btnOK);
Appreciate any help. thanks