Reputation: 93448
I have a specific requirement that all children of a particular JComponent have double buffering turned off. I can recurse through it easily enough and disable them when needed, but I'd like to detect the addition of new children components regardless of their position in the hierarchy and disable it then.
I've taken a look at addHierarchyChangeListener but it seems to only detect changes in parents, not children.
Can someone point me down the right path?
Upvotes: 3
Views: 934
Reputation: 24801
I think you need a RecursiveContainerListener that could execute a common operation whenever any component added or removed in a given parent component. Please find the code for it here(RecursiveContainerListener.java). It does exactly what you want. All you need is to change/override handleAdd and handleRemove methods to turn of double buffering.
And finally you simply add it to your parent:
parentComponent.add(new RecursiveContainerListener());
No need to explicitly add listener to each child :)
Upvotes: 1