-
Bug
-
Resolution: Unresolved
-
P3
-
8, 11, 21, 25, 26
-
x86_64
-
generic
A DESCRIPTION OF THE PROBLEM :
I have created a “JFrame” that alternates between opaque and transparent using “setBackground()”. If I assign the ‘opaque’ color a value of (for example) “new Color( 255,0,0,254 )” (note that this is one step away from total opacity), the transition occurs without any problems. Now, if I use total opacity instead (for example, “new Color( 255,0,0,255 )”), it goes from ‘transparent’ to “opaque” smoothly, but when trying to return to “transparent,” it loses transparency and color (it uses the default color). The mini application has two buttons, one chooses between ‘transparent’ and “opaque,” and the other assigns a value to the “opaque” color. If, after this, I reset the ‘opaque’ color with a transparency value lower than “255,” it works normally again (for example, “new Color( 255,0,0,253 )”), although it may take a couple of clicks.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Once the application has started, try clicking several times on the first button and you will see how the frame alternates between transparent and opaque (as you will see in the text of the second button, it is using a color value that is not completely opaque). Now click on the second button (this sets the color to completely opaque). Repeat the first steps. Now, when you try to switch from opaque to transparent, not only will you be unable to do so, but you will also lose the color. If you use the second button again, everything will work properly.
ACTUAL -
No output
---------- BEGIN SOURCE ----------
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
public class TheSwingError extends JFrame {
Color transparent = new Color( 255, 0, 0, 100 ),
almostOpaque = new Color( 255, 0, 0, 254 ),
completelyOpaque = new Color( 255, 0, 0, 255 ),
opaque = almostOpaque;
public TheSwingError() {
setUndecorated( true );
setDefaultCloseOperation( javax.swing.WindowConstants.EXIT_ON_CLOSE );
setBounds( 10, 10, 500, 500 );
setBackground( transparent );
setLayout( null );
JButton colorChooser = new JButton( "opaque = 255,0,0,254" );
JButton alternate = new JButton( "Transparent" );
colorChooser.setBounds( 10, 50, 160, 26 );
alternate.setBounds( 10, 10, 160, 26 );
add( colorChooser );
add( alternate );
setVisible( true );
alternate.addMouseListener( new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked( java.awt.event.MouseEvent evt ) {
JButton aux = (JButton) evt.getSource();
if( aux.getText().equals( "Transparent" ) ) {
setBackground( opaque );
aux.setText( "Opaque" );
}
else {
setBackground( transparent );
aux.setText( "Transparent" );
}
}
} );
colorChooser.addMouseListener( new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked( java.awt.event.MouseEvent evt ) {
JButton aux = (JButton) evt.getSource();
if( aux.getText().equals( "opaque = 255,0,0,254" ) ) {
opaque = completelyOpaque;
aux.setText( "color = 255,0,0,255" );
}
else {
opaque = almostOpaque;
aux.setText( "opaque = 255,0,0,254" );
}
}
} );
}
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
new TheSwingError();
} );
}
}
---------- END SOURCE ----------
I have created a “JFrame” that alternates between opaque and transparent using “setBackground()”. If I assign the ‘opaque’ color a value of (for example) “new Color( 255,0,0,254 )” (note that this is one step away from total opacity), the transition occurs without any problems. Now, if I use total opacity instead (for example, “new Color( 255,0,0,255 )”), it goes from ‘transparent’ to “opaque” smoothly, but when trying to return to “transparent,” it loses transparency and color (it uses the default color). The mini application has two buttons, one chooses between ‘transparent’ and “opaque,” and the other assigns a value to the “opaque” color. If, after this, I reset the ‘opaque’ color with a transparency value lower than “255,” it works normally again (for example, “new Color( 255,0,0,253 )”), although it may take a couple of clicks.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Once the application has started, try clicking several times on the first button and you will see how the frame alternates between transparent and opaque (as you will see in the text of the second button, it is using a color value that is not completely opaque). Now click on the second button (this sets the color to completely opaque). Repeat the first steps. Now, when you try to switch from opaque to transparent, not only will you be unable to do so, but you will also lose the color. If you use the second button again, everything will work properly.
ACTUAL -
No output
---------- BEGIN SOURCE ----------
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
public class TheSwingError extends JFrame {
Color transparent = new Color( 255, 0, 0, 100 ),
almostOpaque = new Color( 255, 0, 0, 254 ),
completelyOpaque = new Color( 255, 0, 0, 255 ),
opaque = almostOpaque;
public TheSwingError() {
setUndecorated( true );
setDefaultCloseOperation( javax.swing.WindowConstants.EXIT_ON_CLOSE );
setBounds( 10, 10, 500, 500 );
setBackground( transparent );
setLayout( null );
JButton colorChooser = new JButton( "opaque = 255,0,0,254" );
JButton alternate = new JButton( "Transparent" );
colorChooser.setBounds( 10, 50, 160, 26 );
alternate.setBounds( 10, 10, 160, 26 );
add( colorChooser );
add( alternate );
setVisible( true );
alternate.addMouseListener( new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked( java.awt.event.MouseEvent evt ) {
JButton aux = (JButton) evt.getSource();
if( aux.getText().equals( "Transparent" ) ) {
setBackground( opaque );
aux.setText( "Opaque" );
}
else {
setBackground( transparent );
aux.setText( "Transparent" );
}
}
} );
colorChooser.addMouseListener( new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked( java.awt.event.MouseEvent evt ) {
JButton aux = (JButton) evt.getSource();
if( aux.getText().equals( "opaque = 255,0,0,254" ) ) {
opaque = completelyOpaque;
aux.setText( "color = 255,0,0,255" );
}
else {
opaque = almostOpaque;
aux.setText( "opaque = 255,0,0,254" );
}
}
} );
}
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
new TheSwingError();
} );
}
}
---------- END SOURCE ----------