Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i've has similar problems trying to paint smoothly.</p> <p>try running this and see how smooth it is (its smooth for me).</p> <p>profiler says most of the time is in paint component. interestingly draw image is not mentioned.</p> <pre><code>import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import javax.swing.*; class P extends JPanel { void init(Dimension d) { GraphicsConfiguration gc=getGraphicsConfiguration(); bi=gc.createCompatibleImage(d.width,d.height); } @Override public void paintComponent(Graphics g) { //super.paintComponent(g); if(bi!=null) g.drawImage(bi,0,0,null); } BufferedImage bi; } public class So13424311 { So13424311() { p=new P(); } void createAndShowGUI() { Frame f=new JFrame("so13424311"); // f.setUndecorated(true); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.add(p); p.init(d); p.setSize(d); p.setPreferredSize(d); f.pack(); // if(moveToSecondaryDisplay) // moveToSecondaryDisplay(f); f.setVisible(true); } void run() { SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); Timer t=new Timer(20,new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Graphics g=p.bi.getGraphics(); Color old=g.getColor(); g.fillRect(0,0,d.width,d.height); g.setColor(Color.red); g.fillRect(n%(d.width/2),n%(d.height/2),20,20); g.setColor(Color.green); g.fillRect(n%(d.width/2)+20,n%(d.height/2),20,20); g.setColor(Color.blue); g.fillRect(n%(d.width/2),n%(d.height/2)+20,20,20); g.setColor(Color.yellow); g.fillRect(n%(d.width/2)+20,n%(d.height/2)+20,20,20); g.setColor(old); g.dispose(); p.repaint(); n++; } int n; }); t.start(); } public static void main(String[] args) { new So13424311().run(); } final P p; Dimension d=new Dimension(500,300); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload