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 8155225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:36:33+00:00 2026-06-06T16:36:33+00:00

I’m creating an about JFrame for my program. I have an icon which I

  • 0

I’m creating an about JFrame for my program. I have an icon which I used for the program and I have that show up as the first thing on the about JFrame, but I’m having issues trying to center the image. If I do some kind of centering it screws up the whole alignment of everything else.

I’m trying to have all the JLabels, other than the icon, to be left aligned. Then have the icon aligned to the center.

I had to remove some personal information, whatever I did remove I put them between “[]”.

import java.awt.Dimension;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class About extends JFrame {

    public About() {
        super("About [PROGRAM]");
        setIconImage([PROGRAM].getInstance().setIcon());

        JPanel main = new JPanel();

        main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
        main.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

        JLabel icon = new JLabel("", new ImageIcon(getClass().getResource(Constants.ICON_FULL)), JLabel.CENTER);        
        JLabel name = new JLabel("[PROGRAM]");
        JLabel expandedName = new JLabel("[PROGRAM DESCRIPTION]");
        JLabel copyright = new JLabel("[COPYRIGHT JUNK]");
        JLabel credits = new JLabel("[CREDITS]");

        name.setFont(new Font(name.getFont().getFamily(), Font.BOLD, 18));

        copyright.setBorder(BorderFactory.createEmptyBorder(0,0,10,0));

        main.add(icon);
        main.add(Box.createRigidArea(new Dimension(0, 10)));
        main.add(name);
        main.add(expandedName);
        main.add(copyright);
        main.add(credits);

        add(main);

        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }

}
  • 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-06T16:36:34+00:00Added an answer on June 6, 2026 at 4:36 pm

    Consider using some layouts to help you out. Ones that come to mind include BorderLayout with the icon in the BorderLayout.CENTER position. You can stack stuff on one side using a BoxLayout using JPanel that is added to the main BorderLayout-using JPanel.

    e.g.,

    import java.awt.BorderLayout;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    
    import javax.imageio.ImageIO;
    import javax.swing.*;
    
    @SuppressWarnings("serial")
    public class About extends JDialog {
       public static final String IMAGE_PATH = "http://upload.wikimedia.org/wikipedia/"
             + "commons/thumb/3/39/European_Common_Frog_Rana_temporaria.jpg/"
             + "800px-European_Common_Frog_Rana_temporaria.jpg";
    
       public About(JFrame frame) {
          super(frame, "About [PROGRAM]", true);
    
          ImageIcon myIcon = null;
          try {
             URL imgUrl = new URL(IMAGE_PATH);
             BufferedImage img = ImageIO.read(imgUrl);
             myIcon = new ImageIcon(img);
          } catch (MalformedURLException e) {
             e.printStackTrace();
             System.exit(-1);
          } catch (IOException e) {
             e.printStackTrace();
             System.exit(-1);
          }
    
          JPanel main = new JPanel(new BorderLayout());
    
          main.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    
          JLabel centerLabel = new JLabel(myIcon);
          JLabel name = new JLabel("[PROGRAM]");
          JLabel expandedName = new JLabel("[PROGRAM DESCRIPTION]");
          JLabel copyright = new JLabel("[COPYRIGHT JUNK]");
          JLabel credits = new JLabel("[CREDITS]");
    
          name.setFont(new Font(name.getFont().getFamily(), Font.BOLD, 18));
    
          copyright.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
    
          int eb = 20;
          centerLabel.setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));
    
          JPanel leftPanel = new JPanel();
          leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
          leftPanel.add(name);
          leftPanel.add(Box.createVerticalGlue());
          leftPanel.add(expandedName);
          leftPanel.add(copyright);
          leftPanel.add(credits);
          leftPanel.add(Box.createVerticalGlue());
    
          main.add(centerLabel, BorderLayout.CENTER);
          main.add(leftPanel, BorderLayout.LINE_START);
    
          add(main);
    
          pack();
       }
    
       public static void main(String[] args) {
          final JFrame frame = new JFrame("GUI");
          JPanel panel = new JPanel();
          panel.add(new JButton(new AbstractAction("About") {
    
             @Override
             public void actionPerformed(ActionEvent e) {
                About about = new About(frame);
                about.setLocationRelativeTo(frame);
                about.setVisible(true);
             }
          }));
          frame.add(panel);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

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.