List of usage examples for com.jgoodies.binding.list SelectionInList clearSelection
public void clearSelection()
From source file:com.songbook.pc.ui.view.MainFormView.java
License:Open Source License
private static void bind2Way(final JTable jTable, final SelectionInList<?> selectionInListModel) { // Set single row selection jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Bind TABLE => SelectionInList jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override/*from w w w. ja va2 s . c om*/ public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int viewIndex = jTable.getSelectedRow(); if (viewIndex >= 0) { int modelIndex = jTable.convertRowIndexToModel(viewIndex); selectionInListModel.setSelectionIndex(modelIndex); } else { selectionInListModel.clearSelection(); } } } }); // Bind SelectionInList => Table selectionInListModel.getSelectionIndexHolder().addValueChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { Integer modelIndex = (Integer) evt.getNewValue(); if (modelIndex > 0) { int rowIndex = jTable.convertRowIndexToView(modelIndex); jTable.getSelectionModel().setSelectionInterval(rowIndex, rowIndex); } else { jTable.clearSelection(); } } }); }