JProgressBar Cell Renderer

(4 votes, average: 5.00 out of 5)
 Loading ...

The code below is a TableCellRenderer that shows a JProgressBar that can be used as a cell renderer in a JTable cell.

If you check the overridden getTableCellRendererComponent() method, the value should be a percentage value so that the JProgressBar can adjust its visual status according to the percentage.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class JProgressBarTableCellLabelRenderer implements TableCellRenderer  {
 
    private JProgressBar jpb;
 
    public JProgressBarTableCellLabelRenderer(){
        jpb = new JProgressBar();
        jpb.setMinimum(0);
        jpb.setValue(1);
        jpb.setMaximum(100);
 
    }
 
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if (value != null) {
            int v = Integer.parseInt(value.toString());
            jpb.setValue(v);
        }
        return jpb;
    }
}

Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.

Related Posts with Thumbnails