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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:43:12+00:00 2026-05-16T01:43:12+00:00

Here is the issue I am having. I have a JToolBar that contains 3

  • 0

Here is the issue I am having. I have a JToolBar that contains 3 JPanel‘s and each panel contains some various components. The panel that contains my JProgressBar is only visible when there is something loading. What happens when it changes from visible to not visible is my other two panels shift by approx 1 pixel. Here is the code:

private JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL);
private JPanel progressPanel = new JPanel();
private JPanel globalPanel = new JPanel();
private JPanel cameraPanel = new JPanel();
private JLabel cameraLabel = new JLabel("Camera: ");
private JLabel cameraCoords = new JLabel();
private JLabel globalLabel = new JLabel("Global: ");
private JLabel globalCoords = new JLabel();

progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.X_AXIS));
progressPanel.setBackground(Color.RED);
globalPanel.setLayout(new BoxLayout(globalPanel, BoxLayout.X_AXIS));
globalPanel.setBackground(Color.BLUE);
cameraPanel.setLayout(new BoxLayout(cameraPanel, BoxLayout.X_AXIS));
cameraPanel.setBackground(Color.GREEN);

progressBar.setFocusable(false);
progressBar.setPreferredSize(new Dimension(100,0));
progressBar.setMaximumSize(new Dimension(150,20));
progressBar.setStringPainted(true);
//progressBar.setAlignmentY(Component.CENTER_ALIGNMENT);

progressPanel.add(progressBar);
//globalLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
//globalCoords.setAlignmentY(Component.CENTER_ALIGNMENT);
globalPanel.add(globalLabel);
globalPanel.add(globalCoords);

//cameraLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
//cameraCoords.setAlignmentY(Component.CENTER_ALIGNMENT);
cameraPanel.add(cameraLabel);
cameraPanel.add(cameraCoords);


this.setBorder(new EmptyBorder(5,5,5,5));
this.setPreferredSize(new Dimension(0,30));
this.add(progressPanel);
this.add(Box.createHorizontalGlue());
this.addSeparator();
this.add(globalPanel);
this.addSeparator();
this.add(cameraPanel);
this.setFloatable(false);

Now when ever I set progressPanel.setVisible(false) the JLabel‘s shift by a pixel. Where I have the alignment commented out is where I tried to get them to align, but this still did not work. What am I doing wrong here?

  • 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-05-16T01:43:12+00:00Added an answer on May 16, 2026 at 1:43 am
    public class StatusBar extends JPanel{ //Instead of JToolBar
        private JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL);
        private JPanel progressPanel = new JPanel();
        private JPanel globalPanel = new JPanel();
        private JPanel cameraPanel = new JPanel();
        private JLabel cameraLabel = new JLabel("Camera: ");
        private JLabel cameraCoords = new JLabel();
        private JLabel globalLabel = new JLabel("Global: ");
        private JLabel globalCoords = new JLabel();
    
        public StatusBar(){
            progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.X_AXIS));
            globalPanel.setLayout(new BoxLayout(globalPanel, BoxLayout.X_AXIS));
            cameraPanel.setLayout(new BoxLayout(cameraPanel, BoxLayout.X_AXIS));
    
            progressBar.setFocusable(false);
            progressBar.setPreferredSize(new Dimension(100,0));
            progressBar.setMaximumSize(new Dimension(150,20));
            progressBar.setStringPainted(true);
    
            progressPanel.add(tileLoadingLabel);
            progressPanel.add(Box.createHorizontalStrut(5));
            progressPanel.add(progressBar);
            globalPanel.add(globalLabel);
            globalPanel.add(globalCoords);
            globalPanel.add(separator);
            globalCoords.setPreferredSize(new Dimension(150,0));
    
            //Here is where I made the change(after extending JPanel and not JToolBar
            //I used the BorderLayout instead of the BoxLayout  
            this.setLayout(new BorderLayout());
            this.setBorder(new EmptyBorder(5,5,5,5));
            this.setPreferredSize(new Dimension(0,30));
            this.add(globalPanel,BorderLayout.WEST);
            this.add(Box.createHorizontalGlue());
            this.add(progressPanel,BorderLayout.EAST);
        }
    }
    

    I did not think about posting the answer myself, I will know for the future, thanks for the insight 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the issue I am having: I have a large query that needs
Having an issue here that I have tried everything I can think of but
I am having some weird issue here. I have a database table which has
im having a little issue here. I have MediaElement.js set on my project. It
hello fellow java developers. I'm having a bit of an issue here. I have
I am having an issue here i have a list this.Ddown having 3 properties
Basically I'm having a little issue here. I have a superclass and a subclass.
I'm having a strange issue here, i have this bit of code: <?php if
I'm having a MIPS issue here. What I'm trying to do is have the
I'm having a very weird issue here, I have set-up my solr architecture as

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.