How to add transparency slider to JColorChooser with GTK look
Before Java7, if you wanted the user to select a transparent color, you had to show JColorChooser
and add your own transparency slider as the standard color picker did not have an interface for transparency / opacity.
As of Java7, the standard JColorChooser
seems to include such a slider, so I removed my own transparency slider. However, JColorChooser
when using the GTK + look and feel, this slider / custom widget is missing.
Does anyone know of an easy way to add a transparency slider to the GTK + look and feel JColorChooser
(like a system property I have to set, a key-value pair in the UI manager ...)?
Looking at this related question I am afraid no such property exists. Otherwise it could probably have been used to disable / remove the transparency slider.
Screenshots to illustrate what you have with Metal versus what you get under GTK:
Metallic appearance
GTK + appearance
Code used to take screenshots
Of course, the code must be run with JDK7 or higher
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JColorChooser;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class ColorChooserExample {
public static void main(String[] args) {
EventQueue.invokeLater(
new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JColorChooser.showDialog(null, "Pick color", Color.YELLOW );
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (UnsupportedLookAndFeelException e) {
throw new RuntimeException(e);
}
}
}
);
}
}
source to share
No one has answered this question yet
See similar questions:
or similar: