Skip to main content

Non-Opaque window issues

6 replies [Last post]
wzberger
Offline
Joined: 2004-08-31
Points: 0

The possibility to modify window opacity and translucency is very appreciated. However I've noticed some issues in conjunction with non-opaque windows.

1. On Windows Vista with native frame decoration the decoration appears but it's impossible to use components (maximize, minimize, iconify buttons) or modify frame size. On Windows XP no native frame decoration appears. So I assume on Vista no frame decoration should appear and it's Bug.

2. On older machines, without hardware acceleration, setting a window to the non-opaque mode leads to a very high CPU utilization. I wonder if there is a method to check the availability of hardware acceleration?

3. Non-opaque components appear opaque if double buffering isn't disabled - see test case below. Is this the intended behavior or just a Bug (build 1.6.0_10-rc-b27)?

public class NonOpaqueWindowTest extends JFrame
{
public NonOpaqueWindowTest()
{
super();
setLayout(new FlowLayout());

JPanel p = new JPanel();
p.setBorder(new LineBorder(Color.GREEN));
p.setBackground(Color.RED);
p.setOpaque(false);
//disable double buffering because of the opacity issue
//p.setDoubleBuffered(false);
p.setPreferredSize(new Dimension(200,200));
add(p);

setWindowNonOpaque(this);

setTitle(getClass().getSimpleName());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 300);
setLocationRelativeTo(null);
setVisible(true);
}

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 NonOpaqueWindowTest();
}
});
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
anthony_p
Offline
Joined: 2006-07-24
Points: 0

1. Please give me a piece of code that produces that effect (non-funnctional window decorations). The sample code you provided displays Swing decorations which work quite perfectly (minimizing, maximizing the window) - I'm running it on Vista with Aero theme enabled.

2. This is a Java2D related question.

3. Yes, this is a known issue. The user must manually turn off double buffering on all his/her components in order for them to paint correctly. The issue is Swing-related and may be tracked at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6668436

PS. Please use the "code" tag in sqare brackets to present the source code in a readable form. Thank you in advance.

wzberger
Offline
Joined: 2004-08-31
Points: 0

Thanks for the infos. The provided test case demonstrates the frame decoration issue as soon as the following line is remarked (Aero is enabled).
[code]
JFrame.setDefaultLookAndFeelDecorated(true);
[/code]

Test case:
[code]
public class NonOpaqueWindowTest extends JFrame
{
public NonOpaqueWindowTest()
{
super();
setLayout(new FlowLayout());

JPanel p = new JPanel();
p.setBorder(new LineBorder(Color.GREEN));
p.setBackground(Color.RED);
p.setOpaque(false);
//disable double buffering because of the opacity issue
//p.setDoubleBuffered(false);
p.setPreferredSize(new Dimension(200,200));
add(p);

setWindowNonOpaque(this);

setTitle(getClass().getSimpleName());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 300);
setLocationRelativeTo(null);
setVisible(true);
}

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 NonOpaqueWindowTest();
}
});
}
}
[/code]

anthony_p
Offline
Joined: 2006-07-24
Points: 0

Yes, now I'm able to reproduce this. The problem here is that you don't make your frame undecorated before enabling the per-pixel transparency. The AWTUtilities actually does not support natively-decorated non-opaque windows. Apparently the setWindowOpaque() method doesn't throw an exception in this case (but it should, and this is a bug, and we'll fix it). Please invoke the setUndecorated(true) method in the constructor of the NonOpaqueWindowTest and everything should work correctly. Thank you for reporting the issue. It can be tracked at: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6725365 (this URL should be available in a day or two).

wzberger
Offline
Joined: 2004-08-31
Points: 0

Thanks, that's what I've assumed.

In the meantime I've noticed some strange behavior in conjunction with internal frames. Because I'm not quite sure if this is also caused by double buffering please find the test case below. By modifying the size of the internal frame with the mouse some weired painting appears. Then try to move the internal frame or to select the buttons.

[code]
public class NonOpaqueWindowTest2 extends JFrame
{
public NonOpaqueWindowTest2()
{
super();
setWindowNonOpaque(this);

JDesktopPane desktop = new JDesktopPane();
JInternalFrame iFrame = new JInternalFrame("Test", true, true, true, true);
iFrame.add(new JLabel("internal Frame"));
iFrame.setBounds(10, 10, 300, 200);
iFrame.setVisible(true);
desktop.add(iFrame);
getContentPane().add(desktop);

setTitle(getClass().getSimpleName());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
setLocationRelativeTo(null);
setVisible(true);
}

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 NonOpaqueWindowTest2();
}
});
}
}
[/code]

anthony_p
Offline
Joined: 2006-07-24
Points: 0

Yes, I was able to reproduce the issue as well. The following bug is submitted:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6726667

(should appear in a day or two). Thank you for reporting the issues!

trembovetski
Offline
Joined: 2003-12-31
Points: 0

I believe the exception that this bug describes is not related to the painting problems, so I have filed another bug to track the painting issues specifically:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6726866

Dmitri