1

For Java the solution is here: How to add button in a row of JTable in Swing java (I need to put Buttons in given column, not a row).

When translating it into Scala I have the problem with setting new renderer for table column. There is no getter method for column and there is no getter method for column model. At least I don't see any: Table API.

I need something like this:

table.getColumn(...

or

table.getColumnModel(...

to inject my ButtonRenderer.

How to set a column with button with Swing table?

Update 1

Scala Swing Table has peer field which is Java JTable. I was able to set the renderer, but now there is another problem -- the renderer is not used.

Renderer

class ButtonRenderer extends javax.swing.JButton with  TableCellRenderer
{
  def getTableCellRendererComponent(table : javax.swing.JTable, 
                                   value : java.lang.Object,
                                   isSelected : Boolean, 
                                   hasFocus : Boolean, 
                                   row : Int, 
                                   column : Int) : java.awt.Component =
  {
    setText("it works");
    return this;
  }
}

setting the renderer

my_table.peer.getColumnModel().getColumn(3).setCellRenderer(new ButtonRenderer());

Update 2

It might be something wrong with Scala Swing, I rewrote the GUI part to Java Swing (in Scala) and buttons were inserted into table.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
greenoldman
  • 16,895
  • 26
  • 119
  • 185
  • 1
    And these endless little frustrations in interoperabilty are the reason why I cannot use Scala for any large project. Maybe Kotlin will be different. – Ingo Kegel Oct 28 '11 at 19:00
  • See this post. The one answer there looks promising. http://stackoverflow.com/questions/1195013/idiomatic-table-cell-renderers-in-scala – sullivan- Nov 03 '11 at 19:58

0 Answers0