Skip to content

JTable multiple selection on Mac OS X

I have a Swing application and we are having a problem with some Mac users and JTable components.

The tables have this selection mode set:


On Windows with this selected you can:

  1. select a single row
  2. select contiguous rows by holding the mouse and dragging
  3. select contiguous rows by clicking the first row to select, pressing shift and clicking the end row to select
  4. Select multiple groups of contiguous rows by clicking a row and drag and then holding ctrl and doing it again from a different row
  5. You can hold Ctrl down and individually select rows that are Not contiguous

On Mac OS you can only do 1 and 2. I don’t care about 3 and 4, but I really need them to be able to select random rows that are not contiguous.

This is a picture of the selection behavior described in #5 which doesn’t work on Mac: non-contiguous JTable selection

I generated this on windows using the standard JTable simple demo. You can’t do so on Mac. You can on linux. Here is the link to that demo:

Is this a known problem or is there a solution known?



The Windows Ctrl key is closer in function to Mac’s Command key, not the Control key, despite Java recognizing Win’s Ctrl key & Mac’s Control key as having the same KeyEvent#getKeyCode() value of 17.

Selecting non-contiguous rows worked for me by holding down the Command key, not Control. Tested on a MacBook Air with an M1 chip running MacOS Monterey 12.0.1, using Azul Zulu’s Build of the OpenJDK version 17.0.2.

3 People found this is helpful