本文整理匯總了Java中javax.swing.DefaultListSelectionModel.clearSelection方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultListSelectionModel.clearSelection方法的具體用法?Java DefaultListSelectionModel.clearSelection怎麽用?Java DefaultListSelectionModel.clearSelection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.DefaultListSelectionModel
的用法示例。
在下文中一共展示了DefaultListSelectionModel.clearSelection方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testEventsONLeadAnchorAfterClearSelection
import javax.swing.DefaultListSelectionModel; //導入方法依賴的package包/類
/**
* sanity: understand DefaultListSelectionModel behaviour.
*
* Is it allowed that event.getFirstIndex < 0? This happens in
* table.clearLeadAnchor
*
*/
public void testEventsONLeadAnchorAfterClearSelection() {
DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
int selected = 5;
selectionModel.setSelectionInterval(selected, selected);
assertEquals(selected, selectionModel.getAnchorSelectionIndex());
assertEquals(selected, selectionModel.getLeadSelectionIndex());
// selectionModel.setLeadAnchorNotificationEnabled(false);
ListSelectionReport report = new ListSelectionReport();
selectionModel.addListSelectionListener(report);
// following lines are copied from table.clearLeadAnchor()
// selectionModel.setValueIsAdjusting(true);
selectionModel.clearSelection();
assertEquals(1, report.getEventCount());
assertTrue(report.getLastEvent(false).getFirstIndex() >= 0);
report.clear();
selectionModel.setAnchorSelectionIndex(-1);
assertEquals(1, report.getEventCount());
assertTrue(report.getLastEvent(false).getFirstIndex() >= 0);
report.clear();
selectionModel.setLeadSelectionIndex(-1);
assertEquals(1, report.getEventCount());
assertTrue(report.getLastEvent(false).getFirstIndex() >= 0);
report.clear();
}
示例2: testEventONLeadAnchorAfterClearSelection
import javax.swing.DefaultListSelectionModel; //導入方法依賴的package包/類
/**
* sanity: understand DefaultListSelectionModel behaviour.
*
* Is it allowed that event.getFirstIndex < 0? This happens in
* table.clearLeadAnchor
*
*/
public void testEventONLeadAnchorAfterClearSelection() {
DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
int selected = 5;
selectionModel.setSelectionInterval(selected, selected);
assertEquals(selected, selectionModel.getAnchorSelectionIndex());
assertEquals(selected, selectionModel.getLeadSelectionIndex());
selectionModel.setLeadAnchorNotificationEnabled(false);
ListSelectionReport report = new ListSelectionReport();
selectionModel.addListSelectionListener(report);
// following lines are copied from table.clearLeadAnchor()
selectionModel.setValueIsAdjusting(true);
selectionModel.clearSelection();
selectionModel.setAnchorSelectionIndex(-1);
selectionModel.setLeadSelectionIndex(-1);
assertEquals("", 0, report.getEventCount(true));
selectionModel.setValueIsAdjusting(false);
ListSelectionEvent event = report.getLastEvent(true);
assertEquals(5, event.getFirstIndex());
}
示例3: jButtonMoveUpActionPerformed
import javax.swing.DefaultListSelectionModel; //導入方法依賴的package包/類
private void jButtonMoveUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMoveUpActionPerformed
if (jTable1.getSelectedRow() > 0) {
DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();
int[] indices = jTable1.getSelectedRows();
for (int i=indices.length-1; i>=0; --i) {
if (indices[i] == 0) continue;
Object val = jTable1.getValueAt( indices[i], 0);
dtm.removeRow(indices[i]);
dtm.insertRow(indices[i]-1, new Object[5] );
setRowValues( (JRMeterInterval)val, indices[i]-1);
indices[i]--;
}
DefaultListSelectionModel dlsm = (DefaultListSelectionModel)jTable1.getSelectionModel();
dlsm.setValueIsAdjusting(true);
dlsm.clearSelection();
for (int i=0; i<indices.length; ++i) {
dlsm.addSelectionInterval(indices[i], indices[i]);
}
dlsm.setValueIsAdjusting( false );
}
}
示例4: jButtonMoveDownActionPerformed
import javax.swing.DefaultListSelectionModel; //導入方法依賴的package包/類
private void jButtonMoveDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMoveDownActionPerformed
if (jTable1.getSelectedRowCount() > 0) {
DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();
int[] indices = jTable1.getSelectedRows();
for (int i=indices.length-1; i>=0; --i) {
if (indices[i] >= (jTable1.getRowCount() -1)) continue;
Object val = jTable1.getValueAt( indices[i], 0);
dtm.removeRow(indices[i]);
dtm.insertRow(indices[i]+1, new Object[5] );
setRowValues( (JRMeterInterval)val, indices[i]+1);
indices[i]++;
}
DefaultListSelectionModel dlsm = (DefaultListSelectionModel)jTable1.getSelectionModel();
dlsm.setValueIsAdjusting(true);
dlsm.clearSelection();
for (int i=0; i<indices.length; ++i) {
dlsm.addSelectionInterval(indices[i], indices[i]);
}
dlsm.setValueIsAdjusting( false );
}
}