(Apple bug #4138808)
Steps to Reproduce: Run the applet above in a Java 1.4 or 1.5 environment such as Safari on Tiger and on the same computer in a Java 1.3 environment such as Firefox on Tiger. Click the Refresh button.
Expected Results: The components in the array will change from all orange to all yellow, allowing you to verify that the components have refreshed. Refreshing in Java 1.4 and 1.5 should be no slower than refreshing in Java 1.3 and there should not be more flicker.
Actual Results: Refreshing in Java 1.4 and Java 1.5 is much slower than in Java 1.3 (about 4 fold on a G4-500 with 512 MB RAM when measuring from clicking refresh until the new display is complete, discounting the first refreshing that seems longer than subsequent refreshes). Also, Java 1.4 and Java 1.5 show much more flicker, as seen by exposure of the green panel background underlying the yellow/orange components in the array.
Regression:
1. Overriding update for LabelCanvas didn't help.
2. On Windows, refreshing using the Microsoft JVM seems instantaneous.
Using the Sun JVM, refreshing is much slower than the Microsoft JVM.
Notes: If you have any insights, workarounds or comments about
this test page please contact Mickey
Segal. A listing of many Java resources is at this link.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class CanvasTable3 extends Applet implements ActionListener {
Button b;
Panel labelPanel;
int labels;
int count;
Font f;
public void init()
{
f = new Font("SansSerif", Font.BOLD, 15);
b = new Button("Refresh");
add(b);
b.addActionListener(this);
labels = 200;
labelPanel = new Panel();
labelPanel.setLayout(new GridLayout(labels/20, 20, 4, 4));
labelPanel.setBackground(Color.green);
addElements();
add(labelPanel);
}
final void addElements()
{
LabelCanvas[] myLabel = new LabelCanvas[labels];
Color color = ((count%2 == 0)? Color.orange : Color.yellow);
count++;
for (int i=0; i<labels; i++)
{
myLabel[i] = new
LabelCanvas(String.valueOf(i), f);
myLabel[i].setBackground(color);
labelPanel.add(myLabel[i]);
}
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == b)
{
labelPanel.removeAll();
addElements();
validate();
}
}
} // END OF Class CanvasTable3
class LabelCanvas extends Canvas {
Font f;
String label;
LabelCanvas(String label, Font f)
{
this.label = label;
this.f = f;
}
public final void paint(Graphics g)
{
g.setFont(f);
g.drawString(label, 0, 25);
}
public final Dimension getMinimumSize()
{
return (new Dimension(30, 30));
}
public final Dimension getPreferredSize()
{
return(getMinimumSize());
}
} // END OF Class LabelCanvas