One component overlaps another and is not removed in Java?

When you press the button, a JScrollpane with the elements list under the input field, after user selection, it is removed from the root panel, which was added. But he remains visible on the next panel, and will disappear only after the componentResized() , the part of the code.
ListUsers JList =new JList(lm);
 listUsers.setLayout(new BoxLayout(listUsers,BoxLayout.Y_AXIS)); 
listUsers.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

 JScrollPane scrl =new JScrollPane(listUsers,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER
);
 listUsers.addListSelectionListener(new ListSelectionListener(){

 public void valueChanged(ListSelectionEvent ev){
if(listUsers.getSelectedValue()!=null){

 usersTF.setText((listUsers.getSelectedValue()).toString()); 
}

frame.remove(scrl);

listUsers.removeListSelectionListener(this);
btnConnect.enable(true);
revalidate();

repaint();
}
 }); 
frame.add(scrl);
scrl.setBounds(usersTF.getBounds().x
 usersTF.getHeight()+4,usersTF.getWidth(), 76);

listUsers.setBounds(usersTF.getBounds().x
 usersTF.getHeight()+4,usersTF.getWidth()-2, 76);

Disappear and not Usenet litter.
5a6ab7cb4f2d8812937670.png
June 8th 19 at 20:24
0 answer

Find more questions by tags JavaSwing