How to change the LookAndFeel of the NetBeans Platform Framework Application

我怕爱的太早我们不能终老 提交于 2019-12-06 14:35:29

问题


I cannot figure out how to change the LookAndFeel of the application I built on the NetBeans platform framework, can anybody please help? I want to change its look using the TinyLAF java api http://www.muntjak.de/hans/java/tinylaf/index.html. I know how to change the LookAndFeel when developing a regular Swing application in the NetBeans IDE, but not when developing it on the NetBeans Platform framework.

This is the code, for TinyLAF, that I use for regular Swing applications:

Toolkit.getDefaultToolkit().setDynamicLayout(true);
System.setProperty("sun.awt.noerasebackground", "true");
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);

try {
    UIManager.setLookAndFeel("de.muntjak.tinylookandfeel.TinyLookAndFeel");
} catch(Exception ex) {
    ex.printStackTrace();
}

TinyLaF looks for a default theme file named 'Default.theme' (case-sensitive). If it finds one, this file will be loaded at startup. (The 'Default.theme' file is an ordinary TinyLaF .theme file, just with a special name, you can take any .theme file and rename it to 'Default.theme').

TinyLaF will search the following URLs:

  1. TinyLookAndFeel.class.getResource("/Default.theme");
    • finds 'Default.theme' if it is inside tinylaf.jar
  2. Thread.currentThread().getContextClassLoader().getResource("Default.theme");
    • finds 'Default.theme' if it is inside your application's JAR
  3. new File(System.getProperty("user.home"), "Default.theme").toURI().toURL();
    • finds 'Default.theme' if it is inside the home directory
  4. new File(System.getProperty("user.dir"), "Default.theme").toURI().toURL();
    • finds 'Default.theme' if it is inside the working directory

Please note that my question is not how to change the LookAndFeel of the NetBeans IDE, but how to do it for the Java Application built on top of NetBeans Platform framework.


回答1:


I found the following searching the net: you need to do it in the module "Installer". check this link for where you need to add: http://joshiegeek.blogspot.co.il/2012/01/netbeans-platform-custom-laf.html

this one has actual code sample (please ignore the title :)) : http://forums.netbeans.org/topic39450.html

and finally this one talks of a specific plaf but has few comments along the way : https://blogs.oracle.com/geertjan/entry/blue_look_and_feel_for




回答2:


1. You can change the look and feel of Swing very easily as its based on MVC architecture.

2. Swing is also known as PLAF (Pluggable Look And Feel), so keep the same Model part and change the View, example like same model for desktop and web application.

3. Use

UIManager.setLookAndFeel(Your_Choice_of_Look_and_Feel);  // To set the Look and Feel
SwingUtilities.updateComponentTreeUI(frame);        // To refresh the JFrame and Components

See this for more details:

http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html




回答3:


Had to find that first link mentioned in an earlier post on the waybackmachine ...

Answer is to add a runtime argument or put it in the project.properties file. The line to add (for e.g. Metal) is

run.args.extra=--laf javax.swing.plaf.metal.MetalLookAndFeel


来源:https://stackoverflow.com/questions/11637006/how-to-change-the-lookandfeel-of-the-netbeans-platform-framework-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!