Results 1 to 3 of 3
  1. #1
    cknapick is offline Member
    Join Date
    Apr 2012
    Rep Power

    Default 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 ***//
    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***//

    this.add(south, BorderLayout.SOUTH);

    jtf1 = new JTextField();
    jtf2 = new JTextField();

    JPanel north = new JPanel();


    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***//



    public static void main(String [] args) throws ClassNotFoundException
    JFrame frame=new CDFrame("My Database GUI");
    frame.setSize(800, 550);

    //************************End of CDFrame class*********************//

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Bali, Indonesia
    Rep Power

    Default 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.

    Java 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.
    Last edited by wsaryada; 04-27-2012 at 05:45 AM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default 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?

    Last edited by DarrylBurke; 04-27-2012 at 08:15 AM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 3
    Last Post: 03-23-2012, 08:43 PM
  2. array multiplication with single double
    By Tien in forum New To Java
    Replies: 1
    Last Post: 10-25-2011, 01:21 PM
  3. Genrate Single LL from Double LL
    By SHE in forum New To Java
    Replies: 4
    Last Post: 03-26-2011, 09:18 AM
  4. Replies: 1
    Last Post: 07-03-2008, 02:05 PM
  5. Border Layout
    By mark-mlt in forum Java Applets
    Replies: 5
    Last Post: 05-12-2008, 10:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts