ListSelectionModel: setLeadSelectionIndex(int index) : ListSelectionModel « javax.swing « Java by API






ListSelectionModel: setLeadSelectionIndex(int index)

  

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;

public class Main {
  static String labels[] = { "A", "B", "C", "D", "E", "F", "G" };

  public static void main(String args[]) {
    JFrame frame = new JFrame("Modifying Model");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist = new JList(new String[]{"A","B","C"});
    
    jlist.getSelectionModel().setAnchorSelectionIndex(0);   
    jlist.getSelectionModel().setLeadSelectionIndex(2);
    
    
    JScrollPane scrollPane1 = new JScrollPane(jlist);
    frame.add(scrollPane1, BorderLayout.CENTER);

    frame.setSize(640, 300);
    frame.setVisible(true);
  }
}

   
    
  








Related examples in the same category

1.ListSelectionModel.SINGLE_INTERVAL_SELECTION
2.ListSelectionModel.SINGLE_SELECTION
3.ListSelectionModel: getMaxSelectionIndex()
4.ListSelectionModel: getMinSelectionIndex()
5.ListSelectionModel: isSelectedIndex(int index)
6.ListSelectionModel: isSelectionEmpty()
7.ListSelectionModel: setAnchorSelectionIndex(int index)