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.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: GUI problem

  1. #1
    Join Date
    Feb 2013
    Thanked 0 Times in 0 Posts

    Default GUI problem


    I am working on a GUI project and have been having issues. I have managed to properly position the button, the text field, and the text area, but am unable to position the scroll bar, check box, or label. I cannot see the label, the checkbox is fixed in an area that makes it obscured by the text area, and the scroll bar covers the entire frame. I tried to remedy the scroll bar issue by using the border layout and putting it west, but it still doesn't have the proper size of the image given. I have tried to use the setbounds method to position and size the scroll bar, and the set location method to position both the label and the checkbox, but both instances, nothing happens, and I don't understand why. Any guidance would be extremely helpful! I've attached the code so far, if you want a reference.

    import java.awt.*;
    import java.awt.event.*;
    public class FrameExample 
    TextField tf;
    TextArea ta;
    Checkbox cb;
    Scrollbar sb;
    public static void main(String args[])
    FrameExample fe = new FrameExample();
    public FrameExample()
    Frame f= new Frame("Frame Example");
    Button button = new Button("Button");
    Label lbl= new Label("Label");
    tf = new TextField("TextField", 100);
    ta = new TextArea("TextArea");
    cb = new Checkbox("Checkbox");
    sb = new Scrollbar();
    button.setBounds(20, 40, 50, 50);
    lbl.setLocation(130, 200);
    tf.setBounds(100, 40, 120, 50);
    ta.setBounds(30, 110, 150, 100);
    cb.setLocation(250, 200);
    sb.setBounds(5, 110, 25, 100);
    button.addMouseListener(new MyMouseListener());
    f.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent we)

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 636 Times in 540 Posts

    Default Re: GUI problem

    Use a layout manager instead of trying to position everything yourself.

    Using Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. First GUI Problem
    By shodai in forum AWT / Java Swing
    Replies: 5
    Last Post: March 31st, 2013, 04:27 PM
  2. GUI problem
    By Fantasy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 21st, 2011, 09:09 PM
  3. From Console to GUI : problem !!
    By hexwind in forum AWT / Java Swing
    Replies: 33
    Last Post: August 20th, 2011, 10:50 PM
  4. GUI problem
    By Reem in forum AWT / Java Swing
    Replies: 6
    Last Post: November 15th, 2010, 09:45 AM
  5. GUI Problem
    By bulldog in forum AWT / Java Swing
    Replies: 1
    Last Post: December 11th, 2009, 01:47 PM

Tags for this Thread