I have a GridBagLayout, but one label (maxSizeLbl) goes crazy and an other one (maxDateLbl) isnt visible, anyone knows what I've done wrong?
Here is the Picture:
And here is the Code:
import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class SearchGUI {
public static void main(String args[]) {
JFrame frame = new JFrame("Search Files");
JPanel panel = new JPanel();
JTextField rootTF = new JTextField(20);
JTextField containsTF = new JTextField(20);
JTextField containsNotTF = new JTextField(20);
JTextField minSizeTF = new JTextField(10);
JTextField maxSizeTF = new JTextField(10);
JTextField suffixTF = new JTextField(10);
JTextField prefixTF= new JTextField(10);
JTextField minDateTF = new JTextField(10);
JTextField maxDateTF = new JTextField(10);
JCheckBox hiddenCB = new JCheckBox("search hidden");
JCheckBox recursiveCB = new JCheckBox("search subfolders");
JButton searchBtn = new JButton("search");
JLabel rootLbl = new JLabel("search in: ", JLabel.CENTER);
JLabel containsLbl = new JLabel("Filename contains: ", JLabel.CENTER);
JLabel containsNotLbl = new JLabel(" Filename contains not", JLabel.CENTER);
JLabel minSizeLbl = new JLabel("min. Size", JLabel.CENTER);
JLabel maxSizeLbl = new JLabel("max. Size", JLabel.CENTER);
JLabel suffixLbl = new JLabel("Filetypes", JLabel.CENTER);
JLabel prefixLbl = new JLabel("begins with", JLabel.CENTER);
JLabel minDateLbl = new JLabel("min. Date", JLabel.CENTER);
JLabel maxDateLbl = new JLabel("max Date", JLabel.CENTER);
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
Container c = frame.getContentPane();
GridBagLayout gbl = new GridBagLayout();
c.setLayout(gbl);
// addComponent(c, gbl, );
// x y w h wx wy
addComponent(c, gbl, rootLbl, 0, 0, 2, 1, 1.0, 0.0);
addComponent(c, gbl, rootTF, 0, 1, 2, 1, 1.0, 0.0);
addComponent(c, gbl, containsLbl, 0, 2, 2, 1, 1.0, 0.0);
addComponent(c, gbl, containsTF, 0, 3, 2, 1, 1.0, 0.0);
addComponent(c, gbl, containsNotLbl, 0, 4, 2, 1, 1.0, 0.0);
addComponent(c, gbl, containsNotTF, 0, 5, 2, 1, 1.0, 0.0);
addComponent(c, gbl, minSizeLbl, 0, 6, 1, 1, 1.0, 0.0);
addComponent(c, gbl, maxSizeLbl, 1, 6, 1, 1, 1.0, 0.0);
addComponent(c, gbl, minSizeTF, 0, 7, 1, 1, 1.0, 0.0);
addComponent(c, gbl, maxSizeTF, 1, 7, 1, 1, 1.0, 0.0);
addComponent(c, gbl, suffixLbl, 0, 8, 2, 1, 1.0, 0.0);
addComponent(c, gbl, suffixTF, 0, 9, 2, 1, 1.0, 0.0);
addComponent(c, gbl, minDateLbl, 0, 10, 1, 1, 1.0, 0.0);
addComponent(c, gbl, maxSizeLbl, 1, 10, 1, 1, 1.0, 0.0);
addComponent(c, gbl, minDateTF, 0, 11, 1, 1, 1.0, 0.0);
addComponent(c, gbl, maxDateTF, 1, 11, 1, 1, 1.0, 0.0);
addComponent(c, gbl, searchBtn, 0, 12, 2, 1, 1.0, 0.0);
frame.setSize(gbl.preferredLayoutSize(c));
frame.setVisible(true);
}
static void addComponent( Container cont,
GridBagLayout gbl,
Component c,
int x, int y,
int width, int height,
double weightx, double weighty )
{
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = x; gbc.gridy = y;
gbc.gridwidth = width; gbc.gridheight = height;
gbc.weightx = weightx; gbc.weighty = weighty;
gbl.setConstraints( c, gbc );
cont.add( c );
}
}
Thanks in advance.