sportacus
12-07-2005, 08:27 AM
Hi Guys,
I have a JList that I want to double click and get the String that is currently selected.However, the .getSelectedValue.toString keeps returning null or -1 even when I have a String selected.
My code is as follows:
public void makeLstChatters(){
//make the listener for the JList
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
try{
System.out.println(lstChatters.getSelectedValue().toString());
String str = lstChatters.getSelectedValue().toString();
serv.whisper(str, txtAreaMessage.getText());
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
};
listModel = new DefaultListModel();
lstChatters = new JList(listModel);
JScrollPane scrollPane = new JScrollPane(lstChatters);
lstChatters.addMouseListener(mouseListener);
can anyone see where I am going wrong?
Thanks a million!!
I have a JList that I want to double click and get the String that is currently selected.However, the .getSelectedValue.toString keeps returning null or -1 even when I have a String selected.
My code is as follows:
public void makeLstChatters(){
//make the listener for the JList
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
try{
System.out.println(lstChatters.getSelectedValue().toString());
String str = lstChatters.getSelectedValue().toString();
serv.whisper(str, txtAreaMessage.getText());
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
};
listModel = new DefaultListModel();
lstChatters = new JList(listModel);
JScrollPane scrollPane = new JScrollPane(lstChatters);
lstChatters.addMouseListener(mouseListener);
can anyone see where I am going wrong?
Thanks a million!!