-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressCellRenderer.java
42 lines (34 loc) · 1.01 KB
/
ProgressCellRenderer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.awt.Component;
import javax.swing.JProgressBar;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
public class ProgressCellRenderer extends JProgressBar
implements TableCellRenderer {
/**
* Creates a JProgressBar with the range 0,100.
*/
public ProgressCellRenderer(int max) {
super(0, max);
setValue(0);
setString("0%");
setStringPainted(true);
}
public Component getTableCellRendererComponent(
JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
int p = 0;
try {
p = Integer.parseInt(value.toString());
} catch (NumberFormatException e) {
}
setValue(p);
double calc = (float) p / (float) super.getMaximum();
String toOutput = String.valueOf(String.format("%.1f", calc*100));
setString(toOutput + " %");
return this;
}
}