-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.3.1, 1.4.1, 1.4.2
-
x86
-
linux, windows_xp
Name: jk109818 Date: 08/25/2003
FULL PRODUCT VERSION :
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)
Java HotSpot(TM) Client VM (build 1.3.1_07-b02, mixed mode)
FULL OS VERSION :
Linux crow 2.4.20 (Redhat 8)
MS Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
My application displays HTML pages in a JEditorPane. It uses a glass pane to overlay the document and display icons over the html page. A right click displays a JPopupMenu to select and make annotations to the html. The popup is displayed ok anywhere in the frame. Once the popup is displayed, it should scroll the selection while the mouse is over it. In this case, the mouse scrolls as expected only if the menu was initially displayed on the far right side of the frame or the very bottom edge of the frame. Anywhere else and the menu selection does not change. I have tried the JPopupMenu.setLightWeightPopupEnabled call with both values and every way I can think of to redispatch the mouse events to no avail.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the 3 classes and run the application java Annotator
Right click on the right side of the frame. When the popup menu appears, move the mouse up and down to scroll the selection. Now right click on the left side of the frame and try to scroll the selection on the popup menu.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect that the menu selection should scroll with the mouse no matter where it appears on the frame.
ACTUAL -
The menu selection only scrolls if it is initially displayed on the right hand portion of the frame.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error messages.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.Rectangle;
import java.awt.Point;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.MouseEvent;
/** Annotator */
public class Annotator
{
public static void main(String[] args)
{
new Annotator();
}
/** Annotator Constructor */
public Annotator()
{
frame = new JFrame("The Annotator");
frame.getContentPane().setLayout(new BorderLayout());
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// Setup the JEditorPane and ScrollPane
HTMLEditorKit kit = new HTMLEditorKit();
JEditorPane html = new JEditorPane();
html.setBackground(Color.blue);
JScrollPane scroller = new JScrollPane();
JViewport vp = scroller.getViewport();
vp.add(html);
Dimension pref_size = new Dimension(680, 600);
scroller.setPreferredSize(pref_size);
frame.getContentPane().add(scroller, BorderLayout.CENTER);
popup = new JPopupMenu();
JMenuItem selection = new JMenuItem("Annotate Selection");
popup.add(selection);
JMenuItem anno_doc = new JMenuItem("Annotate Document");
popup.add(anno_doc);
html.addMouseListener(new MouseInputAdapter() {
public void mousePressed(MouseEvent e) {
// Popup the JPopupMenu popup
if (e.getModifiers() == e.META_MASK) {
popup.show((Component)e.getComponent(),e.getX(),e.getY());
}
}
});
// Setup the GlassPane
DOMGlassPane glassPane = new DOMGlassPane(frame.getContentPane(),popup);
frame.setGlassPane(glassPane);
glassPane.setEnabled(true);
glassPane.setVisible(true);
frame.pack();
frame.setVisible(true);
}
// GUI components
private JPopupMenu popup;
private JFrame frame;
}
class DOMGlassPane extends JComponent
{
/** Constructor: Create and add listeners, initialize icon. */
public DOMGlassPane(Container contentPane,JPopupMenu pop)
{
GPListener listener = new GPListener(this,contentPane,pop);
addMouseListener(listener);
addMouseMotionListener(listener);
}
}
/**
* Listen for all mouse events that our glass pane is likely to be
* interested in. Redispatch them to the appropriate component. */
class GPListener extends MouseInputAdapter
{
/** Constructor: initialize variables. */
public GPListener(DOMGlassPane glassPane, Container contentPane,
JPopupMenu pop)
{
this.glassPane = glassPane;
this.contentPane = contentPane;
this.popup = pop;
}
/** Handle mouseMoved events. */
public void mouseMoved(MouseEvent e)
{
redispatchMouseEvent(e, false);
}
/** Handle mouseDragged events. */
public void mouseDragged(MouseEvent e)
{
redispatchMouseEvent(e, false);
}
/** Handle mouseClicked events. */
public void mouseClicked(MouseEvent e)
{
redispatchMouseEvent(e, true);
}
/** Handle mouseEntered events. */
public void mouseEntered(MouseEvent e)
{
redispatchMouseEvent(e, false);
}
/** Handle mouseExited events. */
public void mouseExited(MouseEvent e)
{
redispatchMouseEvent(e, false);
}
/** Handle mousePressed events. */
public void mousePressed(MouseEvent e)
{
redispatchMouseEvent(e, false);
}
/** Handle mouseReleased events. */
public void mouseReleased(MouseEvent e)
{
redispatchMouseEvent(e, true);
}
private void redispatchMouseEvent(MouseEvent e, boolean repaint)
{
Point glassPanePoint = e.getPoint();
Component component = null;
Container container = contentPane;
if (popup.isVisible()) {
Rectangle rect = popup.getBounds();
Point popp = SwingUtilities.convertPoint(glassPane,glassPanePoint,popup);
if (rect.contains(popp)) {
popup.dispatchEvent(new MouseEvent(glassPane,
e.getID(),
e.getWhen(),
e.getModifiers(),
popp.x,
popp.y,
e.getClickCount(),
e.isPopupTrigger()));
}
} else {
Point containerPoint = SwingUtilities.convertPoint(glassPane,
glassPanePoint,
contentPane);
// Get component at these coordinates
component = SwingUtilities.getDeepestComponentAt(container,
containerPoint.x,
containerPoint.y);
if (component == null) {
return;
}
// Convert contentPane coordinate to the components coordinates
Point componentPoint = SwingUtilities.convertPoint(glassPane,
glassPanePoint,
component);
// Send the MouseEvent on its way
component.dispatchEvent(new MouseEvent(component,
e.getID(),
e.getWhen(),
e.getModifiers(),
componentPoint.x,
componentPoint.y,
e.getClickCount(),
e.isPopupTrigger()));
}
if (repaint) {
glassPane.repaint();
}
}
private DOMGlassPane glassPane;
private Container contentPane;
private JPopupMenu popup;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Holding down the right mouse button and dragging works everywhere, but it confuses users as it is not the expected behaviour.
(Incident Review ID: 186565)
======================================================================