Results 1 to 3 of 3
  1. #1
    LizardMan090 is offline Member
    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Question I cannot understand my error. My GUI labels won't work out.

    I am trying to complete an exercise where I have to display four Labels of the GUI with borders, no gaps, one under the other, and fill the window box thing-y. However, my code results in a gap between the labels(where there shouldn't be) and the school of computing lines ending abruptly where they should continue out to the rest of the page. Can someone fix this please???

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    
    
    public class Exercise12_05 extends JFrame{
    	
    	private JLabel label1,label2,label3,label4;
    	
    	public Exercise12_05()
    	{
    		setLayout(new GridLayout(4,1));
    		label1 = new JLabel("Department of Computer Science    ");
    		label1.setBorder(new LineBorder(Color.BLACK,1));
    		label2 = new JLabel("School of Computing");
    		label2.setBorder(new LineBorder(Color.BLACK,1));
    		label3 = new JLabel("Armstrong Atlantic State University");
    		label3.setBorder(new LineBorder(Color.BLACK,1));
    		label4 = new JLabel("Tel: (912)921-6440                 ");
    		label4.setBorder(new LineBorder(Color.BLACK,1));
    		add(label1);
    		add(label2);
    		add(label3);
    		add(label4);
    		setLayout((new FlowLayout(FlowLayout.LEFT)));
    	}
    	
    	public static void main(String[]args)
    	{
    		Exercise12_05 frame = new Exercise12_05();
    		frame.setTitle("Execise 12_5");
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
    	}
    }

  2. #2
    dd09wrx is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: I cannot understand my error. My GUI labels won't work out.

    try this:
    Java Code:
    public class Exercise12_05 extends JFrame{
         
        private JLabel label1,label2,label3,label4;
         
        public Exercise12_05()
        {
            setLayout(new GridLayout(4,1));
            label1 = new JLabel("Department of Computer Science    ");
            label1.setBorder(new LineBorder(Color.BLACK,1));
            label2 = new JLabel("School of Computing");
            label2.setBorder(new LineBorder(Color.BLACK,1));
            label3 = new JLabel("Armstrong Atlantic State University");
            label3.setBorder(new LineBorder(Color.BLACK,1));
            label4 = new JLabel("Tel: (912)921-6440                 ");
            label4.setBorder(new LineBorder(Color.BLACK,1));
            add(label1);
            add(label2);
            add(label3);
            add(label4);
            
            pack();
        }
         
        public static void main(String[]args)
        {
            Exercise12_05 frame = new Exercise12_05();
            frame.setTitle("Execise 12_5");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    }

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,579
    Rep Power
    23

    Default Re: I cannot understand my error. My GUI labels won't work out.

    @ddr09wrx Please don't spoonfeed code. Try to explain what the problem and guide the OP to how to fix it.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 13
    Last Post: 10-04-2012, 07:45 PM
  2. I don't understand this error....
    By Lund01 in forum XML
    Replies: 13
    Last Post: 07-10-2011, 12:40 AM
  3. I do not understand this error with charAt()
    By AcousticBruce in forum New To Java
    Replies: 20
    Last Post: 12-25-2010, 06:19 PM
  4. I don't understand the error ... (help!)
    By XmisterIS in forum New To Java
    Replies: 3
    Last Post: 09-02-2010, 09:33 AM
  5. i don understand this error
    By Deon in forum New To Java
    Replies: 4
    Last Post: 01-12-2008, 10:03 AM

Posting Permissions

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