Why is the valueChanged method of my listSelectionListener not firing when an item is selected in my JBList?

public class MainPanel extends JPanel {

private PathTextField pathTextField = new PathTextField(20, this);
private JBList fileList = new JBList(new DefaultListModel());
private Project project;

public MainPanel(Project project) {
super();

this.project = project;

Set<KeyStroke> forwardKeys = new HashSet<KeyStroke>(1);
forwardKeys.add(KeyStroke.getKeyStroke(
KeyEvent.VK_TAB, InputEvent.CTRL_MASK));
Set<KeyStroke> backwardKeys = new HashSet<KeyStroke>(1);
backwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_SHIFT, InputEvent.CTRL_MASK));
setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardKeys);
setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardKeys);

fileList.addListSelectionListener(new ListSelectionListener() {

@Override
public void valueChanged(ListSelectionEvent e) {
System.out.println("Value changed");
String selectedFile = fileList.getSelectedValue().toString();
System.out.println("Selected file " + selectedFile);
VirtualFile destination = LocalFileSystem.getInstance().findFileByPath(pathTextField.getText()
+ selectedFile);
if(destination.isDirectory()) {
pathTextField.setText(destination.getPath());
}
else {
OpenFileDescriptor ofd = new OpenFileDescriptor(project, destination);
ofd.navigate(false);
}
}
});

this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
this.setPreferredSize(new Dimension(500,500));
this.add(pathTextField);
this.add(fileList);
}


}




The problem is pretty simple: the valueChanged method never happens when I click on an item in the list.

Here is the whole project: https://github.com/adammfrank/find-file

2 comments
Comment actions Permalink

Hi Adam,

The valueChanged method always happens when I click on an item in the list. It works even if I add traversal keys.

What is your version of IDEA? and JDK? and OS?

 

 

0
Comment actions Permalink

IDEA 14.1.4, JDK 8, Ubuntu 14.  I added a link to the project's repo.

0

Please sign in to leave a comment.