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: Want to move my button away from center.

  1. #1
    Member Fendaril's Avatar
    Join Date
    Nov 2008
    Posts
    54
    Thanks
    7
    Thanked 6 Times in 5 Posts

    Default Want to move my button away from center.

    Hello. I am trying to move my button to the topmost part of my application's window.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    public class test extends JFrame{
     
    public test()
    {
    super("A window");
    setSize(500,500);
    setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
     
    JPanel panel=new JPanel();
     
    JButton button=new JButton("Hey my name is bob");
    panel.setLayout(new GridBagLayout());
    GridBagConstraints constraints=new GridBagConstraints();
    constraints.gridwidth=10;
    constraints.gridheight=10;
    constraints.gridx=0;
    constraints.gridy=0;
    constraints.fill=GridBagConstraints.BOTH;
    panel.add(button,constraints);
    add(panel);
     
    setVisible(true);
     
     
    	}
     
    public static void main(String[] s) {
        	test a=new test();
     
        }
     
     
    }

    I read the java sun tuts on gridbaglayout but I am still struggling as far as learning how to place controls.Can someone tell me how to position componenets on a gridbaglayout pane the exact way i want them to be layed out?


  2. #2
    Junior Member
    Join Date
    Sep 2009
    Location
    Mount Morgan, Queensland, Australia
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Want to move my button away from center.

    Instead of using GridBagLayout, try using FlowLayout. It will set the button to the top center of the panel.

  3. #3
    Member Fendaril's Avatar
    Join Date
    Nov 2008
    Posts
    54
    Thanks
    7
    Thanked 6 Times in 5 Posts

    Default Re: Want to move my button away from center.

    Thanks for the quick response.

Similar Threads

  1. How to move an image (or how to delete one)
    By User in forum AWT / Java Swing
    Replies: 3
    Last Post: December 17th, 2009, 11:25 AM
  2. The Frame to be Center Position
    By r12ki in forum AWT / Java Swing
    Replies: 3
    Last Post: October 1st, 2009, 10:36 AM
  3. [SOLVED] Implementing push button
    By IDK12 in forum AWT / Java Swing
    Replies: 2
    Last Post: July 10th, 2009, 10:13 AM
  4. How to upload a file by clicking a link instead of button?
    By raghuprasad in forum Java Theory & Questions
    Replies: 2
    Last Post: May 3rd, 2009, 05:21 AM