setCursor to JFrame doesn't work...

If we instantiate the JFrame and then

setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

or

setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));

doesn't work, which means cursor isn't changed.

However, on top of the subpane or panel or any container that attached,

to JFrame, getContentPane(), the cursor shows as if nothing happens.

Why?

If it is designated not to work for JFrame, why it has to be inherited setCursor() ?

[499 byte] By [PaulSheldonII_Screena] at [2007-10-3 8:54:47]
# 1
We don't see your cursor problem on JFrame.What is your Java version?
hiwaa at 2007-7-15 4:04:50 > top of Java-index,Desktop,Core GUI APIs...
# 2

Works fine for me as well using JDK1.4.2.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-15 4:04:50 > top of Java-index,Desktop,Core GUI APIs...
# 3
Yes, it is working for CROSSHAIR_CURSOR, but not HAND_CURSOR, or WAIT_CURSOR.I don't know why.I'm using jdk 5.0.
PaulSheldonII_Screena at 2007-7-15 4:04:50 > top of Java-index,Desktop,Core GUI APIs...
# 4
> Yes, it is working for CROSSHAIR_CURSOR, but > not HAND_CURSOR, or WAIT_CURSOR.> > I don't know why.> I'm using jdk 5.0.Then, I think you should take camickr's advice for small demo code.
hiwaa at 2007-7-15 4:04:50 > top of Java-index,Desktop,Core GUI APIs...
# 5

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.Cursor;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.io.IOException;

import javax.swing.JEditorPane;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JScrollPane;

import javax.swing.JTextField;

import javax.swing.event.HyperlinkEvent;

import javax.swing.event.HyperlinkListener;

public class ReadServerFile extends JFrame {

JTextField jTextField;

JEditorPane jEditorPane;

public ReadServerFile() {

Container container = getContentPane();

jTextField = new JTextField("Enter file URL here");

jTextField.addActionListener( new ActionListener() {

public void actionPerformed(ActionEvent e) {

// this is amazing discovery, getActionCommand

// get Keyboard function information

getThePage(e.getActionCommand());

}

});

container.add(jTextField, BorderLayout.NORTH);

jEditorPane = new JEditorPane();

jEditorPane.setEditable(false);

jEditorPane.addHyperlinkListener(new HyperlinkListener() {

public void hyperlinkUpdate(HyperlinkEvent e) {

if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {

getThePage(e.getURL().toString());

}

}

});

container.add(new JScrollPane(jEditorPane), BorderLayout.CENTER);

setSize(400, 300);

setVisible(true);

}

private void getThePage(String location) {

setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

try {

jEditorPane.setPage(location);

jTextField.setText(location);

} catch (IOException e) {

JOptionPane.showMessageDialog(this, "Error Retrieving specified URL",

"Bad URL", JOptionPane.ERROR_MESSAGE);

e.printStackTrace();

}

//this.setCursor( Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

ReadServerFile application = new ReadServerFile();

application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

This is the code. Several Times I changed it the part at getThePage() method. Try cut and paste. I don't need to see the Tag formatt for this.

PaulSheldonII_Screena at 2007-7-15 4:04:50 > top of Java-index,Desktop,Core GUI APIs...
# 6
It's just that JEditorPane override the cursor setting for supporting Web page hyperlink.I think it is a sound phenomenon.
hiwaa at 2007-7-15 4:04:50 > top of Java-index,Desktop,Core GUI APIs...
# 7

If you are trying to display a wait cursor while loading the page, then you should use a GlassPane and add the wait cursor to the glass pane. The glass pane covers the entire frame. Otherwise you don't know which component the cursor is placed over so the cursor will change value depending on the component.

camickra at 2007-7-15 4:04:50 > top of Java-index,Desktop,Core GUI APIs...
# 8
And beware that JEditorPane.setPage() behaves, as its default, asynchronously returning immediately before full page load be completed. Workaround is described in the API documentation of the class.
hiwaa at 2007-7-15 4:04:50 > top of Java-index,Desktop,Core GUI APIs...