Yhuu penso di aver risolto. Ecco il metodo repaint() nella sua nuova implementazione. La variabile frame è il riferimento al frame principale che contiene tutto.

codice:
public void repaint()
      {
    	 
    	  if (frame == null)
    	  {
    		  return;
    	  }
    	  
    	  // siamo vicino al bordo
    	  if ((this.getLocation().x + this.getBounds().width >= frame.getBounds().width - 20) 
    			  &&(this.getLocation().x + this.getBounds().width <= frame.getBounds().width +20))
    	  {
    		  
    		  // se siamo proprio sul bordo
    		  if(this.getLocation().x + this.getBounds().width == frame.getBounds().width)
    		  {
    			  super.repaint();
    			  frame.repaint();
    		  }
    		  else
    		  {
    			  this.setLocation( frame.getBounds().width - this.getBounds().width, this.getLocation().y);
    		  }
    		  
    	  } // non siamo vicini al bordo 
    	  else
    	  {
    		  super.repaint();
    		  frame.repaint();
    	  }

      }

Grazie a LeleFT