Border Layout issue with GUI - Single or double JTextFields are tiny and won't spread
Can anyone help with this? I am stumped... and have re-arranged it a few ways... I need to have the two JTextFields side by side in the north panel, like the buttons do in the south... HELP?!?!:s:
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
public class CDFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JTextArea jta;
private JTextField jtf1, jtf2;
private JButton first, prev, next, last;
public CDFrame(String title) //*** CDFrame constructor that adds the JPanel ***//
{
super(title);
this.setDefaultCloseOperation(WindowConstants.EXIT _ON_CLOSE);
first=new JButton("First"); //***Assigns each button to a variable with a String identifier***//
prev=new JButton("Previous");
next=new JButton("Next");
last=new JButton("Last");
JPanel south = new JPanel();
south.add(first); //***Adds each button to the south panel of the frame***//
south.add(prev);
south.add(next);
south.add(last);
this.add(south, BorderLayout.SOUTH);
jtf1 = new JTextField();
jtf2 = new JTextField();
JPanel north = new JPanel();
north.add(jtf1);
north.add(jtf2);
this.add(north, BorderLayout.NORTH);
jta = new JTextArea();
this.add(jta, BorderLayout.CENTER);
CDListener cd= new CDListener(jtf1, jtf2, jta); //***Instantiates CDListener and registers with each button***//
first.addActionListener(cd);
prev.addActionListener(cd);
next.addActionListener(cd);
last.addActionListener(cd);
}
public static void main(String [] args) throws ClassNotFoundException
{
JFrame frame=new CDFrame("My Database GUI");
frame.setSize(800, 550);
frame.setVisible(true);
//************************End of CDFrame class*********************//
}
}
Re: Border Layout issue with GUI - Single or double JTextFields are tiny and won't sp
When creating a JTextField you can pass the number of column of those text field, instead of just creating a JTextField with a default constructor. The column value is used to calculate the preferred size of the text field.
Code:
...
JTextField textField = new JTextField(20);
...
There is also a method name setPreferredSize(Dimension d) that you can use to set the size of your JTextField.
Re: Border Layout issue with GUI - Single or double JTextFields are tiny and won't sp
Moved from New to Java.
In your first thread, no less than 3 members advised you about the code tags, and I even provided a link to the relevant FAQ. So, are you lazy or stubborn?
db