Results 1 to 6 of 6

Thread: GridBagLayout class of java

  1. #1
    Join Date
    Jan 2010
    Posts
    79

    GridBagLayout class of java

    Hi friend,

    I am totally confused about the inbuilt classes of java. According to me it is one of the important part of the java programming. I am getting trouble while studying the 'GridBagLayout class' of java programming. I am unable to get the use of GridBagLayout class. Do you have enough knowledge about the GridBagLayout class? If yes then please try to share it me. Your any help over GridBagLayout class will be appreciable.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: GridBagLayout class of java

    Each component managed by a GridBagLayout is associated with an instance of GridBagConstraints. The constraints object specifies where a component's display area should be located on the grid and how the component should be positioned within its display area. In addition to its constraints object, the GridBagLayout also considers each component's minimum and preferred sizes in order to determine a component's size.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: GridBagLayout class of java

    Hi,

    Please go through the following example of GridBagLayout class:
    Code:
    import java.awt.GridBagLayout;
    import javax.swing.JPanel;
    
    p01ublic class GridBagWithDm {
    
      p01ublic static void main(String[] ajrgs) {
        JFrame f1 = new JFrame( "Demonstrates the use of weightx, weighty constraints");
        JPanel p01 = new JPanel();
    
        p01.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        p01.setLayout(new GridBagLayout());
        c1 = new GridBagConstraints();
        c1.insets = new Insets(2, 2, 2, 2);
        c1.weighty = 1.0;
        c1.weightx = 1.0;
        c1.gridx = 0;
        c1.gridy = 0;
        p01.add(new JButton("Java"), c);
        c1.gridx = 1;
        p01.add(new JButton("Source"), c);
        WindowListener wndCloser1 = new WindowAdap01ter() {
          p01ublic void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        };
        f1.addWindowListener(wndCloser1);
    
        f1.getContentPane().add(p01);
        f1.setSize(500, 200);
        f1.show();
      }
    }

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: GridBagLayout class of java

    Please review below methods of GridBagLayout class:
    1. preferredLayoutSize(Container parent1)
    2. setConstraints(Component compn, GridBagConstraints GBconstraints)
    3. removeLayoutComponent(Component compn)
    4. minimumLayoutSize(Container parent1)
    5. layoutContainer(Container parent1)

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: GridBagLayout class of java

    If you want use methods of GridBagLayout class, then please study following example of java code:
    Code:
    import java.awt.GridBagConstraints;
    import javax.swing.JFrame;
    
    public class GridMain 
    {
      public static void main(String[] arglv) throws Exception {
        JFrame frameR = new JFrame();
        Container container = frame.getContentPane();
    
        GridBagLayout gblR = new GridBagLayout();
    
        container.setLayout(gbl);
       
        GridBagConstraints gbcR = new GridBagConstraints();
        gbcR.gridx = 1;
        gbcR.gridy = 1;
        
        JButton component = new JButton("a");
     
        gblR.setConstraints(component, gbcR);
    
        container.add(component);
    
        frameR.pack();
        frameR.setVisible(true);
      }
    }

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: GridBagLayout class of java

    Hello friend,

    Below I have mentioned the important fields of the GridBagLayout class:
    1. defaultConstraints
    2. MAXGRIDSIZE
    3. PREFERREDSIZE
    4. getLayoutDimensions
    5. getLayoutOrigin

Similar Threads

  1. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  2. KeyboardFocusManager class of java
    By Gokul20 in forum Software Development
    Replies: 4
    Last Post: 05-03-2010, 03:38 PM
  3. JDesktopPane class of java
    By Sonam Goenka in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 08:14 AM
  4. Use of JWindow class in java
    By Ram Bharose in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 11:11 AM
  5. Java Programming Language Basics: Reflection Basics and Class Class
    By mayuri_gunjan in forum Guides & Tutorials
    Replies: 6
    Last Post: 29-08-2005, 12:04 AM

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,266,241.52474 seconds with 17 queries