Results 1 to 2 of 2
Like Tree2Likes
  • 2 Post By DarrylBurke

Thread: How to change the location of buttons on a JFrame???

  1. #1
    nithyajann is offline Member
    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Default How to change the location of buttons on a JFrame???

    Hi!,
    By executing the below code,Im getting the 4 buttons(side by side) in the top-center position.
    But,I want to change the positions of the button to the complete left side of my frame...i,e; one below the other...How to change it...Pls help me out...Thanks ...:)


    public Systems()
    {
    JFrame frame = new JFrame("FIRST OUTLAY ");
    JPanel pan = new JPanel();
    button1 = new JButton("OS info");
    button2 = new JButton("N/W info");
    button3 = new JButton("Java info");
    button4 = new JButton("Memory info");

    area = new JTextArea();

    button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);
    button4.addActionListener(this);
    pan.add(button1);
    pan.add(button2);
    pan.add(button3);
    pan.add(button4);

    //pan.setLayout(new FlowLayout());

    jsp= new JScrollPane(area);
    frame.add(jsp);

    jsp.setBounds(100, 60, 380, 400);

    frame.add(pan);

    frame.setSize(600, 600);
    frame.setLocation(100,100);
    frame.setVisible(true);
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: How to change the location of buttons on a JFrame???

    Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    1) Look around the FAQs section of the site and learn how to post code so it retains its formatting.
    2) Don't use setBounds(...), use an appropriate layout manager. In your code sample, setBounds(...) wouldn't be effective, and you wouldn't see the scroll pane either.
    3) As far as your immediate question is concerned, FlowLayout has more than one constructor. Apply the one most appropriate to your need.

    db
    nithyajann and Fubarable like this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. jSplitPane and divider Location after jFrame resize?
    By michalss in forum AWT / Swing
    Replies: 6
    Last Post: 04-21-2011, 12:33 PM
  2. JFrame-buttons missing
    By Jodokus in forum AWT / Swing
    Replies: 5
    Last Post: 01-20-2011, 05:10 PM
  3. Selecting Radio Buttons to change frames?
    By jchsu in forum AWT / Swing
    Replies: 3
    Last Post: 02-25-2010, 11:06 AM
  4. JFrame 's components size and location problem
    By petrosgraf in forum Threads and Synchronization
    Replies: 5
    Last Post: 04-18-2009, 02:24 AM
  5. How to Change MySQL Database Location
    By sayan751 in forum JDBC
    Replies: 3
    Last Post: 03-19-2009, 02:42 PM

Posting Permissions

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