JTable...how to know if a row is selected?!?

Hi!!I need to know if a row is selected and if is true wich row is it!can you help me?!?thanks allbyeRP
[152 byte] By [jrbpinto] at [2007-9-26 4:13:15]
# 1
int row = m_Table.getSelectedRow();if(row == -1) // no tow has been selectedelse //do something with row
shobhana at 2007-6-29 13:19:49 > top of Java-index,Archived Forums,Swing...
# 2

thank's for your help!!

that's true but the problem is that the application check if some row is selected after the creation...so nothing is selected!!

I need an event to check the selection when a mouse click come.

if can help me again...

very thanks!!

bye

Jrbpinto

jrbpinto at 2007-6-29 13:19:49 > top of Java-index,Archived Forums,Swing...
# 3

this is my code...i've no compilation problems and the result is quite ok.

the problem is that components in JPanel dx are not shown!!! only when i put mouse-cursor out of the window this components are shown!!

this is what i don't understand!!!!!

CODE:

jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

ListSelectionModel rowSM = jtable.getSelectionModel();

rowSM.addListSelectionListener(new ListSelectionListener() {

public void valueChanged(ListSelectionEvent e) {

//Ignoro messaggi extra

if (e.getValueIsAdjusting()) return;

ListSelectionModel lsm = (ListSelectionModel)e.getSource();

if (lsm.isSelectionEmpty()) {

int i=1; //non fare niente non c' selezione

} else {

int selectedRow = lsm.getMinSelectionIndex();

dx.removeAll();

JTextField CurrentMac= new JTextField();

Machine current = new Machine(selectedRow+1,c);

ResMsg res = Machine.GetResMsg();

switch(res.GetResult()){

case 5:

CurrentMac.setText("\n I/O ERROR: check your connection!");

dx.add(CurrentMac);

break;

default:

dx.removeAll();

if (res.GetMsg() != null) {

if (res.GetMsg().getType() == GIMsg.GIMACSTSR) {

MacStsRMsg rMsgM = (MacStsRMsg) res.GetMsg();

int cmds = rMsgM.getItems();

CurrentMac.setBorder(null);

CurrentMac.setEditable(false);

CurrentMac.setSelectionColor(new java.awt.Color (250, 250, 220));

CurrentMac.setBackground(new java.awt.Color (250, 250, 220));

CurrentMac.setForeground(new java.awt.Color (0, 0, 255));

CurrentMac.setText("MACHINE ID: " + rMsgM.getMId());

dx.add(CurrentMac);

JCheckBox[] check = new JCheckBox[cmds];

for (int j = 0; j < cmds; j++) {

check[j] = new JCheckBox(rMsgM.getCIdAt(j) + ": " + rMsgM.getCNameAt(j));

dx.add(check[j]);

}

}

else{

CurrentMac.setText("ERROR: Wrong response");

dx.add(CurrentMac);

}

}

else{

CurrentMac.setText("ERROR: Connection error");

dx.add(CurrentMac);

}

break;

}

}

}

});

bye & thank's

JRBPinto

jrbpinto at 2007-6-29 13:19:49 > top of Java-index,Archived Forums,Swing...