Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that the <code>JButton</code> no longer exists when painted in the table. Those components are only used to create a 'stamp' when the table is rendered. There is no actual button present.</p> <p>There is a way to allow you to click on the button, and <em>still keep your table non-editable</em>, but it is far from proper code. Just a quick outline for a possible solution (I do not have the time at this moment to give a full code example)</p> <ul> <li>attach a mouse listener to the table</li> <li>when you receive a mouse click, determine the cell in which the mouse click occurred</li> <li>ask the table renderer for the component for that cell</li> <li>use the location of the mouse click to determine whether a button is present in the component from the previous step at that particular location</li> <li>if so, do the click through the button api (the <code>doClick</code> method)</li> </ul> <p>And this is not even the dirty part of the code. Since your renderer (hopefully) does not return a new <code>JButton</code> each time, you should in your <code>ActionListener</code> which is attached to the <code>JButton</code> keep track of for which component the click actually occurred. A possible solution is to keep a reference to the table model value for which you the last time created a <code>JButton</code> (so in the <code>getCellRendererComponent</code> method keep track of the row/column), but I am unsure whether this is the best approach.</p> <p>As said, a possible solution but far from elegant.</p> <p>The easiest way is to just make that one column editable and use an editor, as pointed out in other answers</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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