swing - java - deactivate a listener -
i have general question regarding listeners.
lets have 2 jtabbedpane
s , both have changelistener
. both displayed , want them both show same pane (index) when user changes selected pane in 1 other changes too.
in brief, 1 jtabbedpane listener changes other jtabbedpane
using setselectedtab()
.
obviously, first listener activate second listener , second reactivate first in endless operation.
this solved booleans.
there smarter way it?
there way change tab without triggering listener?
there way activate listener when user changes , not code?
thank you.
btw: have same questions buttons. buttons take code listener , put in method. when 1 button needs activate button calls code. in jtabbedpane different.
the simple solution act when necessary. example:
if(currenttab != desiredtab) { // change tab }
that prevent infinite loop.
if need able switch behavior on , off, using boolean flag isn't bad way go it. alternative remove listener, using removechangelistener. flag may more performant may avoid memory allocation , deallocation, lot depends on other details of situation.
Comments
Post a Comment