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() ?
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.