开发者

How to change the shape of JFrame?

开发者 https://www.devze.com 2023-02-16 05:33 出处:网络
How to change the shape of JFrame in different shape , and also make it interface look alike Mac Windows Frame

How to change the shape of JFrame in different shape , and also make it interface look alike Mac Windows Frame

开发者_StackOverflow社区

Thanks...


You can make the interface of a Java Swing application look "native" to the operating system it's running on by additing the following lines to either your main method, the init method (if it's an Applet) or to the constructor of your top-level JFrame:

try {
  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {}

Edit

UIManager.setLookAndFeel() can throw five different types of exception, documented here (assuming that you're using Java 6). How to handle these exceptions is completely up to you - if you ignore them (as in my example, catching all Exceptions and then doing nothing) then your application will use the default Java look and feel. Maybe this isn't a bad thing? Only you can decide.


To make a shaped Window you can use the class com.sun.awt.AWTUtilities. It has a Method called `setWindowShape, it takes two parameters, a shape and and a JFrame. But the class is usually restricted, so it's not a really good solution to use it. I think in the next java edition it will be added as a default class.

0

精彩评论

暂无评论...
验证码 换一张
取 消