1

我正在使用TableModel具有伴随 custom 的自定义ColumnModel。下面是它所在面板的代码。

该表工作得很好,我可以毫无困难地添加和删除列,但标题永远不会显示。我将如何解决这个问题?

val panel = new BorderPanel() {
  var sourceLabel = new Label("No file chosen")
  layout(sourceLabel) = North

  var tableModel = new LogRecordTableModel
  var dataTable = new Table {
    model = tableModel
    peer.setColumnModel(tableModel.columnModel)
  }

  val scrollPane = new ScrollPane(dataTable)

  layout(scrollPane) = Center

  layout(controlStrip) = South

  openAction.setParent(this)
  listenTo(openAction)
  reactions += {
    case f:FileChosen =>
      tableModel.setSource(f.file)
      updateFile(f.file)
  }

  listenTo(previousAction)
  reactions += {
    case PREVIOUS =>
      tableModel.previous()
      updateButtons()
  }

  listenTo(nextAction)
  reactions += {
    case NEXT =>
      tableModel.next()
      updateButtons()
  }

  def updateFile(file: File) {
    sourceLabel = new Label(file.getName)
    layout(sourceLabel) = North
    Thread.sleep(100)
    updateButtons()

    revalidate()
    main.repaint()
  }

  def updateButtons() {
    nextButton.enabled = tableModel.hasNext
    previousButton.enabled = tableModel.hasPrevious
  }

  def updateTypeControl() {
    println("[$lessanonymous$greater.updateTypeControl] enter.")
    typeControl.selection.item(tableModel, typeValues.selection.item)
  }
}
4

1 回答 1

2

当您设置列模型摇摆下降标题并且需要重置时,请尝试以下操作:

var dataTable = new Table {
  model = tableModel
  peer.setColumnModel(tableModel.columnModel)

  for( i <- 0 until peer.getColumnCount) {
    peer.getColumnModel().getColumn(i).setHeaderValue(tableModel.getColumnName(i))
  }
}
于 2012-08-08T21:13:34.680 回答