java - How to determine if 2 components are on the same frame? (SWING) -


this question has answer here:

i go on , iterate on parents using getparent() on each until shared parent or null, looks bad solution, there better approach?

basiclly use case in focuslistener, on focuslost() want know if losing focus thats outside frame...

you can compare result of:

swingutilities.windowforcomponent(comp1).equals(swingutilities.windowforcomponent(comp2)) 

or

swingutilities.getwindowancestor(comp1).equals(swingutilities.getwindowancestor(comp2)) 

or

swingutilities.getroot(comp1).equals(swingutilities.getroot(comp2)) 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -