表缺少标题

时间:2012-08-06 19:15:04

标签: scala swing

我正在使用具有随播广告TableModel的自定义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)
  }
}

1 个答案:

答案 0 :(得分:2)

设置列模型时,swing会丢弃标题并需要重置,请尝试尝试:

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

  for( i <- 0 until peer.getColumnCount) {
    peer.getColumnModel().getColumn(i).setHeaderValue(tableModel.getColumnName(i))
  }
}