-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
8u161
-
x86
-
os_x
FULL PRODUCT VERSION :
1.8.0_161, also seen with 1.9.0.4.11
ADDITIONAL OS VERSION INFORMATION :
Mac OS 10.12, also seen with earlier versions
A DESCRIPTION OF THE PROBLEM :
When the cursor is changed to a custom cursor and moved outside the window, then moved back inside the window, it often (but not always) does not change back to the custom cursor.
Note - the image files for the custom cursors are needed to run the test code. I don't know how to attach them to this bug report. I put copies on dropbox, link is
https://www.dropbox.com/sh/stq7a4j5uso916s/AAC-f6itTgoYs69BclK9Sfkma?dl=0
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code
Click on one of the custom cursor boxes (paintbrush or eyedropper)
Cursor changes when moved outside the selection box
Move cursor outside the window, cursor changes to pointer
Move cursor back inside the window, cursor stays pointer most of the time, sometimes correctly changes back to the custom cursor.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Cursor should always change back to the custom cursor
ACTUAL -
Cursor often stays pointer
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;
public class test extends JFrame {
public static final Cursor pointerCursor = Cursor.getDefaultCursor();
public static final Cursor handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
public static final Cursor textCursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
private static final String kEyedropperCursorName = "eyedropper.png";
public static final Image eyedropperCursorImage = getImage(kEyedropperCursorName);
public static final Point eyedropperHotspot = new Point(2,15);
public static final Cursor eyedropperCursor =
makeCustomCursor(eyedropperCursorImage, eyedropperHotspot, kEyedropperCursorName);
private static final String kPaintbrushCursorName = "paintbrush.png";
public static final Image paintbrushCursorImage = getImage(kPaintbrushCursorName);
public static final Point paintbrushHotspot = new Point(2,15);
public static final Cursor paintbrushCursor =
makeCustomCursor(paintbrushCursorImage, paintbrushHotspot, kPaintbrushCursorName);
private cursorChooser currentCursorChooser;
public test() {
super("Test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setSize(400, 400);
cursorChooser pointerCC = new cursorChooser(this, pointerCursor, "Pointer");
cursorChooser handCC = new cursorChooser(this, handCursor, "Hand");
cursorChooser textCC = new cursorChooser(this, textCursor, "Text");
cursorChooser eyedropperCC = new cursorChooser(this, eyedropperCursor, "Eyedropper");
cursorChooser paintbrushCC = new cursorChooser(this, paintbrushCursor, "Paintbrush");
int x = 5;
int y = 5;
pointerCC.setLocation(x, y);
y += cursorChooser.kChooserHeight - 1;
handCC.setLocation(x, y);
y += cursorChooser.kChooserHeight - 1;
textCC.setLocation(x, y);
y += cursorChooser.kChooserHeight - 1;
eyedropperCC.setLocation(x, y);
y += cursorChooser.kChooserHeight - 1;
paintbrushCC.setLocation(x, y);
add(pointerCC);
add(handCC);
add(textCC);
add(eyedropperCC);
add(paintbrushCC);
currentCursorChooser = pointerCC;
selectCursor(currentCursorChooser);
setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@SuppressWarnings("unused")
public void run() {
new test();
}
});
}
public void selectCursor(cursorChooser cc) {
setCursor(cc.crsr);
currentCursorChooser.setSelected(false);
currentCursorChooser = cc;
currentCursorChooser.setSelected(true);
repaint();
}
public static Cursor makeCustomCursor(Image image, Point hotSpot, String name) {
Cursor c = Toolkit.getDefaultToolkit().createCustomCursor(image, hotSpot, name);
return c;
}
public static Image getImage(String name) {
String fName = "images/" + name;
File f = new File(fName);
if (! f.exists())
JOptionPane.showMessageDialog(null,
"File not found: " + fName + "\n",
"Error reading file",
JOptionPane.ERROR_MESSAGE);
Image image = Toolkit.getDefaultToolkit().getImage(fName);
return image;
}
}
class cursorChooser extends JComponent {
public static final int kChooserWidth = 110;
public static final int kChooserHeight = 20;
private static final int textWidth = 90;
private test parent;
private JLabel text;
public Cursor crsr;
private boolean isSelected = false;
cursorChooser(test par, Cursor c, String title) {
super();
parent = par;
crsr = c;
setLayout(null);
setSize(kChooserWidth, kChooserHeight + 1);
setCursor(test.pointerCursor);
text = new JLabel(title);
text.setBounds(kChooserHeight + 10, 0, textWidth, kChooserHeight);
add(text);
MouseListener ml = new MouseListener();
addMouseListener(ml);
}
public void setSelected(boolean isSelect) {
isSelected = isSelect;
repaint();
}
@Override
public void paintComponent(Graphics g) {
if (isSelected) {
g.setColor(Color.YELLOW);
g.fillRect(0, 0, kChooserHeight + textWidth - 1, kChooserHeight);
}
g.setColor(Color.BLACK);
g.drawRect(1, 1, kChooserHeight + textWidth - 2, kChooserHeight - 1);
}
class MouseListener extends MouseAdapter {
@Override
public void mouseClicked(MouseEvent e) {
parent.selectCursor(cursorChooser.this);
}
}
}
---------- END SOURCE ----------
1.8.0_161, also seen with 1.9.0.4.11
ADDITIONAL OS VERSION INFORMATION :
Mac OS 10.12, also seen with earlier versions
A DESCRIPTION OF THE PROBLEM :
When the cursor is changed to a custom cursor and moved outside the window, then moved back inside the window, it often (but not always) does not change back to the custom cursor.
Note - the image files for the custom cursors are needed to run the test code. I don't know how to attach them to this bug report. I put copies on dropbox, link is
https://www.dropbox.com/sh/stq7a4j5uso916s/AAC-f6itTgoYs69BclK9Sfkma?dl=0
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code
Click on one of the custom cursor boxes (paintbrush or eyedropper)
Cursor changes when moved outside the selection box
Move cursor outside the window, cursor changes to pointer
Move cursor back inside the window, cursor stays pointer most of the time, sometimes correctly changes back to the custom cursor.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Cursor should always change back to the custom cursor
ACTUAL -
Cursor often stays pointer
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;
public class test extends JFrame {
public static final Cursor pointerCursor = Cursor.getDefaultCursor();
public static final Cursor handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
public static final Cursor textCursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
private static final String kEyedropperCursorName = "eyedropper.png";
public static final Image eyedropperCursorImage = getImage(kEyedropperCursorName);
public static final Point eyedropperHotspot = new Point(2,15);
public static final Cursor eyedropperCursor =
makeCustomCursor(eyedropperCursorImage, eyedropperHotspot, kEyedropperCursorName);
private static final String kPaintbrushCursorName = "paintbrush.png";
public static final Image paintbrushCursorImage = getImage(kPaintbrushCursorName);
public static final Point paintbrushHotspot = new Point(2,15);
public static final Cursor paintbrushCursor =
makeCustomCursor(paintbrushCursorImage, paintbrushHotspot, kPaintbrushCursorName);
private cursorChooser currentCursorChooser;
public test() {
super("Test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setSize(400, 400);
cursorChooser pointerCC = new cursorChooser(this, pointerCursor, "Pointer");
cursorChooser handCC = new cursorChooser(this, handCursor, "Hand");
cursorChooser textCC = new cursorChooser(this, textCursor, "Text");
cursorChooser eyedropperCC = new cursorChooser(this, eyedropperCursor, "Eyedropper");
cursorChooser paintbrushCC = new cursorChooser(this, paintbrushCursor, "Paintbrush");
int x = 5;
int y = 5;
pointerCC.setLocation(x, y);
y += cursorChooser.kChooserHeight - 1;
handCC.setLocation(x, y);
y += cursorChooser.kChooserHeight - 1;
textCC.setLocation(x, y);
y += cursorChooser.kChooserHeight - 1;
eyedropperCC.setLocation(x, y);
y += cursorChooser.kChooserHeight - 1;
paintbrushCC.setLocation(x, y);
add(pointerCC);
add(handCC);
add(textCC);
add(eyedropperCC);
add(paintbrushCC);
currentCursorChooser = pointerCC;
selectCursor(currentCursorChooser);
setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@SuppressWarnings("unused")
public void run() {
new test();
}
});
}
public void selectCursor(cursorChooser cc) {
setCursor(cc.crsr);
currentCursorChooser.setSelected(false);
currentCursorChooser = cc;
currentCursorChooser.setSelected(true);
repaint();
}
public static Cursor makeCustomCursor(Image image, Point hotSpot, String name) {
Cursor c = Toolkit.getDefaultToolkit().createCustomCursor(image, hotSpot, name);
return c;
}
public static Image getImage(String name) {
String fName = "images/" + name;
File f = new File(fName);
if (! f.exists())
JOptionPane.showMessageDialog(null,
"File not found: " + fName + "\n",
"Error reading file",
JOptionPane.ERROR_MESSAGE);
Image image = Toolkit.getDefaultToolkit().getImage(fName);
return image;
}
}
class cursorChooser extends JComponent {
public static final int kChooserWidth = 110;
public static final int kChooserHeight = 20;
private static final int textWidth = 90;
private test parent;
private JLabel text;
public Cursor crsr;
private boolean isSelected = false;
cursorChooser(test par, Cursor c, String title) {
super();
parent = par;
crsr = c;
setLayout(null);
setSize(kChooserWidth, kChooserHeight + 1);
setCursor(test.pointerCursor);
text = new JLabel(title);
text.setBounds(kChooserHeight + 10, 0, textWidth, kChooserHeight);
add(text);
MouseListener ml = new MouseListener();
addMouseListener(ml);
}
public void setSelected(boolean isSelect) {
isSelected = isSelect;
repaint();
}
@Override
public void paintComponent(Graphics g) {
if (isSelected) {
g.setColor(Color.YELLOW);
g.fillRect(0, 0, kChooserHeight + textWidth - 1, kChooserHeight);
}
g.setColor(Color.BLACK);
g.drawRect(1, 1, kChooserHeight + textWidth - 2, kChooserHeight - 1);
}
class MouseListener extends MouseAdapter {
@Override
public void mouseClicked(MouseEvent e) {
parent.selectCursor(cursorChooser.this);
}
}
}
---------- END SOURCE ----------