次のコードの進行状況バーが更新されないのはなぜですか?どうすれば更新できますか?
import java.awt.event.{ActionListener, ActionEvent}
import javax.swing.table.{TableCellRenderer, AbstractTableModel}
import javax.swing.{Timer, JTable, JProgressBar, JFrame}
object TestProgressBar {
val frame = new JFrame()
val model = new TestModel()
val table = new JTable(model)
class TestModel extends AbstractTableModel {
def getColumnCount = 4
def getRowCount = 4
def getValueAt(y: Int, x: Int) = "%d,%d".format(x, y)
override def setValueAt(value: Any, row: Int, col: Int) {
if (col == 0) {
model.fireTableCellUpdated(row, col);
}
}
}
class TestCellRenderer extends TableCellRenderer with ActionListener {
val progressBar = new JProgressBar()
val timer = new Timer(100, this)
progressBar.setIndeterminate(true)
timer.start()
override def getTableCellRendererComponent(tbl: JTable, value: AnyRef,
isSelected: Boolean,
hasFocus: Boolean,
row: Int, column: Int) = {
progressBar
}
override def actionPerformed(e: ActionEvent) {
val model = table.getModel
for (row <- 0 to model.getRowCount) {
model.setValueAt(0, row, 0)
}
}
}
def main(args: Array[String]) {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
table.getColumnModel.getColumn(0).setCellRenderer(new TestCellRenderer())
frame.add(table)
frame.pack()
frame.setVisible(true)
}
}