title: JLabel Overlapping
body: <p>I have created  a label with overriding its <code>paintComponent</code> (to paint it in a different format with an arc) and located them on a panel. Everything worked fine, however the labels which are located in same location (by <code>.setlocation</code>) are creating problems.</p>
  
  <p>Lets say I have 3 labels at the same location with different shapes. A-B-C
  A is first created, then B is created and lastly c is created.
  When I click on A, my function paints A and displays "youve clicked A"</p>
  
  <p>But when I click on B or C, it acts like i have clicked on A.</p>
  
  <p>(I'm adding labels in a panel stacked in scroll pane )</p>
  
  <p>Here is the code where i make labels</p>
  
  <pre><code>for(int i=0;i&lt;rowcount;i++){
          arcstart = Rawazimuth(azimuth[i]);
                      //custom JLabel to paint it like an arc
          MyLabel FLabel = new MyLabel(100, 50, (int)arcstart,cellid[i],lon[i],lat[i]);
          FLabel.setOpaque(true);
          Dimension LabelSize = new Dimension( 100,50);
          FLabel.setSize(LabelSize);
                      //locate the JLabel to labels location. it might be same or not
          FLabel.setLocation(lon[i], lat[i]);
  
          MyPanel.add(FLabel);    
  }
  </code></pre>
  
  <p>this is my custom jlabel class</p>
  
  <pre><code>public MyLabel(int W, int H, int start,int outcellid,int lonn, int latt) {
      addMouseListener(this);
      arcsizeW = W;
      arcsizeH = H;
      arcstart = start;
      cellid = outcellid;
      clicked = false;
      lon = lonn;
      lat = latt;
  }
  
  @Override
  public void paintComponent(Graphics g){
      // true if button is clicked, so paint acordingly
      if(clicked ==true){
         g.setColor(dummyg.getColor());  
     }else{
         g.setColor(Color.blue);
     }
    // draw the arc
     g.fillArc(0, 0,arcsizeW , arcsizeH, arcstart, 60);
  }
  
   //if cell is clicked, change its color to red and print its cellid
  @Override
  public void mouseClicked(MouseEvent e) {
  
      System.out.println(cellid);
  
       dummyg = this.getGraphics();
       dummyg.setColor(Color.red);
      this.paintComponent(dummyg);
      clicked = true;
  }// other listener stuff}
  </code></pre>
  
  <p>so how do i prevent this?
  i think i can use jlayerpane, but i will need at least 4 layers ( dunno if its ok ).</p>