Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did some experiments and also read the documentation <a href="http://docs.oracle.com/javase/6/docs/api/javax/swing/JTable.html#setCellSelectionEnabled%28boolean%29" rel="nofollow">here</a>. It says the <code>setCellSelectionEnabled()</code> method:</p> <p>Sets whether this table allows both a column selection and a row selection to exist simultaneously. <em>When set, the table treats the intersection of the row and column selection models as the selected cells.</em></p> <p>I added two lines of code for the debugging purpose immediately before <code>showDemo()</code> to see what the selected rows and columns are after adding the rows interval:</p> <pre><code>public static void main(String[] args) { JTable table = new JTable(10, 10); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setCellSelectionEnabled(true); table.addRowSelectionInterval(6, 7); // Select 2 lines // Let's see what rows and columns have been selected System.out.println("Rows: " + Arrays.toString(table.getSelectedRows())); System.out.print("Columns: " + Arrays.toString(table.getSelectedColumns())); showDemo(new JScrollPane(table), "Select a block and some rows"); } </code></pre> <p>and I got this output:</p> <pre><code>Rows: [6, 7] Columns: [] </code></pre> <p>which explains why <code>addRowSelectionInterval</code> doesn't work as you expected. It's easy to add the missing part:</p> <pre><code> ... table.addRowSelectionInterval(6, 7); // Select 2 lines table.addColumnSelectionInterval(0, 9); // and Select ** ALL** the columns ... </code></pre> <p>Similar justification could be made for the other observation.</p>
    singulars
    1. This table or related slice is empty.
    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. 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