Here is a ss of what I am talking about -
I want that particular JPanel to fill it's empty space.
I am using a layout manager to place 4 JPanels on a JFrame. However, I can't get the JPanel aligned WEST (with the JTextFields) to use up all of that empty space.
Here is what my constructor for that particular JPanel looks like:
public UserParamsPanel() { params = UserParams.instance(); pnlParams = new JPanel(new GridLayout(11, 2)); //Define parameter labels. lblPreyLoneliness = new JLabel("Prey Loneliness"); lblPreyEaten = new JLabel("Prey Eaten"); lblPredatorIsolation = new JLabel("Predator Isolation"); lblPredatorStarvation = new JLabel("Predator Starvation"); lblPredatorLoneliness = new JLabel("Predator Loneliness"); lblPreyReproduction = new JLabel("Prey Reproduction"); lblPredatorReproduction = new JLabel("Predator Reproduction"); lblPreySurvivalWhenPredators = new JLabel("Prey Survival when Predators"); lblPredatorSurvivalWhenPrey = new JLabel("Predator Survival when Prey"); lblPreyInitialProbability = new JLabel("Prey Initial Probability"); lblPredatorInitialProbability = new JLabel("Predator Initial Probability"); //Initialize text fields. txtPreyLoneliness = new JTextField(10); txtPreyEaten = new JTextField(10); txtPredatorIsolation = new JTextField(10); txtPredatorStarvation = new JTextField(10); txtPredatorLoneliness = new JTextField(10); txtPreyReproduction = new JTextField(10); txtPredatorReproduction = new JTextField(10); txtPreySurvivalWhenPredators = new JTextField(10); txtPredatorSurvivalWhenPrey = new JTextField(10); txtPreyInitialProbability = new JTextField(10); txtPredatorInitialProbability = new JTextField(10); //Add elements above to Panel. pnlParams.add(lblPreyLoneliness); pnlParams.add(txtPreyLoneliness); pnlParams.add(lblPreyEaten); pnlParams.add(txtPreyEaten); pnlParams.add(lblPredatorIsolation); pnlParams.add(txtPredatorIsolation); pnlParams.add(lblPredatorStarvation); pnlParams.add(txtPredatorStarvation); pnlParams.add(lblPredatorLoneliness); pnlParams.add(txtPredatorLoneliness); pnlParams.add(lblPreyReproduction); pnlParams.add(txtPreyReproduction); pnlParams.add(lblPredatorReproduction); pnlParams.add(txtPredatorReproduction); pnlParams.add(lblPreySurvivalWhenPredators); pnlParams.add(txtPreySurvivalWhenPredators); pnlParams.add(lblPredatorSurvivalWhenPrey); pnlParams.add(txtPredatorSurvivalWhenPrey); pnlParams.add(lblPreyInitialProbability); pnlParams.add(txtPreyInitialProbability); pnlParams.add(lblPredatorInitialProbability); pnlParams.add(txtPredatorInitialProbability); populateDefaultValues(); add(pnlParams); }
It's really simple. You can see that I just create the fields in a grid layout, add them to the panel and add the panel to the class itself (which extends JPanel).
Is there a simple way I can modify my code so it will take up all of that empty space at the bottom of the panel? Any help is appreciated.
Thanks!!