Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java JPanel Help

  • 20-02-2006 10:45AM
    #1
    Registered Users, Registered Users 2 Posts: 623 ✭✭✭


    Hi all,

    Does anybody know how you can center alignment textboxs, Jbuttons etc within a JPanel in Java.

    The situation is that I have 3 sets of Jbuttons with JTextfields, and I want to have 1 on the lefthand side, 2nd in the middle and the 3rd one to the righthand side all of the Jpanel.

    Anybody know how its done, help would be great.

    thanks guys & girls

    signing off......


Comments

  • Registered Users, Registered Users 2 Posts: 12,027 ✭✭✭✭Giblet


    Try different layout managers.
    Something like CONTROL.setAlignmentX(CENTER_ALIGNMENT); would work aswell depending on what layout you use.


  • Registered Users, Registered Users 2 Posts: 4,188 ✭✭✭pH


    I thought that a flow layout (center) was the default layout manager, but if not you can try:
    panel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER));
    panel.add(button1);
    panel.add(button2);
    panel.add(button3);
    


  • Registered Users, Registered Users 2 Posts: 623 ✭✭✭smithslist


    Sorry I should be more detailed in what I wish to develop, I am creating 6 small JPanels, and I am creating them, one below the other.

    The problem is I can get the Labels (and TxtFields) to be central, with setting the size of each labels and the furthest two from the right I have as JLabel.right,

    But its the height between the top and bottom of each JLabel(or txtfield) that is different on each side within a single jpanel.

    start of jpanel

    label txtfield label txtfield label txtfield


    end of jpanel

    As you can see here with the space between the start - to - label, and the distance of jpanel end - to - label is different

    This is my problem.....

    thanks everyone for their help


  • Registered Users, Registered Users 2 Posts: 919 ✭✭✭timeout


    If you post a section of code showing what you have done then we can see more clearly where you are going wrong.


Advertisement