-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
5.0
-
Cause Known
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Using setViewPosition(...) or scrollRectToVisible(...) on JViewport can render incorrectly with the JViewport is obsured by another lightweight Component and the scroll mode is BLIT. The problem is also observed with the BACKINGSTORE scroll mode.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Sample code exhibiting the problem is attached.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After scrolling, the viewport rendering should not include errant artifacts remaining from obscuring, transient lightweight Components.
ACTUAL -
A portion of and obscruting JPopupMenu (lightweight enabled) gets copied as the JViewport is repositioned.
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
public class ViewportBug {
public static final void main(String[] args) {
JFrame frame = new JFrame("Viewport Bug");
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(400, 400);
frame.getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(800, 800));
final JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
frame.add(scrollPane, BorderLayout.CENTER);
final JButton button2 = new JButton("Scroll");
button2.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
JPopupMenu menu = new JPopupMenu();
menu.setInvoker(button2);
JMenuItem scrollLeft = new JMenuItem("Scroll Left");
scrollLeft.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
JViewport viewport = scrollPane.getViewport();
Point position = viewport.getViewPosition();
position.setLocation(
(int) (position.getX() -
(.1 * viewport.getViewSize().width)),
(int) position.getY());
viewport.setViewPosition(position);
}
});
menu.add(scrollLeft);
JMenuItem scrollRight = new JMenuItem("Scroll Right");
scrollRight.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
JViewport viewport = scrollPane.getViewport();
Point position = viewport.getViewPosition();
position.setLocation(
(int) (position.getX() +
(.1 * viewport.getViewSize().width)),
(int) position.getY());
viewport.setViewPosition(position);
}
});
menu.add(scrollRight);
Point menuLocation =
new Point(button2.getX(), button2.getY());
SwingUtilities.convertPointToScreen(
menuLocation,
scrollPane);
menu.setLocation(
(int) (menuLocation.getX() +
(button2.getSize().getWidth() / 2) -
(menu.getPreferredSize().getWidth() / 2)),
(int) (menuLocation.getY() -
menu.getPreferredSize().getHeight()));
menu.pack();
menu.setVisible(true);
}
});
frame.add(button2, BorderLayout.SOUTH);
frame.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Two workarounds possible:
1) Make the obscuring JPopupMenu heavyweight enabled
2) Change the scroll mode on the JViewport to be "BASIC".
java version "1.5.0_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Using setViewPosition(...) or scrollRectToVisible(...) on JViewport can render incorrectly with the JViewport is obsured by another lightweight Component and the scroll mode is BLIT. The problem is also observed with the BACKINGSTORE scroll mode.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Sample code exhibiting the problem is attached.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After scrolling, the viewport rendering should not include errant artifacts remaining from obscuring, transient lightweight Components.
ACTUAL -
A portion of and obscruting JPopupMenu (lightweight enabled) gets copied as the JViewport is repositioned.
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
public class ViewportBug {
public static final void main(String[] args) {
JFrame frame = new JFrame("Viewport Bug");
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(400, 400);
frame.getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(800, 800));
final JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
frame.add(scrollPane, BorderLayout.CENTER);
final JButton button2 = new JButton("Scroll");
button2.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
JPopupMenu menu = new JPopupMenu();
menu.setInvoker(button2);
JMenuItem scrollLeft = new JMenuItem("Scroll Left");
scrollLeft.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
JViewport viewport = scrollPane.getViewport();
Point position = viewport.getViewPosition();
position.setLocation(
(int) (position.getX() -
(.1 * viewport.getViewSize().width)),
(int) position.getY());
viewport.setViewPosition(position);
}
});
menu.add(scrollLeft);
JMenuItem scrollRight = new JMenuItem("Scroll Right");
scrollRight.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
JViewport viewport = scrollPane.getViewport();
Point position = viewport.getViewPosition();
position.setLocation(
(int) (position.getX() +
(.1 * viewport.getViewSize().width)),
(int) position.getY());
viewport.setViewPosition(position);
}
});
menu.add(scrollRight);
Point menuLocation =
new Point(button2.getX(), button2.getY());
SwingUtilities.convertPointToScreen(
menuLocation,
scrollPane);
menu.setLocation(
(int) (menuLocation.getX() +
(button2.getSize().getWidth() / 2) -
(menu.getPreferredSize().getWidth() / 2)),
(int) (menuLocation.getY() -
menu.getPreferredSize().getHeight()));
menu.pack();
menu.setVisible(true);
}
});
frame.add(button2, BorderLayout.SOUTH);
frame.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Two workarounds possible:
1) Make the obscuring JPopupMenu heavyweight enabled
2) Change the scroll mode on the JViewport to be "BASIC".