Skip to content

Instantly share code, notes, and snippets.

@noherczeg
Created November 3, 2014 20:04
Show Gist options
  • Save noherczeg/9672a2fab88ba4d6999c to your computer and use it in GitHub Desktop.
Save noherczeg/9672a2fab88ba4d6999c to your computer and use it in GitHub Desktop.
Translucency test
package main.java;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
public class Main extends JFrame {
public static final String NOT_SUPPORTED_ERR_MSG = "Translucency is not supported";
public static final String PROGRAM_TITLE = "Translucency demo";
public static void main(String[] args) throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
if (!gd.isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT)) {
System.err.println(NOT_SUPPORTED_ERR_MSG);
System.exit(0);
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Main tw = new Main();
addEscapeListener(tw);
tw.setVisible(true);
}
});
}
private Main() {
super(PROGRAM_TITLE);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
setLocation(0, 0);
setSize(dim);
setUndecorated(true);
setBackground(new Color(0, 0, 0, 210));
JButton asd = new JButton("asd");
asd.setPreferredSize(new Dimension(80, 30));
JPanel buttonPane = new JPanel();
buttonPane.setBackground(new Color(0, 0, 0, 0));
buttonPane.add(asd);
add(buttonPane, BorderLayout.SOUTH);
}
private static void addEscapeListener(final JFrame frame) {
ActionListener escListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
};
frame.getRootPane().registerKeyboardAction(escListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment