Hi all. I'm trying to use a gridbaglayout to set the layout of a dialog box.
The dialog box contains a panel with buttons in the southe field of a
borderlayout and the center panel contains the gridbaglayout
the centre panel is meant to show three rows. two of whoch contain a label,
a textfield and a button containing "..." and the other row contains a label
and a textfield only. Sounds simple huh?
I'm getting a mess. A self contained example is below
Any advice would be greatly appreciated.
-
Darren
--
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
/**
* Summary description for JarFileFrame
*
*/
public class test extends JFrame
{
// Variables declaration
private JPanel contentPane;
private JPanel loOptionPanel = new JPanel();
private JPanel loButtonPanel = new JPanel();
JTextField ledtJarSignerPath= new JTextField();
JTextField ledtJarSignerFormat= new JTextField();
JTextField ledtJarVerifyFormat= new JTextField();
JButton loOKButton=new JButton("OK");
JButton loCancelButton=new JButton("Cancel");
JButton loJarExeFindButton=new JButton("..");
JButton loJarSignerExeFindButton=new JButton("..");
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
JLabel jarSignerFormatLabel =new JLabel("Jar Signer Format");
// End of variables declaration
test()
{
super("Options");
contentPane = (JPanel)this.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.setBorder(BorderFactory.createEtchedBorder());
contentPane.add(loOptionPanel,BorderLayout.CENTER);
loButtonPanel.setLayout(new GridLayout());
contentPane.add(loButtonPanel,BorderLayout.SOUTH);
loOptionPanel.setLayout(gridbag);
c.fill = GridBagConstraints.HORIZONTAL;
/*c.gridwidth=5;
c.gridheight=3;
*/
c.weightx = 1;
c.gridx = 0;
c.gridy = 0;
c.gridwidth=1;
gridbag.setConstraints(jarSignerFormatLabel, c);
loOptionPanel.add( jarSignerFormatLabel);
c.weightx = 2;
c.gridx = 1;
c.gridy = 0;
c.gridwidth=2;
c.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(ledtJarSignerPath, c);
loOptionPanel.add(ledtJarSignerPath);
c.weightx=1;
c.gridx = 4;
c.gridy = 0;
c.gridwidth=1;
gridbag.setConstraints(loJarSignerExeFindButton, c);
loOptionPanel.add(loJarSignerExeFindButton);
c.weightx =2;
c.gridx = 0;
c.gridy = 1;
gridbag.setConstraints(jarSignerFormatLabel, c);
loOptionPanel.add( jarSignerFormatLabel);
c.gridx = 1;
c.gridy = 1;
gridbag.setConstraints(ledtJarSignerFormat, c);
loOptionPanel.add(ledtJarSignerFormat);
c.gridx = 0;
c.gridy = 2;
gridbag.setConstraints(new JLabel("Jar Verify Path"), c);
loOptionPanel.add( new JLabel("Jar Verify Path"));
c.weightx = 0.5;
c.gridx = 1;
c.gridy = 2;
gridbag.setConstraints(ledtJarVerifyFormat, c);
loOptionPanel.add(ledtJarVerifyFormat);
loButtonPanel.setBorder(BorderFactory.createBevelBorder(1));
loButtonPanel.add(loOKButton);
loButtonPanel.add(new JLabel());
loButtonPanel.add(loCancelButton);
loCancelButton.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
}
);
loOKButton.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
}
);
this.setTitle("Options");
this.setLocation(new Point(50, 50));
this.setSize(new Dimension(390, 150));
this.setResizable(true);
}
//
//
public static void main(String[] args)
{
test mytest=new test();
mytest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mytest.setSize(700,500);
mytest.setLocation(50,50);
mytest.setVisible(true);
}
}
Knute Johnson - 26 Nov 2005 06:08 GMT
> Hi all. I'm trying to use a gridbaglayout to set the layout of a dialog box.
> The dialog box contains a panel with buttons in the southe field of a
[quoted text clipped - 9 lines]
> -
> Darren
Darren:
You've got a mess there all right. See test1 below.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test1 {
public static void createGUI() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = c.gridy = 0; c.insets = new Insets(3,3,3,3);
JLabel l = new JLabel("Label 1");
f.add(l,c);
++c.gridx;
JTextField tf = new JTextField(10);
f.add(tf,c);
++c.gridx;
JButton b = new JButton("...");
f.add(b,c);
c.gridx = 0; ++c.gridy;
l = new JLabel("Label 2");
f.add(l,c);
++c.gridx;
tf = new JTextField(10);
f.add(tf,c);
++c.gridx;
b = new JButton("...");
f.add(b,c);
c.gridx = 0; ++c.gridy;
l = new JLabel("Label 3");
f.add(l,c);
++c.gridx;
tf = new JTextField(10);
f.add(tf,c);
f.pack();
f.setVisible(true);
}
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
createGUI();
}
};
EventQueue.invokeLater(r);
}
}

Signature
Knute Johnson
email s/nospam/knute/
Roedy Green - 26 Nov 2005 16:41 GMT
>> Hi all. I'm trying to use a gridbaglayout to set the layout of a dialog box.
>> The dialog box contains a panel with buttons in the southe field of a
[quoted text clipped - 6 lines]
>>
>> Any advice would be greatly appreciated.
see http://mindprod.com/jgloss/gridbaglayout.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Darren - 26 Nov 2005 20:32 GMT
> > Hi all. I'm trying to use a gridbaglayout to set the layout of a dialog box.
> > The dialog box contains a panel with buttons in the southe field of a
[quoted text clipped - 13 lines]
>
> You've got a mess there all right. See test1 below.
typical of me to over complicate thangs. Thanks very much, you too Roedy
> import java.awt.*;
> import java.awt.event.*;
[quoted text clipped - 53 lines]
> }
> }
steve - 27 Nov 2005 08:51 GMT
check out this
http://madbean.com/blog/2004/17/totallygridbag.html
> Hi all. I'm trying to use a gridbaglayout to set the layout of a dialog box.
> The dialog box contains a panel with buttons in the southe field of a
[quoted text clipped - 170 lines]
>
> }
Darren - 28 Nov 2005 17:04 GMT
LOL, well said. :)
> check out this
>
[quoted text clipped - 174 lines]
> >
> > }