1

I'm using a custom TableModel that has a companion custom ColumnModel. Below is the code for the panel that it is on.

The table works great and I can add and remove columns without any trouble but the headers are never displayed. How would I fix that?

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)
  }
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Donald.McLean
  • 869
  • 12
  • 18

1 Answers1

2

When you set the column model swing drops the header and it needs to be reset, give this a try:

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

  for( i <- 0 until peer.getColumnCount) {
    peer.getColumnModel().getColumn(i).setHeaderValue(tableModel.getColumnName(i))
  }
}
andy
  • 1,695
  • 1
  • 9
  • 7