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

  • Home
  • SEARCH
  • 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 5960329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:48:41+00:00 2026-05-22T18:48:41+00:00

I am creating a java swing app which makes use of the JProgressBar control.

  • 0

I am creating a java swing app which makes use of the JProgressBar control. The control looks ok on Linux and Windows but it is too big for my likings on Mac. I would like to change its height.

I am constructing the entire layout via boxes, i.e. createHorizontalBox, etc. I understand that whatever I put in the box it should take its entire space.

Here is my code (it is ugly):

    this.iconLabel = new JLabel();
    this.nameLabel = new JLabel();
    this.statusProgressbar = new JProgressBar();
    this.pausePush = new PushButton();
    this.resumePush = new PushButton();
    this.actionPush = new PushButton();
    this.statusLabel = new JLabel("...");
    this.clientTask = null;

    this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    this.setOpaque(false);
    this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    this.add(this.iconLabel);

    Box container = Box.createVerticalBox();
    Box box = Box.createHorizontalBox();

    box.setOpaque(false);
    box.add(this.nameLabel);
    box.add(Box.createHorizontalGlue());

    container.add(box);

    this.pausePush.setVisible(false);
    this.resumePush.setVisible(false);
    this.actionPush.setVisible(false);

    box = Box.createHorizontalBox();

    box.setOpaque(false);
    box.add(this.statusProgressbar);
    box.add(this.pausePush);
    box.add(this.resumePush);
    box.add(this.actionPush);

    container.add(box);

    this.nameLabel.setFont(new Font(UIManager.getFont("TabbedPane.font").getFamily(), 0, 12));
    this.statusLabel.setFont(new Font(UIManager.getFont("TabbedPane.font").getFamily(), 0, 9));

    box = Box.createHorizontalBox();

    box.setOpaque(false);
    box.add(this.statusLabel);
    box.add(Box.createHorizontalGlue());

    container.add(box);

    this.add(container);

I am struggling to find the right way to layout all the components such as the JProgressBar height can be controlled.

Can you help?

UPDATE: Here is a small program which demonstrates the problem

package test;

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

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.UIManager;

public class Test {

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        JPanel panel = new JPanel();

        frame.setSize(500, 500);

        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
        panel.setOpaque(false);
        panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        JLabel nameLabel = new JLabel("...");
        JProgressBar statusProgressbar = new JProgressBar();
        JLabel statusLabel = new JLabel("...");

        Box container = Box.createVerticalBox();
        Box box = Box.createHorizontalBox();

        box.setOpaque(false);
        box.add(nameLabel);
        box.add(Box.createHorizontalGlue());

        container.add(box);

        statusProgressbar.setPreferredSize(new Dimension(0, 5)); // NOT WORKING

        box = Box.createHorizontalBox();

        box.setOpaque(false);
        box.add(statusProgressbar);

        container.add(box);

        nameLabel.setFont(new Font(UIManager.getFont("TabbedPane.font").getFamily(), 0, 9));
        statusLabel.setFont(new Font(UIManager.getFont("TabbedPane.font").getFamily(), 0, 9));

        box = Box.createHorizontalBox();

        box.setOpaque(false);
        box.add(statusLabel);
        box.add(Box.createHorizontalGlue());

        container.add(box);

        panel.add(container);

        frame.add(panel);
        frame.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-05-22T18:48:42+00:00Added an answer on May 22, 2026 at 6:48 pm
    1. A Box layout will attempt to stretch a component to its maximum size if space is available. So make sure that the preferred height and maximum height are the same values so it doesn’t get stretched.

    2. The size of the progress bar may be determined by the LAF. The Metal LAF uses “ProgressBar.horizontalSize”. Check out the UIManager Defaults and you might be able to customize it for the Mac.

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

Sidebar

Related Questions

I have a Swing runnable app which updates messages, then I have a Java
How would you go about creating a java swing table, which automatically creates a
I am using Java back end for creating an XML string which is passed
I am creating an application in java which will be the part of an
I'm creating some big files (DB exports) with Java and I need to put
I'm creating a Java app that creates 4 PDF files using iText. On the
We have a one Java Swing app. Now there is one requirement that it
I am new to Java Swing. I am creating a frame with some components.
I am creating a Java Application using netBeans and Swing Gui Builder. I am
I am new to creating Java web applications and came across this problem when

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.