Results 1 to 2 of 2
  1. #1
    gawkes1 is offline Member
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default Creating and positioning components in loop

    Hi I've got following code
    Java Code:
        JFrame PassengerData = new JFrame("Dane pasażerów");
     
        PassengerData.setSize(new Dimension(350,400));
        PassengerData.setLocationRelativeTo(null);
        JTextField[] PassengerName=new JTextField[5];
        for(int i=0;i<5;i++)
        {
     
            PassengerName[i]=new JTextField(""+i);
            PassengerName[i].setSize(120,20);
            PassengerName[i].setLocation(10, 10+(i*30));
            PassengerData.add(PassengerName[i]);
        } 
            PassengerData.setVisible(true);
    Every textfield except last one is placed where I wanted to, the last one stetches to the size of JFrame and I've got no idea how to fix it
    Last edited by gawkes1; 05-31-2011 at 11:57 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,571
    Rep Power
    25

    Default

    What layout manager are you using? Are you giving the correct constraint in the add()?

Similar Threads

  1. Need Help Creating A Loop!
    By chrisnojen117 in forum New To Java
    Replies: 3
    Last Post: 05-12-2011, 07:30 PM
  2. Creating a loop help !
    By theman279 in forum New To Java
    Replies: 5
    Last Post: 03-10-2011, 10:13 AM
  3. Creating a Loop
    By SenorJalapeno in forum New To Java
    Replies: 3
    Last Post: 04-02-2010, 10:13 AM
  4. tutorials 4 creating windows components
    By jaytee in forum New To Java
    Replies: 1
    Last Post: 03-07-2010, 08:48 PM
  5. creating New Components in swings
    By sandeepsai17 in forum New To Java
    Replies: 11
    Last Post: 07-13-2009, 06:49 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
  •