I have a grid layout, consisting of 4 columns. Just one row. Inside each grid layout box i have a box layout so i can stack things on top of each other.
The problem is, i have 5 things in column one, 4 in column 2, 3 and 4 are irellevant for now. The issue is i want the items in columns 1 and 2 to match, but because the 2nd has 4 items in it, its stretching those to fit the size of column 1 which has 5 things inside it
Ok its complicated to explain, here is the code i am working on
import javax.swing.*;
import java.awt.*;
public class myGui extends JFrame
{
/**
* Constructor for my GUI class
*/
public myGui()
{
}
/**
* @param args
*/
public static void main(String[] args)
{
createFrame();
}
/**
* Build the gui
*/
public static void createFrame ()
{
JFrame frame = new JFrame("This is my gui");
JPanel content = new JPanel(new GridLayout(1, 4));
frame.getContentPane().add(content);
content.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), "Requestor"));
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
//Create a box grid layout inside a panel and apply this to the grid view colums
JPanel col1 = new JPanel();
BoxLayout boxLayout1 = new BoxLayout(col1, BoxLayout.Y_AXIS);
col1.setLayout(boxLayout1);
JPanel col2 = new JPanel();
BoxLayout boxLayout2 = new BoxLayout(col2, BoxLayout.Y_AXIS);
col2.setLayout(boxLayout2);
JPanel col3 = new JPanel();
BoxLayout boxLayout3 = new BoxLayout(col3, BoxLayout.Y_AXIS);
col3.setLayout(boxLayout3);
JPanel col4 = new JPanel();
BoxLayout boxLayout4 = new BoxLayout(col4, BoxLayout.Y_AXIS);
col4.setLayout(boxLayout4);
//Add the boxLayouts to the appropriate columns
content.add(col1);
content.add(col2);
content.add(col3);
content.add(col4);
//create JLabels
JLabel requestorId = new JLabel("RequestorID");
JLabel org = new JLabel("Organisation");
JLabel orgAddress = new JLabel("Organisation Address");
JLabel otherAdd = new JLabel("Other Address");
JLabel title = new JLabel("Title");
JLabel phoneNo = new JLabel("Phone Number");
JLabel firstName = new JLabel("First Name");
JLabel surname = new JLabel("Surname");
JLabel emailAdd = new JLabel("E Mail Address");
JLabel dept = new JLabel("Department");
JLabel fax = new JLabel("Fax Number");
//create text areas
JTextArea reqIDTxt = new JTextArea();
reqIDTxt.setEditable(false);
JTextArea orgTxt = new JTextArea();
JTextArea orgAddTxt = new JTextArea();
JTextArea otherAddTxt = new JTextArea();
JTextArea titleTxt = new JTextArea();
JTextArea phoneNoTxt = new JTextArea();
JTextArea firstNameTxt = new JTextArea();
JTextArea faxNoTxt = new JTextArea();
JTextArea surnameTxt = new JTextArea();
JTextArea emailTxt = new JTextArea();
JTextArea deptTxt = new JTextArea();
//Add text areas and labels to their respective grid locations
col1.add(requestorId);
col1.add(reqIDTxt);
col1.add(title);
col1.add(titleTxt);
col1.add(firstName);
col1.add(firstNameTxt);
col1.add(surname);
col1.add(surnameTxt);
col1.add(dept);
col1.add(deptTxt);
col2.add(org);
col2.add(orgTxt);
col2.add(phoneNo);
col2.add(phoneNoTxt);
col2.add(fax);
col2.add(faxNoTxt);
col2.add(emailAdd);
col2.add(emailTxt);
col3.add(orgAddress);
col3.add(orgAddTxt);
col4.add(otherAdd);
col4.add(otherAddTxt);
frame.pack();
frame.show();
}
}
any ideas how to make the colums line up :/
Thanks