Piyush
Piyush

Reputation: 2609

How to change the shape of JFrame?

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

Thanks...

Upvotes: 0

Views: 2051

Answers (2)

Brian Beckett
Brian Beckett

Reputation: 4900

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.

Upvotes: 3

const-ae
const-ae

Reputation: 2206

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.

Upvotes: 0

Related Questions