Please how is possible (probably dirty hack) to create How to Create Translucent and Shaped Windows
undecorated container (returns java.awt.IllegalComponentStateException: The frame is displayable.)
change Look and Feel for (returns AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is decorated)
by using code from linked official tutorial
.
import java.awt.*;
import javax.swing.*;
public class TranslucentWindow extends JFrame {
private static final long serialVersionUID = 1L;
public TranslucentWindow() {
super("Test translucent window");
setLayout(new FlowLayout());
add(new JButton("test"));
add(new JCheckBox("test"));
add(new JRadioButton("test"));
add(new JProgressBar(0, 100));
JPanel panel = new JPanel() {
@Override
public Dimension getPreferredSize() {
return new Dimension(400, 300);
}
private static final long serialVersionUID = 1L;
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.red);
g.fillRect(0, 0, getWidth(), getHeight());
}
};
panel.add(new JLabel("Very long textxxxxxxxxxxxxxxxxxxxxx "));
add(panel);
pack();
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setUndecorated(true);
}
public static void main(String[] args) {
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
/*JFrame.setDefaultLookAndFeelDecorated(true);*/
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Window w = new TranslucentWindow();
w.setVisible(true);
com.sun.awt.AWTUtilities.setWindowOpacity(w, 0.7f);
}
});
}
}
everything works for code compiled in JDK6xx, Top-level Container can be undecorated, LookAndFeel changed to Nimbus,
not for Java7 (doesn't matter if desicion platform, binnary souce is setted back to JDK6 or not)
original discusion on SO, Can't transparent and undecorated JFrame in JDK7 when enabling nimbus
Asked/CrossPosted