Well i got a problem guys and request your help. I added in my own kind of JPopupMenu to allow changing calculation methods, but now my whole application is slowen down significantly and I narrowed it down to this classes i made :
class PopUpTimeCalcMethodChangeClickListener extends MouseAdapter {
PopUpMenuTimeCalcMethodChange menu;
public void mousePressed(MouseEvent e){
if (e.isPopupTrigger())
doPop(e);
}
public void mouseReleased(MouseEvent e){
if (e.isPopupTrigger())
doPop(e);
}
private void doPop(MouseEvent e){
if(menu == null)
menu = new PopUpMenuTimeCalcMethodChange();
menu.show(e.getComponent(), 0, 0);
}
}
class PopUpMenuTimeCalcMethodChange extends JPopupMenu {
public PopUpMenuTimeCalcMethodChange(){
final String[] calctyps = {"Calculate by last download","Calculate by average speed"};
for(int i = 0;i<calctyps.length;i++){
final JCheckBox setCalcMethod = new JCheckBox(calctyps[i]);
setCalcMethod.setIconTextGap(15);
if(Main.TimeLeftCalculationMode == i)
setCalcMethod.setSelected(true);
setCalcMethod.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
for(Component c : getmenu().getComponents()){
if(c.getClass() == JCheckBox.class){
((JCheckBox) c).setSelected(false);
}
}
setCalcMethod.setSelected(true);
System.out.println("lol we are running");
int index = -1;
for (int i=0;i<calctyps.length;i++) {
if (calctyps[i].equals(setCalcMethod.getText())) {
index = i;
break;
}
}
Main.TimeLeftCalculationMode = index;
}
});
add(setCalcMethod);
}
}
public JPopupMenu getmenu(){
return this;
}
}
the main problem is that the code is slowing down the ui after its first execution even though its not visible anymore.I assume its something about the actionlisteners but im not sure.