简体   繁体   English

Netbeans:如何更改JTree的外观

[英]Netbeans: How to change look and feel of JTree

I am using Net-beans for developing a small desktop application. 我正在使用Net-beans开发小型桌面应用程序。 I am using a Jtree in this application. 我在此应用程序中使用Jtree Referring to the following tutorial: 请参考以下教程:

http://download.oracle.com/javase/tutorial/uiswing/components/tree.html#display 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). 我想将JTree的外观和感觉自定义为“ Java外观”(左图)。 How should I achieve that? 我应该如何实现?

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. 有关说明,请参见Swing教程

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. 我永远不会那样做。

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. 这是您应该研究的内容: 可插拔的外观体系结构 :Swing的可插拔的外观体系结构使我们能够提供单个组件API,而无需规定特定的外观。 The Swing toolkit provides a default set of look-and-feels; Swing工具箱提供了一组默认的外观。 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. 但是,API是“开放的”-一种设计,它允许开发人员通过扩展现有的外观或从头开始创建外观,从而创建新的外观实现。

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 根据@JB Nizet的建议,如果您希望更改应用程序的LaF,这可能会有所帮助: Java中的外观

I used this change my swing app's view to windows look and feel . 我使用此更改将swing应用程序的视图更改为Windows外观
As I referred from this swing docs and this property docs . 正如我从这个swing文档property文档中提到的那样。
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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM