Each JPanel does knows about its location, which you can get by using panel.getX()/getY(). Seems like what you asking for is this :
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PanelLocation extends JFrame implements MouseListener
{
private JPanel mainPanel, footerPanel;
private JPanel[] panel = new JPanel[9];
private JTextField tfield;
public PanelLocation()
{
mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(3, 3));
for (int i = 0; i < 9; i++)
{
panel[i] = new JPanel();
panel[i].addMouseListener(this);
panel[i].setBorder(BorderFactory.createLineBorder(Color.BLUE));
mainPanel.add(panel[i]);
}
footerPanel = new JPanel();
tfield = new JTextField(10);
footerPanel.add(tfield);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
add(mainPanel, BorderLayout.CENTER);
add(footerPanel, BorderLayout.PAGE_END);
pack();
setVisible(true);
}
private void getWhichButtonGotPressed(int x, int y)
{
if ((x == panel[0].getX()) && (y == panel[0].getY()))
{
panel[0].setBackground(Color.MAGENTA);
tfield.setText("You Clicked Panel : " + panel[0].getToolTipText());
}
else if ((x == panel[1].getX()) && (y == panel[1].getY()))
{
panel[1].setBackground(Color.YELLOW);
tfield.setText("You Clicked Panel : " + panel[1].getToolTipText());
}
else if ((x == panel[2].getX()) && (y == panel[2].getY()))
{
panel[2].setBackground(Color.RED);
tfield.setText("You Clicked Panel : " + panel[2].getToolTipText());
}
else if ((x == panel[3].getX()) && (y == panel[3].getY()))
{
panel[3].setBackground(Color.DARK_GRAY);
tfield.setText("You Clicked Panel : " + panel[3].getToolTipText());
}
else if ((x == panel[4].getX()) && (y == panel[4].getY()))
{
panel[4].setBackground(Color.ORANGE);
tfield.setText("You Clicked Panel : " + panel[4].getToolTipText());
}
else if ((x == panel[5].getX()) && (y == panel[5].getY()))
{
panel[5].setBackground(Color.PINK);
tfield.setText("You Clicked Panel : " + panel[5].getToolTipText());
}
else if ((x == panel[6].getX()) && (y == panel[6].getY()))
{
panel[6].setBackground(Color.BLUE);
tfield.setText("You Clicked Panel : " + panel[6].getToolTipText());
}
else if ((x == panel[7].getX()) && (y == panel[7].getY()))
{
panel[7].setBackground(Color.CYAN);
tfield.setText("You Clicked Panel : " + panel[7].getToolTipText());
}
else if ((x == panel[8].getX()) && (y == panel[8].getY()))
{
panel[8].setBackground(Color.GRAY);
tfield.setText("You Clicked Panel : " + panel[8].getToolTipText());
}
}
public void mouseClicked(MouseEvent ae)
{
JPanel panel = (JPanel) ae.getSource();
getWhichButtonGotPressed(panel.getX(), panel.getY());
}
public void mousePressed(MouseEvent ae)
{
}
public void mouseReleased(MouseEvent ae)
{
}
public void mouseEntered(MouseEvent ae)
{
}
public void mouseExited(MouseEvent ae)
{
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
new PanelLocation();
}
});
}
}
A sample program showing the Co-ordinates of the clicked panel. You just click the panel, the co-ordinates are passed to the function and that function will check which panel is clicked on, and returns the toopTipText for the said panel.
Here is the output of the program :

Hope this might help in some way.
Regards