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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:06:21+00:00 2026-05-29T20:06:21+00:00

I have implemented a JProgressBar in a JTable. I used renderer for the ProgressBar

  • 0

I have implemented a JProgressBar in a JTable.
I used renderer for the ProgressBar NOT EDITOR.

Now I tried to implement a ProgressBar set value but due to EDT its not working so I used SwingUtilties but it did not work as well.

EXPECTED BEHAVIOUR – The JProgressBar must be setting value to 80 ,
currently it is showing only 0%

public class SkillSetTableProgressBarRenderer extends JProgressBar implements
        TableCellRenderer {

    public SkillSetTableProgressBarRenderer() {
        super(0, 100);
        super.setPreferredSize(new Dimension(100, 80));
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {

        final JProgressBar bar = (JProgressBar) value;

        if (bar.getString().equals("JAVA") || bar.getString().equals("SWING"))
            super.setString("Mellow");
        else
            super.setString("GOOD");

        setOpaque(true);
        table.setOpaque(true);

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                System.err.println("MAIN ANDER");
                setValue(80);
                bar.setValue(80);
            }
        });

        super.setStringPainted(true);
        super.setIndeterminate(true);
        super.setPreferredSize(new Dimension(140, 16));
        if (isSelected) {
            super.setBackground(table.getSelectionBackground());
            super.setForeground(table.getSelectionForeground());
            // this.setBackground(table.getSelectionBackground());
        } else {
            super.setForeground(table.getForeground());
            super.setBackground(Color.WHITE);
        }

        return this;
    }

}
  • 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-29T20:06:22+00:00Added an answer on May 29, 2026 at 8:06 pm

    1) even is possible, don’t create JComponents inside TableCellRenderer, nor re_create Object, Renderer is only for formatting cell contents

    2) use SwingWorker for moving with progress in JProgressBar (if you have real important reasons, then use Runnable#Tread)

    example about Runnable#Tread

    enter image description here

    import java.awt.Component;
    import java.util.Random;
    import javax.swing.JFrame;
    import javax.swing.JProgressBar;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.SwingUtilities;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellRenderer;
    
    public class TableWithProgressBars {
    
        public static class ProgressRenderer extends JProgressBar implements TableCellRenderer {
    
            private static final long serialVersionUID = 1L;
    
            public ProgressRenderer(int min, int max) {
                super(min, max);
                this.setStringPainted(true);
            }
    
            @Override
            public Component getTableCellRendererComponent(JTable table, Object value,
                    boolean isSelected, boolean hasFocus, int row, int column) {
                this.setValue((Integer) value);
                return this;
            }
        }
        private static final int maximum = 100;
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new TableWithProgressBars().createGUI();
                }
            });
    
        }
    
        public void createGUI() {
            final JFrame frame = new JFrame("Progressing");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Integer[] oneRow = {0, 0, 0, 0};
            String[] headers = {"One", "Two", "Three", "Four"};
            Integer[][] data = {oneRow, oneRow, oneRow, oneRow, oneRow,};
            final DefaultTableModel model = new DefaultTableModel(data, headers);
            final JTable table = new JTable(model);
            table.setDefaultRenderer(Object.class, new ProgressRenderer(0, maximum));
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            frame.add(new JScrollPane(table));
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            new Thread(new Runnable() {
    
                @Override
                public void run() {
                    Object waiter = new Object();
                    synchronized (waiter) {
                        int rows = model.getRowCount();
                        int columns = model.getColumnCount();
                        Random random = new Random(System.currentTimeMillis());
                        boolean done = false;
                        while (!done) {
                            int row = random.nextInt(rows);
                            int column = random.nextInt(columns);
                            Integer value = (Integer) model.getValueAt(row, column);
                            value++;
                            if (value <= maximum) {
                                model.setValueAt(value, row, column);
                                try {
                                    waiter.wait(15);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            }
                            done = true;
                            for (row = 0; row < rows; row++) {
                                for (column = 0; column < columns; column++) {
                                    if (!model.getValueAt(row, column).equals(maximum)) {
                                        done = false;
                                        break;
                                    }
                                }
                                if (!done) {
                                    break;
                                }
                            }
                        }
                        frame.setTitle("All work done");
                    }
                }
            }).start();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to implement the ProgressBar in my application that gets displayed when
I have implemented authentication systems for webapps several times over the years, but before
I have to implement a progressbar that show the progress of a report generation,
I have implemented a custom movie player with AVPlayer . On setting the value
I'm trying to implement basic communication through sockets, what I have now is: server
I have implemented what I thought was a pretty decent representation of MVC in
I have implemented a simple file upload-download mechanism. When a user clicks a file
I have implemented a python webserver. Each http request spawns a new thread. I
I have implemented a SAX parser in Java by extending the default handler. The
I have implemented VirtualPathProvider class so I can keep all my views in 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.