Results 1 to 7 of 7
  1. #1
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    148
    Rep Power
    0

    Default GridLayout question

    public class layouttester {

    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 thought that when we have a gridlayout, it will fill up the rows and then onto the next row etc. Could someone please explain why this one does do so and what difference that for sloop makes.
    Thanks you

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: GridLayout question

    Please use code tags when posting code here.

    Regarding your question, please check out the GridLayout API as it's all spelled out there with the paragraph that begins: "When both the number of rows and the number of columns have been set to non-zero values, either by a constructor or by the setRows and setColumns methods, ..."

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

    Default Re: GridLayout question

    127 posts and you still don't know how to use code tags? Or is it that you just can't be bothered?

    layout question
    static question
    Quick Question!!!!!!!!
    Help with this keyboard GUI
    http://www.java-forums.org/forum-mod...tml#post267044

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    148
    Rep Power
    0

    Default Re: GridLayout question

    Sorry, I always forget to use the code tags. From here on in I will always use them. Is what I did above correct?

    Thanks

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: GridLayout question

    Why do you use a GridLayout(10, 10)?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: GridLayout question

    @JosAH: check the dates of the question. I think he's trying to make amends for not replying to previous threads, and good for him!

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: GridLayout question

    Quote Originally Posted by Fubarable View Post
    @JosAH: check the dates of the question. I think he's trying to make amends for not replying to previous threads, and good for him!
    Oh dear, I wasn't paying attention; but it's Sunday so I'm forgiven ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Making a GridLayout?
    By umzz in forum AWT / Swing
    Replies: 1
    Last Post: 03-19-2012, 10:32 PM
  2. help! Gridlayout
    By eiramae in forum Java Applets
    Replies: 3
    Last Post: 02-19-2011, 05:11 AM
  3. how to control the GridLayout
    By amro in forum New To Java
    Replies: 8
    Last Post: 10-31-2010, 04:45 PM
  4. SWT GridLayout
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-08-2008, 09:04 AM
  5. Gridlayout
    By Marty in forum AWT / Swing
    Replies: 2
    Last Post: 05-31-2007, 11: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
  •