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: [Help]How do I fix this?[Help]

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question [Help]How do I fix this?[Help]

    Hey guys I'm new to this forum so sorry if this is the wrong section.Anyways I was wondering why are the buttons together? View UtZ3Mk.png on ScreenSnapr

    Here is the code:

    tuna.java
    import java.awt.FlowLayout;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
     
    public class tuna extends JFrame {
    	private JLabel item1;
    	private JButton reg;
    	private JButton reg2;
    	private JButton reg3;
     
    	public tuna() {
    		super("Matrix-RPG");
    		setLayout(new FlowLayout());
     
    		item1 = new JLabel("Welcome to Matrix RPG");
    		item1.setToolTipText("Coded in Java by Dayron1234");
    		add(item1);
     
    		reg = new JButton("Singleplayer");
    		add(reg);
    		reg2 = new JButton("Multiplayer");
    		add(reg2);
    		reg3 = new JButton("Change Language");
    		add(reg3);
    	}
    }

    apples.java
    import javax.swing.JFrame;
     
    class apples {
    	public static void main(String[] args) {
     
    		tuna matrix = new tuna();
    		matrix.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		matrix.setSize(500, 500);
    		matrix.setVisible(true);
    	}
    }

    I want the buttons on top of each other and centered but I don't know how to do that.If you don't know what I mean then I mean like this:

    Singleplayer button
    Multiplayer button
    Change Langauge

    On top of each other and centered.


  2. #2
    Member
    Join Date
    Jun 2011
    Posts
    182
    My Mood
    Where
    Thanks
    15
    Thanked 8 Times in 8 Posts

    Default Re: [Help]How do I fix this?[Help]

    You should probably read up on the Swing and AWT libraries to learn more about managing GUI layouts and components.

    For what you're trying to do, I would recommend taking a look at Box and/or BoxLayout specifically.

  3. The Following User Says Thank You to bgroenks96 For This Useful Post:

    Dayron1234 (April 8th, 2012)

  4. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: [Help]How do I fix this?[Help]

    Thanks for the links! Much thanks once again.