爲什麼下面代碼中的進度條不更新,我將如何獲取它們?JTable中的JProgressBar不更新
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)
}
}
那麼是否有解決問題的方法? –
+1爲概念;它應該在Scala中工作。我認爲它只是需要一些東西來驅動它,例如(http://stackoverflow.com/a/10491290/230513)。 – trashgod