java swing jdialog joptionpane custom-cursor

java - Cursor personalizado en un JDialog Swing



joptionpane custom-cursor (2)

Tengo una aplicación Java Swing, desarrollada en Mac OS X 10.5 con Java 1.5.

Intento que aparezca un cursor personalizado cuando el usuario mueve el mouse sobre un texto en un cuadro de diálogo. El cursor nunca cambia, sin embargo.

Cuando no utilizo un JFrame en lugar de un JDialog, el cursor cambia. Pero luego tendré que escribir todo el código de diálogo yo mismo.

¿Cómo puedo hacer que aparezca el cursor?

Este es el código más simple que pude crear para demostrar el problema:

import javax.swing.*; import java.awt.*; public class CursorTest { public static void main(String[] args) { JLabel label = new JLabel("Move mouse here for hand cursor"); label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); JOptionPane pane = new JOptionPane(label); pane.setOptions(new Object[]{"OK"}); JDialog dialog = pane.createDialog(null, "Test Dialog"); dialog.setVisible(true); } }


Gracias PhiLho, ese informe de errores de Sun me dio la solución. El propietario (cuadro principal) debe ser no nulo y mostrar. Para el registro, aquí hay una versión modificada de mi código de ejemplo que muestra un cursor de mano.

import javax.swing.*; import java.awt.*; public class CursorTest { public static void main(String[] args) { JLabel label = new JLabel("Move mouse here for hand cursor"); label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); JOptionPane pane = new JOptionPane(label); pane.setOptions(new Object[]{"OK"}); JFrame parent = new JFrame(); parent.setVisible(true); JDialog dialog = pane.createDialog(parent, "Test Dialog"); dialog.setModal(false); dialog.setVisible(true); } }


Parece que es un error en Java 1.5: primero probé con Java 1.6.0_07 y funcionó como se esperaba (en Windows XP). Luego volví a compilar con Java 1.5.0_06 y, de hecho, el cursor permanece en el estado predeterminado.

Conociendo las dificultades de Java 1.6 en MacOS, veo que será difícil arreglar eso ...

ID de error: 5079694 JDialog no respeta setCursor
Dan una solución alternativa ...

[EDITAR] Solución provisional probada:

public class CursorTest extends JFrame { private CursorTest() { } private void ShowDialog() { JLabel label = new JLabel("Move mouse here for hand cursor"); label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); JOptionPane pane = new JOptionPane(label); pane.setOptions(new Object[] { "OK" } ); JDialog dialog = pane.createDialog(this, "Test Dialog"); dialog.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { CursorTest testFrame = new CursorTest(); testFrame.setTitle("Test GUI"); testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); testFrame.setSize(500, 300); testFrame.setVisible(true); testFrame.ShowDialog(); } }); } }

Funciona bien con mi sistema JDK.