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

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

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

    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 04:45 AM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    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?

    db
    Last edited by DarrylBurke; 04-27-2012 at 07: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, 07:43 PM
  2. array multiplication with single double
    By Tien in forum New To Java
    Replies: 1
    Last Post: 10-25-2011, 12:21 PM
  3. Genrate Single LL from Double LL
    By SHE in forum New To Java
    Replies: 4
    Last Post: 03-26-2011, 08:18 AM
  4. Replies: 1
    Last Post: 07-03-2008, 01:05 PM
  5. Border Layout
    By mark-mlt in forum Java Applets
    Replies: 5
    Last Post: 05-12-2008, 09: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
  •