How to put Buttons into Swing Table in Scala?

巧了我就是萌 提交于 2019-12-13 18:10:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!