To let the user decide to enable such an option is OK.

However I think possibly there still exists a performance bug. The test case 
below causes an avererage of 5% CPU utilization for opaque window and 50% CPU 
utilization for non-opaque windows even if the animated panel is placed on an 
opaque panel (tested on the older machine).

[code]
public class NonOpaqueWindowPerformanceTest extends JFrame
{
  public NonOpaqueWindowPerformanceTest()
  {
    super();    
    setLayout(new BorderLayout());

    JPanel p = new JPanel();
    p.setBorder(new LineBorder(Color.GREEN));
    p.setBackground(Color.RED);
    p.setOpaque(true);

    final JPanel p2 = new JPanel();
    p2.setOpaque(true);
    p2.setBorder(new LineBorder(Color.blue));
    p2.setPreferredSize(new Dimension(300,300));    
    p.add(p2);
    
    add(p);
    //remarking the following line means 90% less CPU-utilization on Windows XP
    setWindowNonOpaque(this);
    
    setTitle(getClass().getSimpleName());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(800, 600);    
    setLocationRelativeTo(null);
    setVisible(true);
    
    new Thread(){
      public void run()
      {
        while (true)
        {  
          try
          {
            Thread.sleep(50);
          }
          catch (InterruptedException e)
          {
            e.printStackTrace();
          }

          EventQueue.invokeLater(new Runnable()
          {
            public void run()
            {
              Color color = new Color(new Random().nextInt(0xFFFFFF));
              p2.setBackground(color);
            }      
          });
        }
      }      
    }.start();
  }
  
  private void setWindowNonOpaque(Window w)
  {
    try 
    {
      Class<?> c = Class.forName("com.sun.awt.AWTUtilities");
      Method m = c.getMethod("setWindowOpaque", Window.class, boolean.class);
      m.invoke(null, w, false);
    } 
    catch (Exception e) 
    {
      e.printStackTrace();
    }    
  }

  public static void main(String[] args) throws Exception
  {
    EventQueue.invokeLater(new Runnable(){
      public void run()
      {
        JFrame.setDefaultLookAndFeelDecorated(true);
        new NonOpaqueWindowPerformanceTest();
      }      
    });
  }  
}
[/code]
[Message sent by forum member 'wzberger' (wzberger)]

http://forums.java.net/jive/thread.jspa?messageID=287511

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to