1
2 package info.mikethomas.fahview.v6project.utilities;
3
4 import java.awt.Component;
5 import javax.swing.JProgressBar;
6 import javax.swing.JTable;
7 import javax.swing.table.TableCellRenderer;
8
9
10
11
12
13
14
15
16
17 public class ProgressCellRenderer extends JProgressBar
18 implements TableCellRenderer {
19
20
21
22
23 public ProgressCellRenderer() {
24 super(0, 100);
25 setValue(0);
26 setString("0%");
27 setStringPainted(true);
28 }
29
30
31 @Override
32 public Component getTableCellRendererComponent(
33 JTable table,
34 Object value,
35 boolean isSelected,
36 boolean hasFocus,
37 int row,
38 int column) {
39
40
41 final String sValue = value.toString();
42 int index = sValue.indexOf('%');
43 if (index != -1) {
44 int p = 0;
45 try {
46 p = Integer.parseInt(sValue.substring(0, index));
47 }
48 catch (NumberFormatException e) {
49 }
50 setValue(p);
51 setString(sValue);
52 }
53 return this;
54 }
55 }