Using Flowlayout in GUI - what am I missing here?
The following is some code from an open source applet that I am trying to modify to change the look of the GUI a bit. What this code does is place three buttons on a panel called "btnPan". "Btnpan" is then placed in another panel called jpanel1, along with two text fields (called txtInput and txtOutput) using gridlayout (see the seventh line below, including blank lines in the count, and also lines 23, 32, and 33). jpanel1 is then placed in a larger panel called jpanel3 in the SOUTH area, using borderlayout. A blank (for now) panel called jpanel2 is placed in the NORTH section, but the rest of jpanel3 is empty.
This version works fine. The three buttons, and the two text fields wind up evenly spaced along a row like they should. See the code below:
jPanel3.setLayout(new java.awt.BorderLayout());
jPanel3.add(jPanel2, java.awt.BorderLayout.NORTH);
txtOutput.setEditable(false);
txtOutput.setFont(new java.awt.Font("Dialog", 0, 10));
jPanel1.setLayout(new java.awt.GridLayout(0, 3));
//jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
btnPan.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
btnTalk.setLabel("Talk");
btnTalk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTalkActionPerformed(evt);
}
});
btnPan.add(btnTalk);
btnPan.add(volPlus);
btnPan.add(volMinus);
jPanel1.add(btnPan);
txtInput.setFont(new java.awt.Font("Dialog", 0, 10));
txtInput.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtInputActionPerformed(evt, playerNick);
}
});
jPanel1.add(txtInput);
jPanel1.add(txtOutput);
jPanel3.add(jPanel1, java.awt.BorderLayout.SOUTH);
this.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
this.add(jPanel3);
The problem occurred when I decided that I'd rather use flowlaout and have the buttons and text areas shoved against each other toward the left. I eliminated line 7 and replaced it with the commented out line shown as line 8 , above:
jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
When I use that line, the three buttons and the first text field (txtInput) disappear, but the last text field (txtOutput) remains off toward the right side of jpanel1.
I cannot find anything wrong with the flowlayout statement, but this is the first time that I have tried anything with GUI so I am probably just missing something obvious. Anyone know what could be going wrong?