Java-如何在 Java 中降低装饰 JFrame 的不透明度?
Java-How to decrease opacity of decorated JFrame in Java?
我正在尝试更改 JFrame 的不透明度,但不要将其设置为未装饰,因为它会删除它的倾斜栏。
我已经试过了:-
JFrame subFrame = new JFrame();
subFrame.setBounds(0, 0, 500, 500);
subFrame.setVisible(true);
subFrame.setOpacity(0.80f);
但它给出了错误:-
Exception in thread "main" java.awt.IllegalComponentStateException: The frame is decorated
at java.awt.Frame.setOpacity(Unknown Source)
at TransparentFrame.main(TransparentFrame.java:26)
请帮助我!!!!!!!!!!
javaDocs 明确指出 JFrame 必须未修饰才能使用 setOpacity() 方法。所以很遗憾,这是不可能的。至少不是你这样做的方式。
您可以使用以下(不是很干净)解决方法:
JFrame.setDefaultLookAndFeelDecorated(true); //Before you create the JFrame.
UIManager.setLookAndFeel(new MetalLookAndFeel());
然后创建您的 JFrame 实例。
我正在尝试更改 JFrame 的不透明度,但不要将其设置为未装饰,因为它会删除它的倾斜栏。
我已经试过了:-
JFrame subFrame = new JFrame();
subFrame.setBounds(0, 0, 500, 500);
subFrame.setVisible(true);
subFrame.setOpacity(0.80f);
但它给出了错误:-
Exception in thread "main" java.awt.IllegalComponentStateException: The frame is decorated
at java.awt.Frame.setOpacity(Unknown Source)
at TransparentFrame.main(TransparentFrame.java:26)
请帮助我!!!!!!!!!!
javaDocs 明确指出 JFrame 必须未修饰才能使用 setOpacity() 方法。所以很遗憾,这是不可能的。至少不是你这样做的方式。 您可以使用以下(不是很干净)解决方法:
JFrame.setDefaultLookAndFeelDecorated(true); //Before you create the JFrame.
UIManager.setLookAndFeel(new MetalLookAndFeel());
然后创建您的 JFrame 实例。