I have A Jpanel with A GridLayout inside. Now I added another Jpanel inside of there which draws a circle with PaintComponent. I’m now trying to get the ComponentCount() of the panel but it fails :s this is my code for mouse tracking :
public void mousePressed(MouseEvent me) {
int click_x = me.getX();
int click_y = me.getY();
int col = click_x/100;
int row = click_y/100;
System.out.println("select_C:"+col+" select_Y:"+row);
System.out.println("COMPONENT COUNT:"+positionPanels[col][row].getComponentCount());
}
it’s okay, but when I click a container ( JPANEL with gridlayout(1,1) ) that actually contains another component (JPANEL) it returns ZERO as components count. please see screenshot for further details,…
clicking the red circle returned zero … see System.out outputs… on screenshot, hope you guys can help me.
thanks

A red circle painted in a JPanel is not a component. You would have to add a JLabel (with a red circle as icon, for example) to the JPanel to have it contain a component.
If you actually added some component to the JPanel, then it probably means that the positionPanel is the inner component and not the containing component. Without seeing the code, it’s impossible to say.