-
Bug
-
Resolution: Unresolved
-
P4
-
11, 23
-
x86_64
-
linux_ubuntu
A DESCRIPTION OF THE PROBLEM :
When setting the window background to transparent on Ubuntu and in Java versions above 8 (I tested 11, 17, 22), the window flickers when the setBounds method is called.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create any window with a transparent background
2. Calling the repaint method on it
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Calling the repaint method repaints the view without flickering
ACTUAL -
Calling the repaint method repaints the view with flickering
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class FlickeringWindow {
public static void main(String[] args) {
JPanel panel = new JPanel(new BorderLayout());
panel.setBackground(Color.RED);
JDialog dialog = new JDialog();
dialog.setUndecorated(true);
dialog.getRootPane().setOpaque(false);
dialog.setBackground(new Color(0, 0, 0, 0));
dialog.getRootPane().setBorder(new LineBorder(Color.BLUE, 5));
dialog.setContentPane(panel);
dialog.setPreferredSize(new Dimension(450, 450));
ResizableListener listener = new ResizableListener(dialog);
dialog.addMouseMotionListener(listener);
dialog.addMouseListener(listener);
dialog.setLocationRelativeTo(null);
dialog.pack();
dialog.setVisible(true);
}
private static class ResizableListener extends MouseAdapter {
boolean isInResize = false;
Point referencePoint;
Dialog dialog;
public ResizableListener(Dialog dialog) {
this.dialog = dialog;
}
@Override
public void mousePressed(MouseEvent e) {
referencePoint = e.getPoint();
isInResize = true;
}
@Override
public void mouseReleased(MouseEvent e) {
if (isInResize) {
isInResize = false;
referencePoint = null;
}
}
@Override
public void mouseDragged(MouseEvent e) {
if (isInResize) {
resizeView(e);
}
}
private void resizeView(MouseEvent e) {
int mouseOffset = (int) (referencePoint.distance(e.getX(), e.getY()));
if (mouseOffset > 20 || mouseOffset < -20) {
referencePoint = new Point(e.getX(), e.getY());
dialog.setBounds(dialog.getX(), dialog.getY(), dialog.getWidth() + 10, dialog.getHeight() + 10);
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Not found
FREQUENCY : always
When setting the window background to transparent on Ubuntu and in Java versions above 8 (I tested 11, 17, 22), the window flickers when the setBounds method is called.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create any window with a transparent background
2. Calling the repaint method on it
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Calling the repaint method repaints the view without flickering
ACTUAL -
Calling the repaint method repaints the view with flickering
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class FlickeringWindow {
public static void main(String[] args) {
JPanel panel = new JPanel(new BorderLayout());
panel.setBackground(Color.RED);
JDialog dialog = new JDialog();
dialog.setUndecorated(true);
dialog.getRootPane().setOpaque(false);
dialog.setBackground(new Color(0, 0, 0, 0));
dialog.getRootPane().setBorder(new LineBorder(Color.BLUE, 5));
dialog.setContentPane(panel);
dialog.setPreferredSize(new Dimension(450, 450));
ResizableListener listener = new ResizableListener(dialog);
dialog.addMouseMotionListener(listener);
dialog.addMouseListener(listener);
dialog.setLocationRelativeTo(null);
dialog.pack();
dialog.setVisible(true);
}
private static class ResizableListener extends MouseAdapter {
boolean isInResize = false;
Point referencePoint;
Dialog dialog;
public ResizableListener(Dialog dialog) {
this.dialog = dialog;
}
@Override
public void mousePressed(MouseEvent e) {
referencePoint = e.getPoint();
isInResize = true;
}
@Override
public void mouseReleased(MouseEvent e) {
if (isInResize) {
isInResize = false;
referencePoint = null;
}
}
@Override
public void mouseDragged(MouseEvent e) {
if (isInResize) {
resizeView(e);
}
}
private void resizeView(MouseEvent e) {
int mouseOffset = (int) (referencePoint.distance(e.getX(), e.getY()));
if (mouseOffset > 20 || mouseOffset < -20) {
referencePoint = new Point(e.getX(), e.getY());
dialog.setBounds(dialog.getX(), dialog.getY(), dialog.getWidth() + 10, dialog.getHeight() + 10);
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Not found
FREQUENCY : always