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

Thread: Help w/ hw , help with panels layouts in frame.

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

    Default Help w/ hw , help with panels layouts in frame.

    It is a class assignment, I have to create a form as given in a picture but I was not given any instructions ...
    Now they did say the window is splited to 3 forms.
    I am not sure what to do I think they meant panels? (by saying forms)...

    this is the pic:
    class_hw.jpg

    My program is different, I don;t know what to do witht he middle panel, I used grid and it's even on the columns unlike the example I tried using different layouts but for no use

    Now I have no idea what this gray line in between the panels is...

    Please help me figure this out.

    This is my code:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.GridLayout;
     
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.SwingConstants;
    import javax.swing.border.Border;
    import javax.swing.border.LineBorder;
    import javax.swing.border.TitledBorder;
     
     
    public class HW2_ShirFriedman {
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		new ApplicationForm();				
    	}
     
    }
     
    class ApplicationForm
    {
    	ApplicationForm()
    	{
    		boolean aln=false;		
    	//declaring the frame
    		JFrame frame = new JFrame("Aplication Form");
     
     
    		//frame settings
    		frame.setSize(550, 400);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setLocationRelativeTo(null); // Center the frame
    		frame.setAlwaysOnTop(true);
    		//frame.pack();
    		frame.setVisible(true);
    		frame.setLayout(new BorderLayout());
    		frame.setResizable(false);
     
     
     
    		//north panel					
    		JPanel Personal_Information=new JPanel(new GridLayout(4,2,0,5));		
     
    		Personal_Information.setBorder(new TitledBorder("Personal Information"));
    		aln=true;
     
    		Personal_Information.add(createLabel("*First name: ",Color.RED,null,aln));					
    		Personal_Information.add(new JTextField(""));
     
    		Personal_Information.add(createLabel("*Last name: ",Color.RED,null,aln));					
    		Personal_Information.add(new JTextField(""));
     
    		Personal_Information.add(createLabel("Adress: ",null,null,aln));					
    		Personal_Information.add(new JTextField(""));
     
    		Personal_Information.add(createLabel("*Cellular: ",Color.RED,null,aln));					
    		Personal_Information.add(new JTextField(""));
     
    		//attaching the north panel to the frame
    		frame.add(BorderLayout.NORTH,Personal_Information);
     
     
    		//center panel				
    		JPanel List_of_references=new JPanel(new GridLayout(5,2));
     
    		List_of_references.setBorder(new TitledBorder("List of references"));		
    		aln=true;
     
     
    		List_of_references.add(createLabel("*1: ",Color.RED,null,aln));					
    		List_of_references.add(new JTextField(""));
     
    		List_of_references.add(createLabel("*Tel: ",Color.RED,null,aln));					
    		List_of_references.add(new JTextField(""));
     
    		List_of_references.add(createLabel("2: ",null,null,aln));					
    		List_of_references.add(new JTextField(""));
     
    		List_of_references.add(createLabel("Tel: ",null,null,aln));					
    		List_of_references.add(new JTextField(""));
     
    		List_of_references.add(createLabel("3: ",null,null,aln));					
    		List_of_references.add(new JTextField(""));
     
    		List_of_references.add(createLabel("Tel: ",null,null,aln));					
    		List_of_references.add(new JTextField(""));
     
    		List_of_references.add(createLabel("4: ",null,null,aln));					
    		List_of_references.add(new JTextField(""));
     
    		List_of_references.add(createLabel("Tel: ",null,null,aln));					
    		List_of_references.add(new JTextField(""));
     
    		List_of_references.add(createLabel("5: ",null,null,aln));					
    		List_of_references.add(new JTextField(""));
     
    		List_of_references.add(createLabel("Tel: ",null,null,aln));					
    		List_of_references.add(new JTextField(""));			
     
    		//attaching the center panel to the frame
    		frame.add(BorderLayout.CENTER,List_of_references);
     
     
    		//south panel				
    		JPanel Programming_Languages=new JPanel(new GridLayout(2,5));		
    		Programming_Languages.setBorder(new TitledBorder("Programming Languages"));	
    		aln=false;
     
    		Border b=new LineBorder(Color.black,2);
    		Programming_Languages.add(createLabel("JAVA",null,b,aln));		
    		Programming_Languages.add(createLabel("C",null,b,aln));
    		Programming_Languages.add(createLabel("C++",null,b,aln));
    		Programming_Languages.add(createLabel("C#",null,b,aln));
    		Programming_Languages.add(createLabel("Prolog",null,b,aln));
     
    		Programming_Languages.add(createLabel("",null,b,aln));
    		Programming_Languages.add(createLabel("",null,b,aln));		
    		Programming_Languages.add(createLabel("",null,b,aln));		
    		Programming_Languages.add(createLabel("",null,b,aln));		
    		Programming_Languages.add(createLabel("",null,b,aln));
     
    		//attaching the center panel to the frame
     
    		frame.add(BorderLayout.SOUTH,Programming_Languages);
     
    	}
     
     
    	private JLabel createLabel(String label_name,Color c,Border b,boolean setalighright)
    	{
    		JLabel label=new JLabel(label_name);
    		if(setalighright)
    			label.setHorizontalAlignment(SwingConstants.RIGHT);	
    		else
    			label.setHorizontalAlignment(SwingConstants.CENTER);
     
    		label.setForeground(c);
    		label.setBorder(b);
    		Font myFont = new Font("Times New Roman", Font.ITALIC, 15);
     
    		label.setFont(myFont);
    		return label;
    	}
    }


    looks like this:
    class_hw_attempt.jpg


    PS:Sorry it turned out really small I hope u can see the difference in the middle panel and the green lines I am missing in my code but present in the example.


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Help w/ hw , help with panels layouts in frame.

    Have you considered using GridBagLayout, not GridLayout for the middle JPanel?

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

    Default Re: Help w/ hw , help with panels layouts in frame.

    I can try though we only learned grid flow and border in class.
    Though I don;t mind trying (which I will do right away) it still leaves the question how the gray line in between the panels is created.
    Since it adds to the width between the panels it does not seem to be a part of the panels I don't see a way to add it to the frame though.

    edit: after reading a bit about gridbag : gridbag seems complicated (in comparison to the basic 3 I pointed) since we didn't even mention its existance I hardly believe they expect us to use it.

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Help w/ hw , help with panels layouts in frame.

    The lines may be created by borders, but it's hard to tell as your images are so small.

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

    Default Re: Help w/ hw , help with panels layouts in frame.

    class_hw2.jpg
    I hope this is better
    They did split to 3 parts (using the word forms) but it could b anything I guess like parts in parts or w/e they did not say what not to use :S...
    -.- I am clueless....I tried compound border but I don;t need to touch the sides only upper and lower part of the middle panel.
    And yet again the middle panel's layout is wrong I can;t seem to fix it.

    Left column should start to the most left and go through the center while the right column should start at the end of the center and till the end of the right part.

    can;t make it happen (I can let it start from the center and go to the right, alright, but not from the left -.-)

Similar Threads

  1. Why do layouts never work the way I want them to?
    By sonicjr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 4th, 2012, 10:17 PM
  2. Replies: 3
    Last Post: May 5th, 2012, 08:33 AM
  3. Replies: 1
    Last Post: January 19th, 2012, 03:44 PM
  4. adding or removing panels to panels
    By luisp88 in forum AWT / Java Swing
    Replies: 3
    Last Post: November 1st, 2011, 04:37 PM
  5. Help with Layouts and Panels
    By Zookey in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 29th, 2011, 06:48 PM