Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Simple MigLayout Question

  1. #1
    Aerandir is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Simple MigLayout Question

    I am just starting out with MigLayout and im having some trouble with getting the frame to autosize. I don't really want to define a size by doing something like frame.setSize(500,500) but when I remove this, the frame size is basically nothing and I can't see my application unless I resize the window with my mouse. Here is my basic example code below and a screen capture of what I see when running this.

    Simple MigLayout Question-screen-shot-2012-12-22-19.24.23.png

    Java Code:
    import javax.swing.*;
    import net.miginfocom.swing.MigLayout;
    
    public class GUI2 {
    
    	public static void main(String[] args) {
    
    		new GUI2().buildGUI();
    
    	}
    
    	public void buildGUI() {
    
    		JFrame frame = new JFrame();
    		JPanel panel = new JPanel(new MigLayout());
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.getContentPane().add(panel);
    		// frame.setSize(500,500);
    		frame.setVisible(true);
    
    		JLabel firstNameLabel = new JLabel("First Name");
    		JLabel lastNameLabel = new JLabel("Last Name");
    		JLabel addressLabel = new JLabel("Address");
    
    		JTextField firstNameTextField = new JTextField(100);
    		JTextField lastNameTextField = new JTextField(100);
    		JTextField addressTextField = new JTextField();
    
    		panel.add(firstNameLabel);
    		panel.add(firstNameTextField);
    		panel.add(lastNameLabel);
    		panel.add(lastNameTextField, "wrap");
    		panel.add(addressLabel);
    		panel.add(addressTextField, "span, grow");
    
    	}
    
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Simple MigLayout Question

    Moved from New to Java

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

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Simple MigLayout Question

    1. Add all content
    2. Call pack()
    3. Set the frame visible

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

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Simple MigLayout Question

    Cross posted
    Java using MigLayout Size - Stack Overflow

    Any more?

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

  5. #5
    Aerandir is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: Simple MigLayout Question

    This works perfect, thank you!

    Quote Originally Posted by DarrylBurke View Post
    1. Add all content
    2. Call pack()
    3. Set the frame visible

    db

  6. #6
    Aerandir is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: Simple MigLayout Question

    Nop, only this one which is now deleted

    Quote Originally Posted by DarrylBurke View Post

Similar Threads

  1. simple question
    By jwl in forum New To Java
    Replies: 4
    Last Post: 08-05-2012, 02:31 AM
  2. Replies: 0
    Last Post: 02-19-2012, 06:53 PM
  3. Simple question...
    By Onyx in forum New To Java
    Replies: 10
    Last Post: 08-10-2011, 10:44 PM
  4. Please help. Simple question
    By owencain in forum New To Java
    Replies: 14
    Last Post: 06-16-2011, 01:07 AM
  5. Simple Question
    By barusk in forum Networking
    Replies: 13
    Last Post: 03-04-2009, 07:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •