Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: GUI freezes instead of showing JProgressBar

  1. #1
    Junior Member
    Join Date
    Dec 2021
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default GUI freezes instead of showing JProgressBar

    https://i.ibb.co/SJPQQvb/progress.png

    This is what I see, but I shoulw see somthing like this:
    https://i.ibb.co/YQh2J87/progress.png

    this is my code

      JFrame frame = new JFrame();
        JProgressBar barra;
        HOME home;
        int massimo;
        Thread thread = null;
     
        public BARRA_PROGRESSO(int minimo, int m, HOME h) {
            massimo = m;
            home = h;
     
            /*   BigDecimal risultato = minimo .divide(dividi);
    Integer.parseInt(new DecimalFormat("#")).format(risultato + "");*/
            barra = new JProgressBar(0, m);
     
            frame.add(barra);
            barra.setBackground(Color.WHITE);
            barra.setStringPainted(true);
            barra.setFont(new java.awt.Font("Tahoma", 1, 30)); // NOI18N
            barra.setBounds(0, 0, 500, 100);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(500, 200);
            frame.setLayout(null);
            frame.setVisible(true);
            //   barra.setForeground(new java.awt.Color(45, 60, 128));
            thread = new Thread(new Runnable() {
                public void run() {
                    sistema_percentuale_();
                }
            });
     
            thread.start();
     
        }
     
        public void sistema_percentuale_() {
     
            while (true) {
                try {
                    Thread.sleep(10);
                    BigDecimal boh = home.conta_barra.divide(home.dividi_progress_bar);
     
                    System.out.println(
                            boh.multiply(new BigDecimal("100")).divide(new BigDecimal(massimo + ""), RoundingMode.HALF_DOWN) + "%");
     
                    barra.setValue(Integer.parseInt(new DecimalFormat("#").format(boh)));
                } catch (Exception e) {
                    System.out.println("BARRA_PROGRESSO.sistema_percentuale_()" + e);
                }
            }
     
        }
     
    }
    Last edited by ciliegia; January 28th, 2022 at 11:39 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: GUI freezes instead of showing JProgressBar

    The posted code does not compile for testing because of missing import statements.
    Also there is no main method for starting execution.
    Please correct the code.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2021
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GUI freezes instead of showing JProgressBar

    Thank you I'll keep it in mind for the next time. Any help? thanks

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: GUI freezes instead of showing JProgressBar

    I can't help if I can not compile and execute the code for testing.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2021
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GUI freezes instead of showing JProgressBar

    Why can't you?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: GUI freezes instead of showing JProgressBar

    I get these compiler errors:
    Running: C:\Program Files\Java\jdk1.8.0_60\bin\javac.exe -cp .;D:\JavaDevelopment -Xlint -Xdiags:verbose BARRA_PROGRESSO.java

    BARRA_PROGRESSO.java:10: error: cannot find symbol
    JFrame frame = new JFrame();
    ^
    symbol: class JFrame
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:11: error: cannot find symbol
    JProgressBar barra;
    ^
    symbol: class JProgressBar
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:12: error: cannot find symbol
    HOME home;
    ^
    symbol: class HOME
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:15: error: cannot find symbol
    public BARRA_PROGRESSO(int minimo, int m, HOME h) {
    ^
    symbol: class HOME
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:10: error: cannot find symbol
    JFrame frame = new JFrame();
    ^
    symbol: class JFrame
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:21: error: cannot find symbol
    barra = new JProgressBar(0, m);
    ^
    symbol: class JProgressBar
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:24: error: cannot find symbol
    barra.setBackground(Color.WHITE);
    ^
    symbol: variable Color
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:28: error: cannot find symbol
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    ^
    symbol: variable JFrame
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:48: error: cannot find symbol
    BigDecimal boh = home.conta_barra.divide(home.dividi_progress_bar);
    ^
    symbol: class BigDecimal
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:51: error: cannot find symbol
    boh.multiply(new BigDecimal("100")).divide(new BigDecimal(massimo + ""), RoundingMode.HALF_DOWN) + "%");
    ^
    symbol: class BigDecimal
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:51: error: cannot find symbol
    boh.multiply(new BigDecimal("100")).divide(new BigDecimal(massimo + ""), RoundingMode.HALF_DOWN) + "%");
    ^
    symbol: variable RoundingMode
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:51: error: cannot find symbol
    boh.multiply(new BigDecimal("100")).divide(new BigDecimal(massimo + ""), RoundingMode.HALF_DOWN) + "%");
    ^
    symbol: class BigDecimal
    location: class BARRA_PROGRESSO
    BARRA_PROGRESSO.java:53: error: cannot find symbol
    barra.setValue(Integer.parseInt(new DecimalFormat("#").format(boh)));
    ^
    symbol: class DecimalFormat
    location: class BARRA_PROGRESSO
    13 errors

    13 error(s)
    Also there is no main method.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2021
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GUI freezes instead of showing JProgressBar

    Quote Originally Posted by Norm View Post
    I get these compiler errors:

    Also there is no main method.
    What is that you don't understand? You have to copy and paste the code in NetBeans /eclipse/etc... in a class and then call it in the main class...

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: GUI freezes instead of showing JProgressBar

    Sorry, I do not use an IDE that does that. I need the full code that compiles and executes for testing. I don't want to have to add anything to the code. The code needs to be complete and ready to compile. For example the Home class is missing.

    If you want help, I suggest you provide complete code. Do not expect me to write any code.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Jul 2019
    Posts
    36
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Thumbs down Re: GUI freezes instead of showing JProgressBar

    The graphic of code that you posted correctly displays a progressbar, albeit in an infinite loop.
    The problem may be how calculate or get value of boh variable, and if there is correct increment of numbers.
    Last edited by zemiak; January 31st, 2022 at 07:43 PM.

Similar Threads

  1. JFrame Freezes
    By RedXVIII in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 22nd, 2013, 05:14 AM
  2. JProgressBar
    By Tyluur in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 25th, 2013, 06:59 AM
  3. BufferedReader - Freezes on 2nd read
    By mds1256 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 14th, 2011, 03:26 PM
  4. JSP freezes after AJAX call !!
    By java_freek in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: April 16th, 2010, 10:31 AM
  5. Replies: 1
    Last Post: February 16th, 2009, 11:52 AM

Tags for this Thread