下面列出了怎么用javax.swing.UIManager.LookAndFeelInfo的API类实例代码及写法,或者点击链接到github查看源代码。
public static void main(String[] args) {
if (args.length != 5) {
System.err.println("Needs database parameters eg. ...");
System.err.println(
"java TableExample2 \"jdbc:derby://localhost:1527/sample\" "
+ "org.apache.derby.jdbc.ClientDriver app app "
+ "\"select * from app.customer\"");
return;
}
// Trying to set Nimbus look and feel
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
Logger.getLogger(TableExample2.class.getName()).log(Level.SEVERE,
"Failed to apply Nimbus look and feel", ex);
}
new TableExample2(args[0], args[1], args[2], args[3], args[4]);
}
public static void main(String[] args) {
// Trying to set Nimbus look and feel
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
Logger.getLogger(TableExample4.class.getName()).log(Level.SEVERE,
"Failed to apply Nimbus look and feel", ex);
}
new TableExample4();
}
public static void main(String s[]) {
// Trying to set Nimbus look and feel
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
Logger.getLogger(TableExample.class.getName()).log(Level.SEVERE,
"Failed to apply Nimbus look and feel", ex);
}
new TableExample();
}
public static void main(String[] args) {
if (args.length != 5) {
System.err.println("Needs database parameters eg. ...");
System.err.println(
"java TableExample2 \"jdbc:derby://localhost:1527/sample\" "
+ "org.apache.derby.jdbc.ClientDriver app app "
+ "\"select * from app.customer\"");
return;
}
// Trying to set Nimbus look and feel
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
Logger.getLogger(TableExample2.class.getName()).log(Level.SEVERE,
"Failed to apply Nimbus look and feel", ex);
}
new TableExample2(args[0], args[1], args[2], args[3], args[4]);
}
public static void main(final String[] args) throws Exception {
try {
createGUI();
for (final LookAndFeelInfo laf : getInstalledLookAndFeels()) {
final String name = laf.getName();
if (name.contains("OS X") || name.contains("Metal")) {
SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
SwingUtilities.invokeAndWait(() -> {
for (int i = 0; i < 4000; ++i) {
SwingUtilities.updateComponentTreeUI(frame);
}
});
}
}
} finally {
EventQueue.invokeAndWait(() -> frame.dispose());
}
}
public static void main(String s[]) {
// Trying to set Nimbus look and feel
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
Logger.getLogger(TableExample.class.getName()).log(Level.SEVERE,
"Failed to apply Nimbus look and feel", ex);
}
new TableExample();
}
public static void main(String s[]) {
// Trying to set Nimbus look and feel
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
Logger.getLogger(TableExample.class.getName()).log(Level.SEVERE,
"Failed to apply Nimbus look and feel", ex);
}
new TableExample();
}
public static void main(String[] args) {
// Trying to set Nimbus look and feel
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
Logger.getLogger(TableExample4.class.getName()).log(Level.SEVERE,
"Failed to apply Nimbus look and feel", ex);
}
new TableExample4();
}
public static void main(String[] args) {
if (args.length != 5) {
System.err.println("Needs database parameters eg. ...");
System.err.println(
"java TableExample2 \"jdbc:derby://localhost:1527/sample\" "
+ "org.apache.derby.jdbc.ClientDriver app app "
+ "\"select * from app.customer\"");
return;
}
// Trying to set Nimbus look and feel
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
Logger.getLogger(TableExample2.class.getName()).log(Level.SEVERE,
"Failed to apply Nimbus look and feel", ex);
}
new TableExample2(args[0], args[1], args[2], args[3], args[4]);
}
public static void main(String[] args) {
if (args.length != 5) {
System.err.println("Needs database parameters eg. ...");
System.err.println(
"java TableExample2 \"jdbc:derby://localhost:1527/sample\" "
+ "org.apache.derby.jdbc.ClientDriver app app "
+ "\"select * from app.customer\"");
return;
}
// Trying to set Nimbus look and feel
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
Logger.getLogger(TableExample2.class.getName()).log(Level.SEVERE,
"Failed to apply Nimbus look and feel", ex);
}
new TableExample2(args[0], args[1], args[2], args[3], args[4]);
}
protected boolean store() {
prefs.putBoolean(WinSysPrefs.MAXIMIZE_NATIVE_LAF, checkMaximizeNativeLaF.isSelected());
System.setProperty("nb.native.filechooser", checkMaximizeNativeLaF.isSelected() ? "true" : "false"); //NOI18N
int selLaFIndex = comboLaf.getSelectedIndex();
if( selLaFIndex != defaultLookAndFeelIndex && !isForcedLaF() ) {
LookAndFeelInfo li = lafs.get( comboLaf.getSelectedIndex() );
NbPreferences.root().node( "laf" ).put( "laf", li.getClassName() ); //NOI18N
if (NO_RESTART_ON_LAF_CHANGE) {
try {
UIManager.setLookAndFeel(li.getClassName());
WindowManager wmgr = Lookup.getDefault().lookup(WindowManager.class);
wmgr.updateUI();
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException ex) {
askForRestart();
}
} else {
askForRestart();
}
}
return false;
}
public static void main(String[] args) {
if (args.length != 5) {
System.err.println("Needs database parameters eg. ...");
System.err.println(
"java TableExample2 \"jdbc:derby://localhost:1527/sample\" "
+ "org.apache.derby.jdbc.ClientDriver app app "
+ "\"select * from app.customer\"");
return;
}
// Trying to set Nimbus look and feel
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
Logger.getLogger(TableExample2.class.getName()).log(Level.SEVERE,
"Failed to apply Nimbus look and feel", ex);
}
new TableExample2(args[0], args[1], args[2], args[3], args[4]);
}
private static void runTest() {
try {
LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
for (LookAndFeelInfo info : lafInfo) {
UIManager.setLookAndFeel(info.getClassName());
for (Locale locale : LOCALES) {
for (String key : MNEMONIC_KEYS) {
int mnemonic = SwingUtilities2.getUIDefaultsInt(key, locale);
if (mnemonic != 0) {
throw new RuntimeException("No mnemonic expected (" + mnemonic + ") " +
"for '" + key + "' " +
"in locale '" + locale + "' " +
"in Look-and-Feel '"
+ UIManager.getLookAndFeel().getClass().getName() + "'");
}
}
}
}
System.out.println("Test passed");
} catch (Exception e) {
exception = e;
}
}
/**
* Sets the Look And Feel specified by its name.
*
* <p>
* This method does not log in case of errors, so can be called before the logger is initialized.
* </p>
*
* @param lafName name of the Look And Feel to be set
* @return the exception if any was thrown while setting the specified Look and Feel
*/
public static Exception setLaf( final String lafName ) {
final Holder< Exception > exception = new Holder< >();
runInEDT( new Runnable() {
@Override
public void run() {
for ( final LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels() )
if ( lafName.equals( lookAndFeelInfo.getName() ) ) {
try {
UIManager.setLookAndFeel( lookAndFeelInfo.getClassName() );
} catch ( final Exception e ) {
exception.value = e;
}
break;
}
}
} );
return exception.value;
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();
for (int i = 0, n = lookAndFeels.length; i < n; i++) {
if ("Nimbus".equals(lookAndFeels[i].getName())) {
try {
UIManager.setLookAndFeel(lookAndFeels[i].getClassName());
} catch (Exception ignored) {
}
break;
}
}
try {
new Hiero();
} catch (SlickException ex) {
throw new RuntimeException(ex);
}
}
});
}
public static void main(String[] args) {
// Trying to set Nimbus look and feel
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
Logger.getLogger(TableExample4.class.getName()).log(Level.SEVERE,
"Failed to apply Nimbus look and feel", ex);
}
new TableExample4();
}
public void run() {
int indent = 0;
try {
final String lnfName = WorkspaceSettings.getInstance().getLNF();
if ( !StringUtils.isEmpty( lnfName ) ) {
final LookAndFeelInfo[] lnfs = UIManager.getInstalledLookAndFeels();
for ( final LookAndFeelInfo lnf : lnfs ) {
if ( lnf.getName().equals( lnfName ) ) {
UIManager.setLookAndFeel( lnf.getClassName() );
return;
}
}
}
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
indent = 5; //PRD-4583
} catch ( Throwable t ) {
UncaughtExceptionsModel.getInstance().addException( t );
}
final UIDefaults uiDefaults = UIManager.getDefaults();
uiDefaults.put( "Table.gridColor", uiDefaults.get( "Panel.background" ) );// NON-NLS
uiDefaults.put( "Tree.leftChildIndent", indent );//PRD-4419
}
public void run() {
if (this.infos == null) {
this.infos = UIManager.getInstalledLookAndFeels();
Thread.currentThread().setUncaughtExceptionHandler(this);
JPanel panel = new JPanel();
panel.setBorder(this);
this.frame = new JFrame(getClass().getSimpleName());
this.frame.add(panel);
this.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.frame.setVisible(true);
}
if (this.index == this.infos.length) {
this.frame.dispose();
}
else {
LookAndFeelInfo info = this.infos[this.index % this.infos.length];
try {
UIManager.setLookAndFeel(info.getClassName());
}
catch (Exception exception) {
System.err.println("could not change look and feel");
}
SwingUtilities.updateComponentTreeUI(this.frame);
this.frame.pack();
this.frame.setLocationRelativeTo(null);
this.index++;
SwingUtilities.invokeLater(this);
}
}
@SuppressWarnings( "unchecked" )
public LookAndFeelsComboBox() {
setRenderer( new BasicComboBoxRenderer() {
@Override
@SuppressWarnings( "rawtypes" )
public Component getListCellRendererComponent( JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus )
{
value = (value != null)
? ((LookAndFeelInfo)value).getName()
: UIManager.getLookAndFeel().getName();
return super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus );
}
} );
}
public static boolean hasLAF(String name, LookAndFeelInfo[] lafInfo) {
for (int counter = 0; counter < lafInfo.length; counter++) {
if (lafInfo[counter].getName().toLowerCase().indexOf(name) != -1) {
return true;
}
}
return false;
}
public int getIndexOfLookAndFeel( String className ) {
ComboBoxModel<LookAndFeelInfo> model = getModel();
int size = model.getSize();
for( int i = 0; i < size; i++ ) {
if( className.equals( model.getElementAt( i ).getClassName() ) )
return i;
}
return -1;
}
public static void setLookAndFeel(String lafName) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException {
for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
if (lafName.equals(laf.getName())) {
UIManager.setLookAndFeel(laf.getClassName());
}
}
}
public static void main(String[] args) throws Exception {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
runTest();
break;
}
}
}
private static boolean checkAndSetNimbusLookAndFeel() {
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
return true;
}
}
return false;
} catch (Exception ignore) {
return false;
}
}
public static boolean hasLAF(String name, LookAndFeelInfo[] lafInfo) {
for (int counter = 0; counter < lafInfo.length; counter++) {
if (lafInfo[counter].getName().toLowerCase().indexOf(name) != -1) {
return true;
}
}
return false;
}
public static void main(String[] args) throws Exception {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
UIManager.put("FileChooser.openButtonMnemonic", KeyEvent.VK_O);
UIManager.put("FileChooser.saveButtonMnemonic", KeyEvent.VK_S);
runTest();
break;
}
}
}
public static void main(final String[] args) {
if (args.length > 0) {
switch (args[0]) {
case "sliceImage": {
System.exit(new SliceImageCmd().process(Arrays.copyOfRange(args, 1, args.length)));
}
break;
default: {
System.err.println("Unexpected command : " + args[0]);
System.exit(1);
}
}
}
java.util.Locale.setDefault(Locale.ROOT);
try {
for (final LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
SwingUtilities.invokeLater(() -> {
final JFrame frame = new MainFrame();
frame.setVisible(true);
});
}
public void run() {
if (this.infos == null) {
this.infos = UIManager.getInstalledLookAndFeels();
Thread.currentThread().setUncaughtExceptionHandler(this);
JPanel panel = new JPanel();
panel.setBorder(this);
this.frame = new JFrame(getClass().getSimpleName());
this.frame.add(panel);
this.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.frame.setVisible(true);
}
if (this.index == this.infos.length) {
this.frame.dispose();
}
else {
LookAndFeelInfo info = this.infos[this.index % this.infos.length];
try {
UIManager.setLookAndFeel(info.getClassName());
}
catch (Exception exception) {
System.err.println("could not change look and feel");
}
SwingUtilities.updateComponentTreeUI(this.frame);
this.frame.pack();
this.frame.setLocationRelativeTo(null);
this.index++;
SwingUtilities.invokeLater(this);
}
}
private void test() throws Exception {
Robot robot = new Robot();
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
UIManager.setLookAndFeel(info.getClassName());
SwingUtilities.invokeAndWait(this);
robot.waitForIdle(); // after creation
Thread.sleep(1000);
Point point = this.bar.getLocation();
SwingUtilities.convertPointToScreen(point, this.bar);
point.x += this.bar.getWidth() >> 2;
point.y += this.bar.getHeight() >> 1;
robot.mouseMove(point.x, point.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.waitForIdle(); // before validation
Thread.sleep(1000);
SwingUtilities.invokeAndWait(this);
if (this.bar != null) {
this.bar = null; // allows to reuse the instance
if (AUTO) { // error reporting only for automatic testing
throw new Error("TEST FAILED");
}
}
}
}
public synchronized void run() {
if (this.chooser == null) {
this.chooser = new JColorChooser();
JFrame frame = new JFrame(getClass().getName());
frame.add(this.chooser);
frame.setVisible(true);
}
else if (this.updated) {
if (isShowing(this.chooser.getPreviewPanel())) {
exit("custom preview panel is showing");
}
exit(null);
}
else {
Component component = this.chooser.getPreviewPanel();
if (component == null) {
component = getPreview(this.chooser);
}
if (!isShowing(component)) {
exit("default preview panel is not showing");
}
this.updated = true;
this.chooser.setPreviewPanel(new JPanel());
}
LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
LookAndFeelInfo info = infos[++this.index % infos.length];
try {
UIManager.setLookAndFeel(info.getClassName());
}
catch (Exception exception) {
exit("could not change L&F");
}
SwingUtilities.updateComponentTreeUI(this.chooser);
SwingUtilities.invokeLater(this);
}