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

Thread: Help with how to set up my layout

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Help with how to set up my layout

    This is what i need to do except the layout alone is being a pain and cant get it to do what i want even though i know how to make a flow and grid layout.

    I'm using grid at the moment

    layout.jpg

    So my questions are

    How do you tell it when the jlabels and textfields are supposed to stay on 1 line and when to go to a new line.

    Also on the grid when I create a new column I don't see a difference at all and can't get it to move a thing to it.

    If the flow layout works better please still tell me the above just for flow instead of grid or even do both if you want.


    This is the basic layout code from my book and it works but I cant edit it to what I want.

    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JFrame;
    import java.awt.GridLayout;
     
    public class MortgageCalculator extends JFrame
    {
    	public MortgageCalculator()
    	{
    		setLayout(new GridLayout(3,2,5,5));
     
    		add(new JLabel("First Name:"));
    		add(new JTextField(8));
    		add(new JLabel("MI"));
    		add(new JTextField(1));
    		add(new JLabel("Last Name"));
    		add(new JTextField(8));
    	}
    	public static void main (String [] args)
    	{
    		MortgageCalculator frame = new MortgageCalculator();
    		frame.setTitle("ShowGridLayout");
    		frame.setSize(200, 125);
    		frame.setLocationRelativeTo(null);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setVisible(true);
    	}
    }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Help with how to set up my layout

    Rather than adding your components directly to the frame, try adding them to a panel and then the panel to the frame. The advantage of this is you can add one, two or more panels to other panels and each panel can have a different layout manager. Do this as many times as you need to achieve the layout you want.
    Improving the world one idiot at a time!

Similar Threads

  1. Is there a layout for this?
    By gkffjcs in forum AWT / Java Swing
    Replies: 2
    Last Post: September 27th, 2011, 09:15 AM
  2. Layout Manager
    By mDennis10 in forum AWT / Java Swing
    Replies: 4
    Last Post: September 3rd, 2011, 10:27 PM
  3. Replies: 1
    Last Post: April 14th, 2011, 07:50 AM
  4. Grid bag layout inside grid bag layout
    By kiddkoder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 29th, 2011, 08:07 AM
  5. Layout manager
    By kurt-hardy in forum AWT / Java Swing
    Replies: 3
    Last Post: January 19th, 2011, 10:25 AM