JTable Default Selection Problem!!

hi all,

i m creating one small appplication in which i have to display select content of JTable.

i create one defaulttable model and give refrence in JTable

and get selected item from ListSelectionModel.

bt i m facing one problem it gives me default value means when no Row is selected it give 1st Row as selected so how to solve this problem.....

i m giving u code to show me my mistake......

tab.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

if (ALLOW_ROW_SELECTION==false)

{// true by default

ListSelectionModel rowSM = tab.getSelectionModel();

rowSM.addListSelectionListener(new ListSelectionListener()

{

publicvoid valueChanged(ListSelectionEvent e)

{

//Ignore extra messages.

if (e.getValueIsAdjusting())return;

lsm = (ListSelectionModel)e.getSource();

if (lsm.isSelectionEmpty()){

JOptionPane.showMessageDialog(con,"SELECT CERTIFICATE!!!");

}else{

selectedRow = lsm.getMinSelectionIndex();

}

}

});

}else{

tab.setRowSelectionAllowed(false);

}

[1902 byte] By [javarocktheworlda] at [2007-11-27 8:30:11]
# 1

Try to clear the selection before giving control to the user:

rowSM.clearSelection();

Also, are you sure nothing is selected in the table?

You use ListSelectionModel.SINGLE_SELECTION so one element is always selected.

Try to change it to SINGLE_INTERVAL_SELECTION or MULTIPLE_INTERVAL_SELECTION, this should allow you to specify a empty range of selected rows i.e. no row selected.

Under Windows, to unselect a selected item you must hold Ctrl and click on the item.

Message was edited by: java_knight

java_knighta at 2007-7-12 20:20:43 > top of Java-index,Desktop,Core GUI APIs...