Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I put a control in the JTableHeader of a JTable?
    primarykey
    data
    text
    <p>Given a <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/table.html" rel="nofollow noreferrer"><code>JTable</code></a> with a column of type <code>Boolean.class</code>, the <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editrender" rel="nofollow noreferrer"><em>default renderer</em></a> is a <code>JCheckBox</code>. It's easy enough to select individual cells based on a <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/table.html#selection" rel="nofollow noreferrer"><em>user selection</em></a>, but it may be convenient to select all or none of the check boxes, too. These <a href="https://stackoverflow.com/questions/7093213/jtableheader-with-jcheckbox-issue">recent</a> <a href="https://stackoverflow.com/questions/7092219/exception-in-thread-awt-eventqueue-0-java-lang-classcastexception-javax-swing">examples</a> mentioned using <code>JCheckBox</code> in the table header, but the implementation was awkward and unappealing. If I don't need to sort the column, how can I put a well-behaved control in the <a href="https://docs.oracle.com/javase/6/docs/api/javax/swing/table/JTableHeader.html" rel="nofollow noreferrer"><code>JTableHeader</code></a>?</p> <p>Addendum: For convenience, I've added my <a href="http://sscce.org/" rel="nofollow noreferrer">sscce</a> as an <a href="https://stackoverflow.com/questions/7137786/how-can-i-put-a-control-in-the-jtableheader-of-a-jtable/7137801#7137801">answer</a>, but I'd be pleased to accept an answer that addresses the <em>well-behaved</em> aspect of the problem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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