Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8713363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:19:35+00:00 2026-06-13T05:19:35+00:00

I’m working on a GUI, and I’m trying to format to look more appealing

  • 0

I’m working on a GUI, and I’m trying to format to look more appealing for the user, however; I’ve run into a few roadblocks, one being I can’t figure out how I would properly center JButtons in an existing JPanel, I’ve managed to arrange them into rows, I would like to know some more about how I can really format these.(If you’re interested in helping me in my other problem look here, How to set output stream to TextArea)

This is what I have currently.

If you click the link it will show you what I currently have in one of my tabs, I would like for the JButtons in the picture to be centered on the X-Axis instead of to the left as they are as a default setting I suppose.

So here’s my code, it arranges vertically, I need all of the rows to be centered though.

package guipanel;

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author Dan
 */
public class GUIPanel extends JFrame {
    /**
     * Creates new form GUIPanel
     */
    public GUIPanel() {
        initComponents();
    }
    private void setOutputStream(boolean catchErrors) throws IOException {
        System.setOut(new PrintStream(new FilterOutputStream(new ByteArrayOutputStream()))); // catches System.out messages
        setVisible(true);
        requestFocus();
        if (catchErrors) {
               System.setErr(new PrintStream(new FilterOutputStream(new ByteArrayOutputStream())));
        }
    }
    private void setPosition(JPanel jPanel) {
        GridBagLayout layout = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = gbc.CENTER;
        layout.setConstraints(jPanel, gbc);
        jPanel.setLayout(layout);
    }
    private void addTabs(JTabbedPane jTabbedPane1) throws IOException {
        jTabbedPane1.add("Main", jPanel);
        jPanel.add(textArea1);
        jTabbedPane1.add("Commands", jPanel1);
        jTabbedPane1.add("Rules", jPanel2);
        jTabbedPane1.add("Links", jPanel3);
        jPanel3.add(website);
        jPanel3.add(jSeparator1);
        jPanel3.add(youtube);
        jPanel3.add(jSeparator2);
        jPanel3.add(webclient);
        jPanel3.add(jSeparator4);
        jPanel3.add(forums);
        jTabbedPane1.add("Information", jPanel4);
        jTabbedPane1.add("Shutdown", jPanel5);
        jPanel5.add(Shutdown);
        jPanel3.setLayout(new BoxLayout(jPanel3, BoxLayout.PAGE_AXIS));
        setPosition(jPanel5);
        setOutputStream(true);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        textArea1 = new java.awt.TextArea();
        jLabel1 = new javax.swing.JLabel();
        website = new javax.swing.JButton();
        youtube = new javax.swing.JButton();
        forums = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        webclient = new javax.swing.JButton();
        Shutdown = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        textArea1.setPreferredSize(new java.awt.Dimension(432, 300));
        textArea1.getAccessibleContext().setAccessibleParent(jTabbedPane1);

        jLabel1.setText("Evolution-X™ Programmed by Musicmasta.");
        jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jLabel1.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        website.setText("Website");
        website.setMaximumSize(new java.awt.Dimension(133, 37));
        website.setPreferredSize(new java.awt.Dimension(133, 37));
        website.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        website.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                websiteActionPerformed(evt);
            }
        });

        youtube.setText("Youtube");
        youtube.setMaximumSize(new java.awt.Dimension(133, 37));
        youtube.setPreferredSize(new java.awt.Dimension(133, 37));
        youtube.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                youtubeActionPerformed(evt);
            }
        });

        forums.setText("Forums");
        forums.setMaximumSize(new java.awt.Dimension(133, 37));
        forums.setPreferredSize(new java.awt.Dimension(133, 37));
        forums.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        forums.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                forumsActionPerformed(evt);
            }
        });
        forums.getAccessibleContext().setAccessibleName("Forums");

        webclient.setText("Webclient");
        webclient.setMaximumSize(new java.awt.Dimension(133, 37));
        webclient.setName(""); // NOI18N
        webclient.setPreferredSize(new java.awt.Dimension(133, 37));
        webclient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                webclientActionPerformed(evt);
            }
        });
        webclient.getAccessibleContext().setAccessibleName("");

        Shutdown.setText("Shutdown");
        Shutdown.setMaximumSize(new java.awt.Dimension(221, 81));
        Shutdown.setPreferredSize(new java.awt.Dimension(221, 81));
        Shutdown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ShutdownActionPerformed(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Evolution-X 639");
        setBounds(new java.awt.Rectangle(0, 0, 400, 450));
        setPreferredSize(new java.awt.Dimension(450, 420));
        getContentPane().setLayout(new java.awt.FlowLayout());

        try {
            addTabs(jTabbedPane1);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        jTabbedPane1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTabbedPane1.setFocusable(false);
        jTabbedPane1.setOpaque(true);
        getContentPane().add(jTabbedPane1);
        jTabbedPane1.getAccessibleContext().setAccessibleName("");

        jMenu1.setText("File");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem2.setText("Exit");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        System.exit(0);
    }                                      

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        System.exit(0);
    }                                          

    private void youtubeActionPerformed(java.awt.event.ActionEvent evt) {
        Desktop desktop = Desktop.getDesktop();
        try {
            youtubelink = new URI("http://youtube.com/user/theevolutionx10");
            try {
                desktop.browse(youtubelink);
            } catch (IOException ex) {
                Logger.getLogger(GUIPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (URISyntaxException ex) {
            Logger.getLogger(GUIPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void websiteActionPerformed(java.awt.event.ActionEvent evt) {
        Desktop desktop = Desktop.getDesktop();
        try {
            websitelink = new URI("http://evolutionx.x10.mx/");
            try {
                desktop.browse(websitelink);
            } catch (IOException ex) {
                Logger.getLogger(GUIPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (URISyntaxException ex) {
            Logger.getLogger(GUIPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void forumsActionPerformed(java.awt.event.ActionEvent evt) {

        Desktop desktop = Desktop.getDesktop();
        try {
            forumlink = new URI("http://www.evolutionx.x10.mx/forum/index.php");
            try {
                desktop.browse(forumlink);
            } catch (IOException ex) {
                Logger.getLogger(GUIPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (URISyntaxException ex) {
            Logger.getLogger(GUIPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void webclientActionPerformed(java.awt.event.ActionEvent evt) {
        Desktop desktop = Desktop.getDesktop();
        try {
            webclientlink = new URI("http://evolutionx.x10.mx/play.html");
            try {
                desktop.browse(webclientlink);
            } catch (IOException ex) {
                Logger.getLogger(GUIPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (URISyntaxException ex) {
            Logger.getLogger(GUIPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void ShutdownActionPerformed(java.awt.event.ActionEvent evt) {
        System.exit(0);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUIPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUIPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUIPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUIPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUIPanel().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton Shutdown;
    private javax.swing.JButton forums;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private java.awt.TextArea textArea1;
    private javax.swing.JButton webclient;
    private javax.swing.JButton website;
    private javax.swing.JButton youtube;
    // End of variables declaration
    private JPanel jPanel = new JPanel();
    private JPanel jPanel1 = new JPanel();
    private JPanel jPanel2 = new JPanel();
    private JPanel jPanel3 = new JPanel();
    private JPanel jPanel4 = new JPanel();
    private JPanel jPanel5 = new JPanel();
    private URI webclientlink, youtubelink, forumlink, websitelink;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:19:36+00:00Added an answer on June 13, 2026 at 5:19 am

    You only have to add this lines before add the buttons to the tab:

    website.setAlignmentX(Component.CENTER_ALIGNMENT);
    youtube.setAlignmentX(Component.CENTER_ALIGNMENT);
    webclient.setAlignmentX(Component.CENTER_ALIGNMENT);
    forums.setAlignmentX(Component.CENTER_ALIGNMENT);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.