Jame
Jame

Reputation: 22200

Netbeans: How to change look and feel of JTree

I am using Net-beans for developing a small desktop application. I am using a Jtree in this application. Referring to the following tutorial:

http://download.oracle.com/javase/tutorial/uiswing/components/tree.html#display

I want to customize the look and feel of my JTree to the "Java Look and Feel" (First fig from left). How should I achieve that?

Upvotes: 2

Views: 3186

Answers (3)

guru_007
guru_007

Reputation: 473

I used this change my swing app's view to windows look and feel.
As I referred from this swing docs and this property docs.
This is how we change the look and feel using command line args. java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel MyApp java -Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel MyApp

But, this is how we do programmatically using these below lines.
Properties properties = System.getProperties(); properties. setProperty("swing.defaultlaf","com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

Upvotes: 0

COD3BOY
COD3BOY

Reputation: 12112

This is something you should look into : Pluggable look-and-feel architecture : Swing's pluggable look-and-feel architecture allows us to provide a single component API without dictating a particular look-and-feel. The Swing toolkit provides a default set of look-and-feels; however, the API is "open" -- a design that additionally allows developers to create new look-and-feel implementations by either extending an existing look-and-feel or creating one from scratch.

And as per the suggestion of @JB Nizet , if you prefer to change the LaF of the application , this might be helpful : Look and Feel in Java

Upvotes: 2

JB Nizet
JB Nizet

Reputation: 692121

You generally don't change the look and feel of a unique component, but the look and feel of the entire application.

See the Swing tutorial for explanations.

It's perhaps possible to change the look and feel of a single component, but then the application would be inconsistent. I would never do that.

Upvotes: 3

Related Questions