0

I'm developing a desktop application which consists of overlapping jpanels. Those jpanels are transparent and include some jbuttons. What I want my application to do is to redispatch mouse events to below jpanels if user clicks buttonless areas. However, I could not get which jpanels below those jpanels. java.awt.container class has getComponentAt(int x, int y) method but it gives only component at top. javax.swing.SwingUtilities class has getDeepestComponentAt(Component parent, int x, int y) method but it gives only the deepest. Those methods do not meet my needs. Is it possible to implement methods like JComponent getComponentAt(int x, int y, int z-order) or JComponent[] getComponentsAt(int x, int y). Only possible solution I found is using getComponents() to get all components and checking their locations with their z-orders. However, I will have too many components in the application and this way is cpu consuming. Is it possible to access jpanels in a better way?

Note: Could not add image to support the question, since my reputation is not high enough sorry for that.

user
  • 43
  • 5
  • why do you need things to be transparent+overlapping? doesn't that cause all kinds of other unintended possibilities like overlapping controls? – John Gardner Feb 05 '14 at 19:30
  • Take a look at [this answer](http://stackoverflow.com/questions/21449502/passing-the-click-event-on-one-jpanel-to-another-jpanel/21468973#21468973) – MadProgrammer Feb 05 '14 at 19:41
  • And [this answer](http://stackoverflow.com/questions/16074116/getcomponentat-not-finding-a-component/16074336#16074336) – MadProgrammer Feb 05 '14 at 19:50
  • MadProgrammer, I have looked at your answers before but I could not find what I looked for. JohnGardner, Do not know much about overlapping controls. I searched on internet about what you mean. As far as I understand this happens because of jbuttons. Actually I will not use Jbuttons instead I will use some graphical objects on panels. My main question could I get component at location with z-order? I want to use swing to not reinvent the wheel. However, If this is not possible with swing i will not use it instead I will do all the things with java graphics. – user Feb 05 '14 at 20:07

0 Answers0