ListSelectionListener wrong index

时间:2015-05-08 10:01:02

标签: java eclipse swing jlist listselectionlistener

I just wanted to see which element is getting selected, and change other labels and texfields on the frame as per the index. My code is as follows:

- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController {
    return YES;
}

When I clicked first element output: [detailViewController.navigationController.navigationController popToRootViewControllerAnimated:YES] After clicking the second element: list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setLayoutOrientation(JList.VERTICAL); list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { System.out.println(e.getLastIndex()); } }); After that I tried to click first element again, but this time output was 0 0 again. When I tried with 25 elements, selecting last element and after that click first element and output is 1 1. Is it about event's problem or it's about my code?

0 个答案:

没有答案