So my problem is is that only certain regions of some components are clickable. I have these 3 classes:
TDUsersPanel
-- https://github.com/cats-/TD/blob/master/src/cats/td/gui/game/TDUsersPanel.javaTDSavedUsersPanel
-- https://github.com/cats-/TD/blob/master/src/cats/td/gui/game/TDSavedUsersPanel.javaTDRegisterPanel
-- https://github.com/cats-/TD/blob/master/src/cats/td/gui/game/TDRegisterPanel.java
And here is an image of what all that looks like together:
But as you can tell, there are pink regions (I added inside the pink) and the pink regions indicate where the component is clickable. For example, if you look at the register button, you could notice that there a pink region on the top part of the button, and this means that you could only click the buttons within the bounds of the pink region. And you could also see a pink region of the list, on the far right side, indicating that it only acts the way it's supposed to act if you click it within the bounds of the pink region.
And my question is, why does it act this way? I want it to act just like any other component, and I am really curious to why it only reacts properly from those certain regions. I have considered the possibility that there might be some component overlap, but after drawing borders around every single component, there definitely isn't any overlap.
If anyone could help me with my problem and tell me any possible solutions, it would be greatly appreciated, thanks.
If you have any other questions, feel free to ask.
Edit: I've made somewhat of a tiny discovery; I tried adding a mouse listener to the button and print out the bounds of the button, and the location of where I am clicking. Then I added a simple if statement stating that if the bounds of the button contains the point at which I'm clicking, print out a statement such as:
System.out.println(registerButton.getBounds());
System.out.println(e.getPoint());
System.out.println(registerButton.getBounds().contains(e.getPoint()));
Here is a sample output:
java.awt.Rectangle[x=1,y=115,width=498,height=42]
java.awt.Point[x=383,y=47]
false
And as you could see, there is no output statement saying that it is in bounds. And this is strange though because this mouse listener is added to only the register button, so it will only trigger if you click within the register button. But this is very strange though because if you compare the y values from looking at the bounds of the register button and the point at which your clicking at, they're very different. The y value range for which you could click in for the button is 115 to 157. But the y value that it says the mouse location is at 57, and of course 57 < 115. So there is no overlap problem, there is just an offset problem it seems. Does anybody know how to fix this?
Note: I think i just noticed something; I added a mouse listener to the register panel ONLY and just the register panel, and I clicked the top left corner of the register panel (expecting it to be 0,0) but when it printed out the point, it was (3,30) so that means theres a offset, and due to this offset, the mouse thinks its somewhere where it isn't, causing only the top region to be clickable. But now that I know the problem, I have no idea how to fix this. Any ideas would be greatly appreciated.