title: Paint Component seems to be causing cursor and Mouse Listener of Label to not work
body: <p>Using <code>LayerUI</code> to add labels to the upper corner of a tabbed pane.  Would like to allow these labels to display as hyperlinks, so I  set the color blue, the cursor to a hand and I added a <code>mouselistener</code>.  </p>
  
  <p>Howev,er when I paint the component the cursor customization and mouse listener are not not working.</p>
  
  <p>sample image    </p>
  
  <p><a href="https://i.stack.imgur.com/Fp7HF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fp7HF.png" alt="enter image description here"></a></p>
  
  <p>Sample Application:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Cursor;
  import java.awt.Dimension;
  import java.awt.EventQueue;
  import java.awt.Graphics;
  import java.awt.event.MouseAdapter;
  import java.awt.event.MouseEvent;
  import javax.swing.BorderFactory;
  import javax.swing.JComponent;
  import javax.swing.JDialog;
  import javax.swing.JLabel;
  import javax.swing.JLayer;
  import javax.swing.JPanel;
  import javax.swing.JTabbedPane;
  import javax.swing.SwingUtilities;
  import javax.swing.plaf.LayerUI;
  
  public class TopRightCornerLabelLayerUITest {
      public static JPanel makeUI() {
          JPanel resultPanel = new JPanel();
          resultPanel.setLayout( new BorderLayout());
          resultPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
          JTabbedPane tabbedPane = new JTabbedPane();
          tabbedPane.add("Tab 1", new JPanel());  
          tabbedPane.add("Tab 2", new JPanel());  
  
          resultPanel.add(new JLayer&lt;JComponent&gt;(tabbedPane, new TopRightCornerLabelLayerUI()), BorderLayout.CENTER);
  
          return resultPanel;
      }
  
      private static void initandShow()
      {
          JDialog dialog = new JDialog();
          dialog.getContentPane().add(makeUI());
          dialog.setSize(520, 240);
          dialog.setLocationRelativeTo(null);
          dialog.setVisible(true);
      }
  
      public static void main(String[] args) {
          EventQueue.invokeLater(new Runnable() {
              @Override
              public void run() {
                  initandShow();
              }
          });
  
      }
  }
  
  class TopRightCornerLabelLayerUI extends LayerUI&lt;JComponent&gt; {
      private JPanel rubberStamp = new JPanel();
  
      @Override public void paint(Graphics g, JComponent c) {
          super.paint(g, c);
  
          JLabel layoutHyperlink = new JLabel("&lt;html&gt;&lt;a href=''&gt;File Layout and Descriptions&lt;/a&gt;&lt;/html&gt;");
          JLabel templateHyperlink = new JLabel("&lt;html&gt;&lt;a href=''&gt;Download Template&lt;/a&gt;&lt;/html&gt;");
  
          layoutHyperlink.setForeground(Color.BLUE.darker());
          layoutHyperlink.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          layoutHyperlink.addMouseListener(new MouseAdapter() {
              @Override
              public void mouseClicked(MouseEvent e) {
                  // the user clicks on the label
                  System.err.println("clicked");
              }
         });
  
          templateHyperlink.setForeground(Color.BLUE.darker());
          templateHyperlink.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          templateHyperlink.addMouseListener(new MouseAdapter() {
              @Override
              public void mouseClicked(MouseEvent e) {
                  // the user clicks on the label
                  System.err.println("clicked");
  
              }
         });
  
          // Add components
          Dimension templateDimension = templateHyperlink.getPreferredSize();
          int x = c.getWidth() - templateDimension.width - 5;
          SwingUtilities.paintComponent(g, templateHyperlink, rubberStamp, x, 2, templateDimension.width , templateDimension.height);
  
          Dimension layoutDimension = layoutHyperlink.getPreferredSize();
          x = c.getWidth() - layoutDimension.width - 15 - templateDimension.width;
          SwingUtilities.paintComponent(g, layoutHyperlink, rubberStamp, x, 2, layoutDimension.width, templateDimension.height);
  
      }
  }
  </code></pre>