Skip to main content

Flicker creating fullscreen window

1 reply [Last post]
Joined: 2006-06-15

When I first create a fullscreen window (example below) I see a flicker as the window's background color gets drawn over the whole screen before the window's first paint(). How can I stop a fullscreen window from painting its background? I've tried to set the background color to transparent, but no luck.

The example below flashes the screen red just before paint()ing the default window background color. Tested on Ubuntu 8.04, sun-java6-bin, Dell Inspiron 1720, nVidia Corporation GeForce 8600M GT.

package com.burtonkrahn.jwallpaper;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;

import java.util.Date;

class FullScreenFlickerTest extends JWindow {
public static void main(String[] argv) {
new FullScreenFlickerTest();

public FullScreenFlickerTest() {

// add controls to close this window
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
JButton button = new JButton("You shouldn't see a red background flicker before this screen.\n"
+ "Click to close");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
add(button, BorderLayout.NORTH);

// set a red background to make the flas more visible.
// I don't want to see the red flash before this window appears!
setBackground(new java.awt.Color(255,0,0,0));

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();


public void paint(Graphics g) {
// debug

Reply viewing options

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

1. Please use [ code ] and [ /code ] tags (w/o spaces, lowercase) when posting code.

2. Swing expects all calls be made on the EDT. Please correct your code. (search the web for "java swing concurrency tutorial" for details).

3. You don't need to validate() your window explicitly since it's done automatically upon displaying the window. However, if/when you still want/need to validate the component hierarchy, please use Swing mechanisms for that (revalidate() instead of validate()).

4. Swing doesn't directly support painting of its top-level containers via an overridden paint() method. Instead, please insert a component (like JPanel) in the content pane of the JWindow and override its paintComponent() method. Search for "java swing painting tutorial" for details.

Even though everything above is "a must" to be done, it doesn't guarantee the absense of some flickering. On Windows there's the sun.awt.noerasebackground system property that helps deal with flickering issues. But it isn't supported on X11 unfortunately.