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: GUI Frame Help

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default GUI Frame Help

    Hey guys. I'm new to GUI and am having problems on an assignment I was given. I have to make a frame and it is not working the way I'd like it to. The course I'm taking has one example, and I'm using it as a guide to help me. This is as far as I got. When I run the program, the objects appear in places that I do not want to them to appear in. I'd appreciate any and all tips to help me. Thank you

    import java.awt.*;
     
    public class GUIFinal extends Frame{
     
    	GUIFinal(){
    		setTitle("Frame Example");
    		setSize(300, 300);
    		show();
    	}
     
    	public static void main(String[] args) {
    		Frame f = new GUIFinal();
    		Button b = new Button("Button");
    		TextField tf = new TextField("TextField");
    		TextArea ta = new TextArea("TextArea");
    		Checkbox c = new Checkbox("Checkbox");
    		Label la = new Label("Label");
    		Scrollbar sb = new Scrollbar();
     
    		b.setBounds(10, 50, 25, 25);
    		tf.setBounds(40, 50, 50, 25);
    		ta.setBounds(20, 30, 60, 30);
    		c.setBounds(85, 45, 25, 25);
    		la.setBounds(25, 10, 10, 10);
    		sb.setBounds(5, 30, 10, 30);
     
    		f.add(b);
    		f.add(tf);
    		f.add(ta);
    		f.add(c);
    		f.add(la);
    		f.add(sb);
     
     
     
    	}
     
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,358
    Thanks
    182
    Thanked 834 Times in 777 Posts
    Blog Entries
    5

    Default Re: GUI Frame Help

    the objects appear in places that I do not want to them to appear in. I'd appreciate any and all tips to help me. Thank you
    Do you mean the Components? Are you familiar with LayoutManagers? See..
    A Visual Guide to Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    851
    Thanks
    0
    Thanked 158 Times in 141 Posts

    Default Re: GUI Frame Help

    You should never set the bounds of objects yourself, this is supposed to be done only by the layout manager.
    If you want to set these values yourself (which is not recommended) you need to set the layout manager of your frame to "null".

Similar Threads

  1. New frame should only show GUI once!
    By gerre in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 30th, 2012, 11:34 PM
  2. Replies: 1
    Last Post: January 19th, 2012, 03:44 PM
  3. Replies: 3
    Last Post: February 1st, 2010, 12:24 AM