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 3 of 3

Thread: GridBagLayout problems with align

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default GridBagLayout problems with align

    Hi, guys. Im quite new in Java and specially in GUI. Im using GridBagLayout and I have one problem all my components aligning to center but I need to left and top. How I can do that? How I can set minimum and maximum size of my application(for ex. I have app. with size 500*300 but I want set min. size 400*200 and max. size 600*400)?
    Can you give me an advice where I can search and how I can change view of my components (font, size, color, shape)?

    public class gui extends JFrame {
            gui(){
                super("Grid Bag L.");
                JFrame frame = new JFrame("test_");
                GridBagLayout g = new GridBagLayout();
                frame.setLayout(g);
                GridBagConstraints c = new GridBagConstraints();
                            frame.setSize(500, 200);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
     
                String[] w= {"", "", ""};
                JComboBox box= new JComboBox(w);
                g.setConstraints(box,c);
                frame.add(box,new GridBagConstraints(0,0,5,1,0.0,0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.CENTER, new Insets(5,5,5,5),0,0));
     
                             ..................


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,301
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: GridBagLayout problems with align

    Quote Originally Posted by lugaru View Post
    Can you give me an advice where I can search and how I can change view of my components (font, size, color, shape)?
    Please see the following, and note that layouts can be nested (one JPanel with one layout within another with a different layout)

    http://docs.oracle.com/javase/tutori...ut/visual.html

  3. The Following User Says Thank You to copeg For This Useful Post:

    lugaru (December 12th, 2011)

  4. #3
    Member
    Join Date
    Nov 2011
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: GridBagLayout problems with align

    Quote Originally Posted by lugaru View Post
    Hi, guys. Im quite new in Java and specially in GUI. Im using GridBagLayout and I have one problem all my components aligning to center but I need to left and top. How I can do that?
    Use GridBagConstraints.anchor property.

    Quote Originally Posted by lugaru View Post
    How I can set minimum and maximum size of my application(for ex. I have app. with size 500*300 but I want set min. size 400*200 and max. size 600*400)?
    component.setMinimumSize(), component.setMaximumSize()

    Quote Originally Posted by lugaru View Post
    Can you give me an advice where I can search and how I can change view of my components (font, size, color, shape)?
    component.setFont(), component.setBackground(), component.setForeground()

    Spring 3
    Last edited by cafeteria84; January 22nd, 2012 at 03:04 PM.

Similar Threads

  1. How do you align?
    By JavaStudent1988 in forum Java Theory & Questions
    Replies: 5
    Last Post: October 18th, 2011, 05:33 PM
  2. 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
  3. Building a small app... (GridBagLayout problems)
    By lowfatbeans in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 14th, 2011, 06:49 PM
  4. How to align the items in a form (grid layout)?
    By onlybarca in forum AWT / Java Swing
    Replies: 4
    Last Post: November 27th, 2010, 10:38 PM
  5. System.out.print -align
    By juwan in forum Object Oriented Programming
    Replies: 3
    Last Post: November 17th, 2010, 03:36 PM