Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: GridBagLayout

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default GridBagLayout

    Hi I'm having a problem in GridBagLayout.. I want my code to be same in the image below..

    asdf.png

    But my code output looks like this..

    aa.png

    And How can I set the color of box in checkbox to orange.
    Please help.. Thanks

    Here's my Code..

    import java.awt.*;
    import java.applet.*;
     
    public class test extends Applet
    {
        Panel pane = new Panel();
        Checkbox check;
        GridBagConstraints c = new GridBagConstraints();
       public void init()
       {
    	pane.setLayout(new GridBagLayout());
            c.fill = GridBagConstraints.HORIZONTAL;
    	c.ipadx = 15;
     
     
    	check = new Checkbox("Value Meals");
    	c.gridx = 0;
    	c.gridy = 0;
    	pane.add(check, c);
     
    	check = new Checkbox("Meal 1");
    	c.gridx = 1;
    	c.gridy = 1;
    	pane.add(check, c); 
     
    	check = new Checkbox("Meal 2");
    	c.gridx = 1;
    	c.gridy = 2;
    	pane.add(check, c);
     
    	check = new Checkbox("Meal 3");
    	c.gridx = 2;
    	c.gridy = 1;
    	pane.add(check, c);
     
    	check = new Checkbox("Meal 4");
    	c.gridx = 2;   
    	c.gridy = 2;      
    	pane.add(check, c);
     
    	check = new Checkbox("Meal 5");
    	c.gridx = 3;   
    	c.gridy = 1;      
    	pane.add(check, c);
     
    	check = new Checkbox("Meal 6");
    	c.gridx = 3;   
    	c.gridy = 2;      
    	pane.add(check, c);
     
    	add(pane);
    	setSize(400, 200);
        }
    }


  2. #2
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: GridBagLayout

    Hello.
    Apart from gridx and gridy you may need to set few more properties. Check "Java How to Program" by Deitel & Deitel. Its a wonderful book for GUI programming in Java.
    For setting the boundary of checkbox, you may use setBorder() method of JCheckBox class.

    Hint: You may need to use BorderFactory class' static method to create desired border.

    Syed.

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GridBagLayout

    Can you tell me the particular keyword?
    Does setBorder() is available in Checkbox class??

  4. #4
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: GridBagLayout

    Hello.
    I am not sure about AWT.
    But yes, its certainly available in Swings. So I suggest you use swings because AWT is outdated.

    Syed.

  5. #5
    Junior Member
    Join Date
    Jul 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GridBagLayout

    We are required to use Awt and not Swing..
    Can you tell me the particular keyword to arrange my checkbox?
    Thanks

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: GridBagLayout

    Quote Originally Posted by //java View Post
    Can you tell me the particular keyword?
    Does setBorder() is available in Checkbox class??
    Both of those questions can be answered by checking the documentation.
    (The point of the assignment is to get you to practice reading documentation for code you did not write, but still must use "in practice")

  7. #7
    Junior Member
    Join Date
    Jul 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GridBagLayout

    Thanks @jsp and @syedbhai..

Similar Threads

  1. GridBagLayout help
    By darren465 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 17th, 2013, 11:02 AM
  2. Help with GridBagLayout
    By mikejr76 in forum AWT / Java Swing
    Replies: 1
    Last Post: February 20th, 2012, 07:52 AM
  3. GridBagLayout can't seem to get it right.
    By ToyYoda in forum AWT / Java Swing
    Replies: 1
    Last Post: August 24th, 2011, 02:19 AM
  4. GridBagLayout help
    By mjpam in forum AWT / Java Swing
    Replies: 1
    Last Post: May 8th, 2011, 10:51 AM
  5. GridBagLayout help
    By mjpam in forum Java Theory & Questions
    Replies: 2
    Last Post: August 19th, 2010, 06:35 PM