Results 1 to 5 of 5

Thread: layout question

  1. #1
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default layout question

    public class stringtester {

    public static void main(String[] args){

    JFrame frame = new JFrame();
    Container container = frame.getContentPane();
    container.setLayout(new GridLayout(10,10));
    for(int i =0; i<5; i++)
    for(int j=0; j<5; j++)
    if(i>=j){
    container.add(new JButton("X"));


    }
    else{ container.add(new JLabel());




    }
    frame.setSize(500,500);
    frame.setVisible(true);


    I'm confused in how the grid layout adds the buttons in terms of order, could someone explain to me how it does so?

    Thanks

  2. #2
    SteveVitali is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: layout question

    I think it goes from the top left corner and then down the columns. Perhaps look into GridBagLayout or BoxLayout.

  3. #3
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default Re: layout question

    i had a question that specifcally asks to draw the frame that was produced from the above code, but after testing it in java I have no idea why it is the way it is.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: layout question

    Quote Originally Posted by stuckonjava View Post
    I'm confused in how the grid layout adds the buttons in terms of order, could someone explain to me how it does so?
    A lot will depend on just what you mean by "in terms of order". Please tell us the details and don't assume that we know what the code should be doing or can read minds.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

Similar Threads

  1. Grid Layout change layout alignment of control s
    By rellicott in forum SWT / JFace
    Replies: 1
    Last Post: 02-13-2012, 06:11 PM
  2. Simple Layout Question
    By Guy in forum AWT / Swing
    Replies: 7
    Last Post: 07-13-2011, 02:57 PM
  3. Question about Layout
    By hei1233212000 in forum New To Java
    Replies: 6
    Last Post: 11-04-2010, 02:42 PM
  4. Question Card Layout, Card Management
    By lrichil in forum AWT / Swing
    Replies: 1
    Last Post: 04-22-2010, 11:11 AM
  5. Layout Question
    By vittoire in forum New To Java
    Replies: 6
    Last Post: 01-19-2010, 03:11 PM

Posting Permissions

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