下面列出了javax.swing.LookAndFeel#isSupportedLookAndFeel ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
*
*/
private void addToMenu(String name, String className, JMenu menu) {
logger.debug("PLAF LookAndFeelInfo {}", className);
boolean isSupported = true;
try {
Class cl = Class.forName(className);
LookAndFeel lf = (LookAndFeel) cl.newInstance();
if (!lf.isSupportedLookAndFeel()) {
isSupported = false;
}
} catch (Throwable t) {
isSupported = false;
}
AbstractAction act = new PLAFAction(name, className);
JMenuItem mi = menu.add(act);
if (!isSupported) {
mi.setEnabled(false);
}
}
/**
* A utility function that layers on top of the LookAndFeel's
* isSupportedLookAndFeel() method. Returns true if the LookAndFeel
* is supported. Returns false if the LookAndFeel is not supported
* and/or if there is any kind of error checking if the LookAndFeel
* is supported.
*
* The L&F menu will use this method to detemine whether the various
* L&F options should be active or inactive.
*
* @param laf the laf
* @return true, if is available look and feel
*/
protected boolean isAvailableLookAndFeel(String laf) {
try {
Class lnfClass = Class.forName(laf);
LookAndFeel newLAF = (LookAndFeel)(lnfClass.newInstance());
return newLAF.isSupportedLookAndFeel();
} catch(Exception e) { // If ANYTHING weird happens, return false
return false;
}
}