Vote count:
0
I used the following code, and as usual (with OSX) the drawings occurred as expected: area has no memory and each of the drawings appeared alone on top of a fresh cleared area.
I tried the same under Linux and Windows, but the drawings appeared one top of each other. I verified that every JComponent is double buffered, same for RepaintManager, etc. Everything looks similar on the three systems.
From my past readings about drawings I know that we must double buffer by ourselves. In fact there is no memory under Linux/Windows: when I hide the window everything gets clear, but while not hidden everything gets accumulated.
What makes me curious is: how Linux/Windows does it? Why it behave as such? What part of the GUI clears the drawing area under OSX? Is this due to the host environment (Aqua) or JVM implementation?
It seems to me that Linux/Windows behave simply: while not hidden the screen area is always the same, so there is no reason to clear it. But why OSX clears it?
Note: I tried some OS versions and JVM versions, always the same: OSX => clears in between drawings, Linux/Windows => accumulates drawings.
Any explanation?
import javax.swing.*;
import java.awt.*;
class CanvasPanel extends JPanel implements Runnable{
public void start() {
new Thread(this).start();
}
public void run() {
for (int i=0; i<200; i++) {
repaint();
try { Thread.sleep(100); }
catch (InterruptedException e) { }
}
}
public void paintComponent(Graphics g) {
// Draws one line over a clean area under OSX
// Accumulates drawings under Linux/Windows
g.drawLine((int)(Math.random()*800),
(int)(Math.random()*800),
(int)(Math.random()*800),
(int)(Math.random()*800));
}
public Dimension getPreferredSize() {
return new Dimension(800,800);
}
}
public class MyTest extends JFrame implements Runnable {
public void run() {
JFrame f = new JFrame();
CanvasPanel p = new CanvasPanel();
f.getContentPane().add(p);
f.pack() ;
f.setVisible(true);
p.start();
}
public static void main(String []a) {
SwingUtilities.invokeLater(new MyTest());
}
}
JPanel customization, double-buffering, Linux vs Windows vs OSX experience. Explanation?
Aucun commentaire:
Enregistrer un commentaire