List of usage examples for javax.swing DefaultListSelectionModel DefaultListSelectionModel
DefaultListSelectionModel
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); JList list = new JList(new String[] { "one", "two", "three", "four" }); list.setSelectionModel(new DefaultListSelectionModel() { public void setSelectionInterval(int index0, int index1) { if (index0 == index1) { if (isSelectedIndex(index0)) { removeSelectionInterval(index0, index0); return; }/* w w w . j a v a 2s . c om*/ } super.setSelectionInterval(index0, index1); } @Override public void addSelectionInterval(int index0, int index1) { if (index0 == index1) { if (isSelectedIndex(index0)) { removeSelectionInterval(index0, index0); return; } super.addSelectionInterval(index0, index1); } } }); f.getContentPane().add(list); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { Object rows[][] = { { "one", "ichi" }, { "two", "ni" }, { "three", "san" }, { "four", "shi" }, { "five", "go" }, { "six", "roku" }, { "seven", "shichi" }, { "eight", "hachi" }, { "nine", "kyu" }, { "ten", "ju" } }; Object headers[] = { "English", "Japanese" }; String title = (args.length == 0 ? "JTable Sample" : args[0]); JFrame frame = new JFrame(title); TableColumnModel columnModel = new DefaultTableColumnModel(); TableColumn firstColumn = new TableColumn(1); firstColumn.setHeaderValue(headers[1]); columnModel.addColumn(firstColumn);//from w w w. j a v a 2 s .c o m TableColumn secondColumn = new TableColumn(0); secondColumn.setHeaderValue(headers[0]); columnModel.addColumn(secondColumn); ListSelectionModel selectionModel = new DefaultListSelectionModel(); selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // JTable table = new JTable(model, columnModel, selectionModel); JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TableColumnTester.java
public static void main(String args[]) { Object rows[][] = { { "one", "ichi" }, { "two", "ni" }, { "three", "san" }, { "four", "shi" }, { "five", "go" }, { "six", "roku" }, { "seven", "shichi" }, { "eight", "hachi" }, { "nine", "kyu" }, { "ten", "ju" } }; Object headers[] = { "English", "Japanese" }; String title = (args.length == 0 ? "JTable Sample" : args[0]); JFrame frame = new JFrame(title); TableModel model = new DefaultTableModel(rows, headers); TableColumnModel columnModel = new DefaultTableColumnModel(); TableColumn firstColumn = new TableColumn(1); firstColumn.setHeaderValue(headers[1]); columnModel.addColumn(firstColumn);/* w w w . jav a2 s . com*/ TableColumn secondColumn = new TableColumn(0); secondColumn.setHeaderValue(headers[0]); columnModel.addColumn(secondColumn); ListSelectionModel selectionModel = new DefaultListSelectionModel(); selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // JTable table = new JTable(model, columnModel, selectionModel); JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public Main() { setLayout(new BorderLayout()); list = new JList(label); JScrollPane pane = new JScrollPane(list); DefaultListSelectionModel m = new DefaultListSelectionModel(); list.setSelectionModel(m);/*w w w. j a v a2 s . co m*/ System.out.println(m.getLeadSelectionIndex()); add(pane, BorderLayout.NORTH); }
From source file:Main.java
public Main() { setLayout(new BorderLayout()); list = new JList(label); JScrollPane pane = new JScrollPane(list); DefaultListSelectionModel m = new DefaultListSelectionModel(); list.setSelectionModel(m);/*from www . j a v a 2 s .c om*/ System.out.println(m.getAnchorSelectionIndex()); add(pane, BorderLayout.NORTH); }
From source file:Main.java
public Main() { setLayout(new BorderLayout()); list = new JList(label); JScrollPane pane = new JScrollPane(list); DefaultListSelectionModel m = new DefaultListSelectionModel(); m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); m.setLeadAnchorNotificationEnabled(false); list.setSelectionModel(m);/*from ww w .j ava 2 s. c om*/ m.clearSelection(); add(pane, BorderLayout.NORTH); }
From source file:Main.java
public Main() { setLayout(new BorderLayout()); list = new JList(label); JScrollPane pane = new JScrollPane(list); DefaultListSelectionModel m = new DefaultListSelectionModel(); m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); m.setLeadAnchorNotificationEnabled(false); list.setSelectionModel(m);//from w w w . jav a2 s. c o m m.addSelectionInterval(1, 1); add(pane, BorderLayout.NORTH); }
From source file:Main.java
public Main() { setLayout(new BorderLayout()); list = new JList(label); JScrollPane pane = new JScrollPane(list); DefaultListSelectionModel m = new DefaultListSelectionModel(); m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); m.setLeadAnchorNotificationEnabled(false); list.setSelectionModel(m);//from w w w .j av a 2s. co m try { DefaultListSelectionModel mClone = (DefaultListSelectionModel) m.clone(); } catch (CloneNotSupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } add(pane, BorderLayout.NORTH); }
From source file:Main.java
public Main() { setLayout(new BorderLayout()); list = new JList(label); JScrollPane pane = new JScrollPane(list); DefaultListSelectionModel m = new DefaultListSelectionModel(); m.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { System.out.println(e.toString()); }/*ww w .j a v a 2s . c om*/ }); list.setSelectionModel(m); m.removeSelectionInterval(1, 1); add(pane, BorderLayout.NORTH); }
From source file:Main.java
public Main() { setLayout(new BorderLayout()); list = new JList(label); JScrollPane pane = new JScrollPane(list); DefaultListSelectionModel m = new DefaultListSelectionModel(); m.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { System.out.println(e.toString()); }/*from w ww . ja v a 2 s. c om*/ }); list.setSelectionModel(m); ListSelectionListener[] lis = m.getListSelectionListeners(); add(pane, BorderLayout.NORTH); }