Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to put Buttons into Swing Table in Scala?
    text
    copied!<p>For Java the solution is here: <a href="https://stackoverflow.com/questions/1475543/how-to-add-button-in-a-row-of-jtable-in-swing-java">How to add button in a row of JTable in Swing java</a> (I need to put Buttons in given column, not a row).</p> <p>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: <a href="http://www.scala-lang.org/api/current/scala/swing/Table.html" rel="nofollow noreferrer">Table API</a>.</p> <p>I need something like this:</p> <pre><code>table.getColumn(... </code></pre> <p>or</p> <pre><code>table.getColumnModel(... </code></pre> <p>to inject my ButtonRenderer.</p> <p><strong>How to set a column with button with Swing table?</strong></p> <h2>Update 1</h2> <p>Scala Swing Table has <strong>peer</strong> field which is Java JTable. I was able to set the renderer, but now there is another problem -- the renderer is not used.</p> <p><strong>Renderer</strong></p> <pre><code>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; } } </code></pre> <p><strong>setting the renderer</strong></p> <pre><code>my_table.peer.getColumnModel().getColumn(3).setCellRenderer(new ButtonRenderer()); </code></pre> <h2>Update 2</h2> <p>It might be something wrong with Scala Swing, I rewrote the GUI part to Java Swing (in Scala) and buttons were inserted into table. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload