Results 1 to 4 of 4
  1. #1
    firecat318 is offline Member
    Join Date
    May 2010
    Posts
    6
    Rep Power
    0

    Default Help with alignment

    Here is my program, its like a 3 number hi-low game.



    I am using JPANEL for the top, middle, and bottom rows. Then inside those panels I use gridlayout to layout the objects. I want to know if instead of them being in their respective grids on the left hand side, if they could be centered inside of their grid?

    I tried using setAlignmentX and that didn't work. I don't really know how to go about it. I'll post a snippet of my code that is important.

    Java Code:
    //middle panel setup
            JPanel middle = new JPanel();
            middle.setLayout(new GridLayout(1, 3));
    
            higher = new JButton("Higher");
            higher.setAlignmentX(CENTER_ALIGNMENT);
            middle.add(higher);
    
            or = new JLabel("OR");
            or.setAlignmentX(CENTER_ALIGNMENT);
            middle.add(or);
    
            lower = new JButton("Lower");
            lower.setAlignmentX(CENTER_ALIGNMENT);
            middle.add(lower);
            pane.add(middle);
    EDIT: I drew what I want it to be like in paint... :D


  2. #2
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Hello and welcome to the forum.

    JLabel has a constructor that allows you to set the position of the text in the label, i.e.,

    Java Code:
    JLabel myLabel = new JLabel("Spamalot", SwingConstants.CENTER);
    Why not give this a try and let us know if it helps.

  3. #3
    firecat318 is offline Member
    Join Date
    May 2010
    Posts
    6
    Rep Power
    0

    Default

    Lol wow you are a GOD. Thanks!

  4. #4
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by firecat318 View Post
    Lol wow you are a GOD. Thanks!
    Nah, just someone who had the same problem as you some time in the past. Glad it helped and hope to see you around here again.

Similar Threads

  1. Alignment using BoxLayout
    By tiptoe in forum AWT / Swing
    Replies: 4
    Last Post: 01-23-2010, 08:15 PM
  2. Alignment Issue...
    By chanduseec in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 09-30-2008, 07:47 AM
  3. Label Alignment Example
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 08:49 PM
  4. [SOLVED] alignment problem
    By nanimtech in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-10-2008, 02:23 PM
  5. alignment of textfield in awt
    By nitinborge5 in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 12:16 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
  •