0

我有一个城市列表。当您单击一个城市时,它会显示该城市的当前时间、日期等

但是,它仅在我双击城市时才会更新我将如何将其更改为单击

谢谢

 @Override
public void itemStateChanged(ItemEvent e)
{
    Set<String> countries = regionMap.get(listRegion.getSelectedItem());
    listSubRegion.removeAll();
    for(String country : countries)
    {
        listSubRegion.add(country);
    }

    selectedRegion = listRegion.getSelectedItem();

    listSubRegion.validate();
    listSubRegion.repaint();

    repaint();
}
4

1 回答 1

0

尝试这个:

list.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
        if (mouseEvent.getClickCount() == 1) {
            // single click
            int index = theList.locationToIndex(mouseEvent.getPoint());
            if (index >= 0) {
                Object o = theList.getModel().getElementAt(index);
                ... do something ...            
            }
        }
    }
});
于 2013-05-21T12:49:32.377 回答