added Flat*Laf.install() methods

This commit is contained in:
Karl Tauber
2019-10-09 12:56:56 +02:00
parent 340c0d647c
commit 87845fc6f5
8 changed files with 30 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ FlatLaf Change Log
## Unreleased
- Added `Flat*Laf.install()` methods.
- macOS: Use native screen menu bar if system property
`apple.laf.useScreenMenuBar` is `true`.

View File

@@ -24,6 +24,10 @@ package com.formdev.flatlaf;
public class FlatDarculaLaf
extends FlatDarkLaf
{
public static boolean install( ) {
return install( new FlatDarculaLaf() );
}
@Override
public String getName() {
return "Flat Darcula";

View File

@@ -24,6 +24,10 @@ package com.formdev.flatlaf;
public class FlatDarkLaf
extends FlatLaf
{
public static boolean install( ) {
return install( new FlatDarkLaf() );
}
@Override
public String getName() {
return "Flat Dark";

View File

@@ -24,6 +24,10 @@ package com.formdev.flatlaf;
public class FlatIntelliJLaf
extends FlatLightLaf
{
public static boolean install( ) {
return install( new FlatIntelliJLaf() );
}
@Override
public String getName() {
return "Flat IntelliJ";

View File

@@ -39,6 +39,7 @@ import java.util.function.Function;
import javax.swing.AbstractButton;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
@@ -73,6 +74,16 @@ public abstract class FlatLaf
private AWTEventListener mnemonicListener;
private static boolean altKeyPressed;
public static boolean install( LookAndFeel newLookAndFeel ) {
try {
UIManager.setLookAndFeel( newLookAndFeel );
return true;
} catch( Exception ex ) {
System.err.println( "Failed to initialize look and feel " + newLookAndFeel.getClass().getName() );
return false;
}
}
@Override
public String getID() {
return getName();

View File

@@ -24,6 +24,10 @@ package com.formdev.flatlaf;
public class FlatLightLaf
extends FlatLaf
{
public static boolean install( ) {
return install( new FlatLightLaf() );
}
@Override
public String getName() {
return "Flat Light";

View File

@@ -68,11 +68,7 @@ public class FlatTestFrame
ex.printStackTrace();
// fallback
try {
UIManager.setLookAndFeel( new FlatLightLaf() );
} catch( Exception ex2 ) {
ex2.printStackTrace();
}
FlatLightLaf.install();
}
// create frame

View File

@@ -46,11 +46,7 @@ public class FlatLafDemo
ex.printStackTrace();
// fallback
try {
UIManager.setLookAndFeel( new FlatLightLaf() );
} catch( Exception ex2 ) {
ex2.printStackTrace();
}
FlatLightLaf.install();
}
// create frame