user3430220
user3430220

Reputation: 31

Why two internal frame is creating in my java code?

I am trying to learn how to use java swing components. I have been trying to build up something like a pop up window.Like facebook when we select a friend a window pops up.I have a list of friends. I wish to create a pop up window when the user selects one of his friend from his friend list.But the problem is , each time I run this code, two internal frames are popping up.I fail to sort out the problem.Here is the code snippet. Thanks in advance.

private void list2ValueChanged(javax.swing.event.ListSelectionEvent evt) {

    JInternalFrame f = new JInternalFrame((String)list2.getSelectedValue(), 
            false,true,false,true);  
    f.setSize(150,150);
    f.setVisible(true);
    desk.add(f,BorderLayout.SOUTH);

} 

Here desk is the variable name for JDesktopPane.

Upvotes: 1

Views: 67

Answers (1)

camickr
camickr

Reputation: 324137

A ListSelectionListener will generate multiple events every time the selection changes.

You need to check the ListSelectionEvent.getValueIsAdjusting() to make sure the selection is finished adjusting

if (!event.getValueIsAdjusting())
    // create your internal frame.

Upvotes: 1

Related Questions