swing - java - deactivate a listener -


i have general question regarding listeners.

lets have 2 jtabbedpanes , 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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -