Setting the Selection Mode of a JList Component

// The default mode is MULTIPLE_INTERVAL_SELECTION String[] items = {"A", "B", "C", "D"}; JList list = new JList(items); // Get the current selection model mode int mode = list.getSelectionMode(); // MULTIPLE_INTERVAL_SELECTION // Only one item can be selected list.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); // The selected items must be in a contiguous range list.setSelectionMode(DefaultListSelectionModel.SINGLE_INTERVAL_SELECTION); // Multiple ranges of selected items are allowed list.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.