Results 1 to 3 of 3
- 04-27-2012, 04:12 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 7
- Rep Power
- 0
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?!?!

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*********************//
}
}
- 04-27-2012, 04:39 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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.
There is also a method name setPreferredSize(Dimension d) that you can use to set the size of your JTextField.Java Code:... JTextField textField = new JTextField(20); ...
Last edited by wsaryada; 04-27-2012 at 04:45 AM.
Website: Learn Java by Examples
- 04-27-2012, 07:05 AM #3
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?
dbLast edited by DarrylBurke; 04-27-2012 at 07:15 AM.
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
How do I make a grid of buttons work within a border layout??
By jazzgnat in forum New To JavaReplies: 3Last Post: 03-23-2012, 07:43 PM -
array multiplication with single double
By Tien in forum New To JavaReplies: 1Last Post: 10-25-2011, 12:21 PM -
Genrate Single LL from Double LL
By SHE in forum New To JavaReplies: 4Last Post: 03-26-2011, 08:18 AM -
How to validate JTextFields components in JTreetable in single button click.
By selvin_raj in forum AWT / SwingReplies: 1Last Post: 07-03-2008, 01:05 PM -
Border Layout
By mark-mlt in forum Java AppletsReplies: 5Last Post: 05-12-2008, 09:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks