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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:55:34+00:00 2026-06-02T19:55:34+00:00

When I set the min, value, and max of my JProgressBar they do not

  • 0

When I set the min, value, and max of my JProgressBar they do not update unless I close the window and reopen it.


Picture:

enter image description here

Can anyone give me any insight? I am scratching my head on this one. I tested to make sure that the parsing is done correctly(which is is). I tested to just put numbers in directly. Clearly it works, it just does not show the first time the window is opened(which makes me think that if I update the values it will only show the last values.

* EDIT *

Ladies and Gentleman… may I present… SSCCE. I am sorry to post this because now you will feel my pain with this 😡


package com.jayavon.game.helper;

import javax.swing.*;
import java.awt.event.*;

public class SSCCE extends JFrame implements WindowListener {

    private static final long serialVersionUID = 1L;
    JFrame frame;
    JPanel panel;
    JButton characterButton;
    JInternalFrame characterFrame;
    /* Character Window */
    JProgressBar totalExpProgressBar;

    Action ClassCharacterButton = new ClassCharacterButton();

    public static void main(String[] args){
        //for thread safety     
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new SSCCE();
            }
        });
    }

    SSCCE() {
        initGUI();
    }

    public void initGUI(){

        frame = new JFrame("SSCCE");
        panel = (JPanel)frame.getContentPane();

        /**********************************
         ** 
         **     Buttons
         **    
         *********************************/
        characterButton = new JButton("");
        characterButton.setBounds(50,175,395,100);
        characterButton.setVisible(true);
        characterButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("C"), "characterButtonPress");
        characterButton.getActionMap().put("characterButtonPress", ClassCharacterButton);
        characterButton.setAction(ClassCharacterButton);
        characterButton.setText("Click me three times(open/close/open) to get progress bar to fill");
        panel.add(characterButton);

        /**********************************
         ** 
         **     Internal Frames
         **    
         *********************************/
        //#### Character frame start ####
        characterFrame = new JInternalFrame("Character", true, true, false, false);
        characterFrame.setLocation(50, 50);
        characterFrame.setSize(300,105);

        totalExpProgressBar = new JProgressBar();
        totalExpProgressBar.setString("0/0");
        totalExpProgressBar.setStringPainted(true);

        characterFrame.add(totalExpProgressBar);
        characterFrame.setResizable(false);
        panel.add(characterFrame);
        //#### Character frame end ####

        /**********************************
         ** 
         **     Panel Code
         **    
         *********************************/
        panel.setLayout(null);
        panel.setFocusable(true);

        /**********************************
         ** 
         **     Frame Code
         **    
         *********************************/
        frame.setLocation(100, 100);
        frame.setSize(500, 350);
        frame.setVisible(true);
        frame.setFocusable(true);
        frame.addWindowListener(this);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    class ClassCharacterButton extends AbstractAction {  
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            if (characterFrame.isVisible()){
                characterFrame.setVisible(false);
            } else {
                fakeGetServerResponse();
            }
        }
    }

    public void fakeGetServerResponse(){
        String incommingReply = "proskier-charactersWindow@20|10|10|10|0|234|3|200|400"; //fake message from server
        final String splitAt[] = incommingReply.split("@"); //split the character name from the incommingReply at the '@' sign
        String beforeAt[] = splitAt[0].split("-");
        String commandName = beforeAt[1];
        final String afterAt[] = splitAt[1].split("\\|");

        if (commandName.equals("charactersWindow")){
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    totalExpProgressBar.setString(afterAt[5] + "/" + afterAt[8]);
                    totalExpProgressBar.setMinimum(0);
                    totalExpProgressBar.setMinimum(Integer.parseInt(afterAt[7])); //TODO::SCREW YOU JAVA
                    totalExpProgressBar.setValue(Integer.parseInt(afterAt[5]));   //TODO::SCREW YOU JAVA
                    totalExpProgressBar.setMaximum(Integer.parseInt(afterAt[8])); //TODO::SCREW YOU JAVA
                    characterFrame.setVisible(true);
                }
            });
        }
    }

    @Override
    public void windowClosing(WindowEvent arg0){
        frame.dispose();
        System.exit(1);
    }
    @Override
    public void windowActivated(WindowEvent arg0) {
    }
    @Override
    public void windowClosed(WindowEvent arg0) {
    }
    @Override
    public void windowDeactivated(WindowEvent arg0) {
    }
    @Override
    public void windowDeiconified(WindowEvent arg0) {           
    }
    @Override
    public void windowIconified(WindowEvent arg0) {
    }
    @Override
    public void windowOpened(WindowEvent arg0) {            
    }
}
  • 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-02T19:55:35+00:00Added an answer on June 2, 2026 at 7:55 pm

    The problem appears to be that you set the progress bar’s maximal value after setting its value, and that this will reset the value to the minimum value.

    import javax.swing.*;
    
    public class ProgressBarMinValue {
       private static void createAndShowGui() {
          JProgressBar progressBar = new JProgressBar();
    
          int value = 234;
          int denominator = 400;
          int minValue = 200;
          progressBar.setString(value + "/" + denominator);
          progressBar.setMinimum(minValue);
          System.out.println("value := " + value);
    
          progressBar.setValue(value);  // (A)
    
          progressBar.setMaximum(denominator);
    
          // progressBar.setValue(value);  // (B)
    
          JPanel mainPanel = new JPanel();
          mainPanel.add(progressBar);
    
          JOptionPane.showMessageDialog(null, mainPanel);
          System.out.println("progressBar.getValue() := " + progressBar.getValue());
       }
    
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                createAndShowGui();
             }
          });
       }
    }
    

    Swap commenting and uncommenting lines (A) and (B) and see that all works well if you set the progress bar’s value after setting its minimal and maximal value.

    And that’s your solution.

    Note that I obtained this minimal SSCCE by continuously whittling down your code until the problem could not be reproduced.

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

Sidebar

Related Questions

It is ok to set the max & min value for a UISlider control
Is there any easy way to find min/max value in the set of input
I have set my java min/max heap size to be the same as outlined
I tried to set the tick style to tsManual, the min and max position
Why I can't get the min-height of an object when its parent is set
I am trying to increase/decrease Max and Min value of Y axis in a
I have a masked textbox with the need to have a min/max length set
I use the following code to update my progressBar when using min and max
It's type attribute is set to string and it's min value = 0 and
right now I have min, max value from table1 that defines the range of

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.