D
Darren
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);
}
}
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);
}
}