title: Change/Display Cursor with Text
body: <p>I am currently trying to change the cursor shown on my <code>JFrame</code> to some text like "wait please your job is being done" while a certain <code>button</code> 's <code>actionPerformed()</code> method is executing. The only solution I have found as of yet is to change the <code>Cursor</code> with an <code>Image</code> which contains my desired Text. The code is below:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Cursor;
  import java.awt.Dimension;
  import java.awt.Graphics2D;
  import java.awt.Point;
  import java.awt.Toolkit;
  import java.awt.event.ActionEvent;
  import java.awt.geom.Ellipse2D;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  import java.nio.file.Paths;
  import javax.imageio.ImageIO;
  import javax.swing.AbstractAction;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  
  public class Hasikome extends JFrame{
  
  static Cursor cursor;
  
  private static final long serialVersionUID = 1L;
  
  public static void main(String[] args) {
  
          final Hasikome hasi = new Hasikome();
          hasi.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          hasi.setSize(new Dimension(1200, 1200));
          hasi.setPreferredSize(new Dimension(500, 500));
          Toolkit kit = Toolkit.getDefaultToolkit();
          Dimension dim = kit.getBestCursorSize(16, 16);
          BufferedImage buffered = null;
          try {
              buffered = ImageIO.read(new File(Paths.get("").toAbsolutePath().toString() + "\\belge.png"));
          } catch (IOException e) {
              e.printStackTrace();
          }
          java.awt.Shape circle = new Ellipse2D.Float(0, 0, dim.width - 1, dim.height - 1);
          Graphics2D g = buffered.createGraphics();
          g.setColor(Color.BLUE);
          g.draw(circle);
          g.setColor(Color.RED);
          hasi.add(new JButton(new AbstractAction() {
  
              private static final long serialVersionUID = 1L;
  
              @Override
              public void actionPerformed(ActionEvent e) {
                  hasi.setCursor(cursor);
                  try {
                      Thread.sleep(10000);
                  } catch (InterruptedException e1) {
                      e1.printStackTrace();
                  } finally {
                      hasi.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                  }
              }
          }), BorderLayout.NORTH);
          int centerX = (dim.width - 1) /2;
          int centerY = (dim.height - 1) / 2;
          g.drawLine(centerX, 0, centerX, dim.height - 1);
          g.drawLine(0, centerY, dim.height - 1, centerY);
          g.dispose();
          cursor = kit.createCustomCursor(buffered, new Point(centerX, centerY), "myCursor");
          hasi.pack();
          hasi.setVisible(true);
      }
  }
  </code></pre>
  
  <p>The problem with this code is <code>Dimension dim = kit.getBestCursorSize(16, 16);</code> this line always generates <code>Cursor</code> with size 32x32 on <code>Windows</code> and it is platform dependant. I can't use values more than 32x32 or else I get exception for the line <code>cursor = kit.createCustomCursor(buffered, new Point(centerX, centerY), "myCursor");</code> . And because I use a reasonably long text (250x16) it won't allow me to show the <code>text image</code> as <code>Cursor</code> properly.</p>
  
  <p>This solution not necessary, what I want to accomplish is to show text to users as <code>Cursor</code> while some <code>Button</code> 's <code>actionPerformed()</code> method is being executed. Is there any way I can do this? Thanks in advance.</p>