Nested GUI elements do not respond to listeners?

I have a very stupid question/problem:

  • I have several gui classes; they have buttons, tables you name it.
  • When I add such an object to the main app window, they function properly
  • When I add them to other objects (i.e. I nest classes) they don’t react to GUI events

What am I overlooking or missing? Any clue? (I’m thinking this should be really obvious …)

Maybe the Component bounds overlap in a way that doesn’t let the events through to them. (They could still be visible if there are transparent component areas involved.) But if it isn’t about that, can you show how your code is structured?

The components shouldn’t overlap - but let me double check that - thx for the inspiration!

If your main app window the (button) listener, are you adding it correctly in the constructors of your gui classes as a listener?

WFIW I still have not been able to figure out what’s up with this (too busy coding other parts of the application). I don’t have the listeners in the main app class - the listener is in the constructor of the component of the class where the button is in. Let’s call that class A, and class A has buttons and listeners to those buttons. If I add the A class component to the application base component everything works as expected. When I add the component as a child to another component of say class B, which is in turn a child of the main app, the button in A no longer react to listener events. Very strange.

Without seeing code, we can just guess:

  • you verified, that the components are actually active (visible) and react to normal mouseEvents (possible check: override mouseDown())
  • If that doesn’t happen: did you change hitTest()? does that return true?
  • If the events are happening, is there something that recreates the buttons? Happened recently to me… this will obviously delete your events with it
  • Is there more than one layer of components? (was suggested before)

Which component is created under what component shouldn’t matter. It matters, if the components are visible, the events are tested front to back, and each children list last to first (making the last sibling the front most).

Good luck

Thx. As said I’ve parked this issue because of too much work on other parts of the code. Not at my desk right now but some aswers to your questions:

  • components (buttons, drawn boxes, labels) are visible. Buttons do not visually react to clicking them when component is layered within another one.
  • hitTest not changed
  • buttons not recreated - but I’ll triplecheck that, tx for the hint.
  • multiple layers of components indeed. If I place the problematic component in the main app component it works fine. If I put it within some other component (so multiple layers) my botton component reacts to nothing.

When I get back to that part of the code I’ll post putline of that code.

All comments so far are appreciated!

Just adding one note, if you have Components, that you don’t want to interact with / don’t care, you can set setInterceptMouseClicks (false, false). Then mouse events will just go through them to the ones behind…

Tx @daniel that’s a great tip for debugging my issue. I’ll report back when solved (or when out of inspiration where/how to look).

Found what happened; pretty elementary a series of (button) components that didn’t have a proper size. When testing in main component I place the object containing the buttons at (0,0) - within a child component they’d have a different location an screwed up. Shoulda known better.