Results 1 to 4 of 4

Thread: How to use GridLayout in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    253

    How to use GridLayout in Java?

    Hi friends,
    I have completed the Layout Manager and with that I have also completed some layouts that are present in Java like flow layout, border layout, etc. But now when I am trying for grid layout I am not able to do that. Actually I don't know much about this layout. So please tell me how to use GridLayout in Java? Expecting some help as soon as possible.!!

  2. #2
    Join Date
    Aug 2006
    Posts
    227

    Re: How to use GridLayout in Java?

    A GridLayout places components in a grid of cells. Each component takes all the available space within its cell, and each cell is exactly the same size. You can also say that the container is divided into equal-sized rectangles, and one component is placed in each rectangle. If the GridLayoutTrial window is resized, the GridLayout object changes the cell size so that the cells are as large as possible, given the space available to the container.
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

  3. #3
    Join Date
    Aug 2006
    Posts
    235

    Re: How to use GridLayout in Java?

    I have provided you with an example that is an applet that lays out six buttons into three rows and two columns :
    Code:
    import java.awt.*;
     import java.applet.Applet;
     public class ButtonGridDemo extends Applet {
         public void init() {
             setLayout(new GridLayout(3,2));
             add(new Button("1"));
             add(new Button("2"));
             add(new Button("3"));
             add(new Button("4"));
             add(new Button("5"));
             add(new Button("6"));
         }
     }
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  4. #4
    Join Date
    Nov 2008
    Posts
    996

    Re: How to use GridLayout in Java?

    The code snippet below creates the GridLayout object and the components it manages.
    Code:
    GridLayout DemoLayout = new GridLayout(0,2);
    
    ...
    
    	compsToExperiment.setLayout(DemoLayout);
    
    	compsToExperiment.add(new JButton("Button 1"));
    	compsToExperiment.add(new JButton("Button 2"));
    	compsToExperiment.add(new JButton("Button 3"));
    	compsToExperiment.add(new JButton("Long-Named Button 4"));
    	compsToExperiment.add(new JButton("5"));

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2013, 11:04 PM
  2. Setting Of Java to The Point At Manual Java
    By winni in forum Software Development
    Replies: 4
    Last Post: 10-01-2011, 10:05 PM
  3. Java Programming using Adventnet SNMP Java API
    By ROCKING_Suhas in forum Software Development
    Replies: 5
    Last Post: 17-07-2010, 06:52 AM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,613,726.94802 seconds with 17 queries