问题
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.
来源:https://stackoverflow.com/questions/7907761/how-to-put-buttons-into-swing-table-in-scala