0
我有這樣的代碼:修改此類渲染,將進度條的大小更改爲變量?
TableColumn column = jTable2.getColumnModel().getColumn(1);
column.setCellRenderer(new ProgressRenderer());
類ProgressRenderer:
class ProgressRenderer extends DefaultTableCellRenderer {
private final JProgressBar b = new JProgressBar(0, 100);// I NEED RECEIVE DE VALUE, //LIKE THIS new JProgressBar(0, MAX);
private final JPanel p = new JPanel(new BorderLayout());
public ProgressRenderer() {
super();
setOpaque(true);
b.setStringPainted(true);
p.add(b);
//p.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Integer i = (Integer) value;
String text = "Finalizou o Lote";
if (i < 0) {
text = "Pausa";
} else if (i < 100) {
b.setValue(i);
return p;
}
super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);
return this;
}
@Override
public void updateUI() {
super.updateUI();
if (p != null) {
SwingUtilities.updateComponentTreeUI(p);
}
}
}
現在,我需要,當ProgressRenderer
通話功能()difine一個參數,它是最大的進度條,但我可以不做,有什麼想法?
像這樣:
TableColumn column = jTable2.getColumnModel().getColumn(1);
column.setCellRenderer(new ProgressRenderer(MAX));
類ProgressRenderer()
class ProgressRenderer extends DefaultTableCellRenderer {
private final JProgressBar b = new JProgressBar(0, MAX);// I NEED RECEIVE DE VALUE, //LIKE THIS new JProgressBar(0, MAX);
private final JPanel p = new JPanel(new BorderLayout());
public ProgressRenderer() {
super();
setOpaque(true);
...
...
----編輯---------- 謝謝你,但現在我有大問題,因爲這個:
TableColumn column = jTable2.getColumnModel() GetColumn (1).;
column.setCellRenderer (new ProgressRenderer (maxValue));//
//我怎麼知道什麼時候加t他反對改變包括maxValue
我在JTable中
private LinhasOnline getLinha() {
LinhasOnline linha = new LinhasOnline();
linha.setNome("Linha "+j);
linha.setcont(j*(10));
linha.setmax(100);
j++;
return linha;
}
private void addLinha() {
getModel().addLinha(getLinha());//
}
//我getmodel
private LinhasOnlineTableModel getModel() {
if (model == null) {
model = (LinhasOnlineTableModel) getTblLinhasOnline().getModel();
}
return model;
}
//我getTblLinhasOnline使用插入值這個代碼()
private JTable getTblLinhasOnline() {
if (jTable2 == null) {
jTable2 = new JTable();
jTable2.setModel(new LinhasOnlineTableModel());
TableColumn column = jTable2.getColumnModel().getColumn(1);
column.setCellRenderer(new ProgressRenderer(max)); // need put the value of object(setmax)
}
return jTable2;
}
謝謝,但現在有其他問題,請參閱我的編輯評論,抱歉,因爲必須編碼,但對我來說很難解釋。如果你需要更好的解釋讓我知道:) – user3419041
對不起,現在沒有足夠的時間,試着編輯我的帖子後。 – alex2410
好的,謝謝 – user3419041