-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.1.2, 1.1.4
-
x86, sparc
-
solaris_2.5.1, windows_nt
Name: joT67522 Date: 08/28/97
/*
The following code works fine when scrollbars are enabled,
however it flickers badly when using SCROLLBARS_NEVER. It
appears that paint is being called twice each time a
button is pressed when I use SCROLLBARS_NEVER. When
SCROLLBARS_AS_NEEDED is used, paint is called once each time a
button is pressed.
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class ScrollPaneTest extends Frame implements ActionListener {
private final int SCROLL_VAL = 20;
private ScrollPane scrollPane;
public static void main(String[] args) {
new ScrollPaneTest();
}
public ScrollPaneTest() {
/* flickers badly with no scrollbars */
scrollPane = new ScrollPane(ScrollPane.SCROLLBARS_NEVER);
/* no flicker when scrollbars are displayed */
//scrollPane = new ScrollPane();
scrollPane.add(new MyCanvas());
scrollPane.setSize(300, 300);
add(scrollPane, "Center");
Panel p = new Panel();
Button b = new Button("up");
b.addActionListener(this);
p.add(b);
b = new Button("down");
b.addActionListener(this);
p.add(b);
b = new Button("left");
b.addActionListener(this);
p.add(b);
b = new Button("right");
b.addActionListener(this);
p.add(b);
add(p, "South");
pack();
show();
}
public void actionPerformed(ActionEvent evt) {
String action = evt.getActionCommand();
Point p = scrollPane.getScrollPosition();
if(action.equals("up")) {
p.translate(0, -SCROLL_VAL);
scrollPane.setScrollPosition(p);
}
else if(action.equals("down")) {
p.translate(0, SCROLL_VAL);
scrollPane.setScrollPosition(p);
}
else if(action.equals("left")) {
p.translate(-SCROLL_VAL, 0);
scrollPane.setScrollPosition(p);
}
else if(action.equals("right")) {
p.translate(SCROLL_VAL, 0);
scrollPane.setScrollPosition(p);
}
}
}
class MyCanvas extends Canvas {
private Image image, buffer;
public MyCanvas() {
image = Toolkit.getDefaultToolkit().getImage("main.gif");
prepareImage(image, -1, -1, this);
setSize(640, 480);
}
public void addNotify() {
super.addNotify();
buffer = createImage(640, 480);
drawPage();
}
private void drawPage() {
if(buffer == null)
return;
Graphics g = buffer.getGraphics();
g.drawImage(image, 0, 0, null);
}
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
if(((infoflags & ImageObserver.ALLBITS) != 0)) {
// image is finished downloading
drawPage();
repaint();
return false;
}
return true;
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
/* it appears that paint is being called twice every time a
button is pressed when scrollbars are not displayed */
System.out.print("Painting ");
super.paint(g);
g.drawImage(buffer, 0, 0, null);
}
}
company - Network Communication Systems , email - ###@###.###
======================================================================