Reputation: 289
I am trying to populate a JList through a button, and then populate the JTextField using DoubleClick on the previously populated Jlist.
Code:
private void extractUsedVariablesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(arguments.size() > 0)
JOptionPane.showMessageDialog(null, "Please complete the predicates before accessing this");
DefaultListModel lista1 = new DefaultListModel();
for (int i = 0;i<variableList.size();i++)
{
if (!lista1.contains(variableList.get(i)))
{
lista1.addElement(variableList.get(i));
}
}
argVariables_List.setModel(lista1);
revalidate();
repaint();
if (lista1.size()>0){
System.out.println("got here1");
MouseListener mouseListener2 = new MouseAdapter()
{
public void mouseClicked1(MouseEvent mouseEvent2)
{
JList varList = (JList) mouseEvent2.getSource();
if (mouseEvent2.getClickCount() == 2)
{
System.out.println("may be");
int index varList.locationToIndex(mouseEvent2.getPoint());
if (index >= 0)
{
Object o2 = varList.getModel().getElementAt(index);
System.out.println(o2.toString());
}
}
}
};
argVariables_List.addMouseListener(mouseListener2);
}
}
It is working fine till populating the Jlist. But when I try the doubleclick operation and print the text at the clicked index I am not getting any output neither any errors. Please suggest me if I am missing something.
Upvotes: 0
Views: 59
Reputation: 324157
public void mouseClicked1(MouseEvent mouseEvent2)
There is no such method in the MouseListener interface. (note the "1").
Make sure you include @Override
in the line above the method and you will get a compiler error when you make a typo.
@Override
public void mouseClicked1(MouseEvent mouseEvent2)
Upvotes: 2