Compare commits

...

13 Commits
0.11 ... 0.13

Author SHA1 Message Date
Karl Tauber
873e8604ce added developer information to Maven POM for Maven Central publishing 2019-10-13 21:37:49 +02:00
Karl Tauber
2cfcd0facf release 0.12 2019-10-13 17:53:36 +02:00
Karl Tauber
b49eff348d Linux: support KDE (#2)
The Swing fonts are not updated when the user changes system font size (System Settings > Fonts > Force Font DPI). A application restart is necessary. This is the same behavior as in native KDE applications.

tested on Kubuntu 19.04
2019-10-13 17:48:46 +02:00
Karl Tauber
42d801f123 Linux:
- allow user scaling mode on Linux even if running in Java 9+
- update fonts (and scaling) when user changes text size or scaling in Gnome settings

(#1)
2019-10-13 14:15:37 +02:00
Karl Tauber
5e33182de3 Windows: update fonts (and scaling) when user changes Windows text size 2019-10-12 20:14:18 +02:00
Karl Tauber
012d86066d UI inspector: fixed NPE and use anti-aliasing for painting line border on Java 9+ for better results when scaled 2019-10-12 13:43:43 +02:00
Karl Tauber
ff510095a3 UIScale: renamed some methods (to avoid confusion) 2019-10-12 13:42:05 +02:00
Karl Tauber
10283d022f Linux: initialize font (#2) 2019-10-12 10:44:11 +02:00
Karl Tauber
d55abd1b00 README.md: use SVG button for demo download 2019-10-10 11:15:19 +02:00
Karl Tauber
87845fc6f5 added Flat*Laf.install() methods 2019-10-10 10:34:40 +02:00
Karl Tauber
340c0d647c README.md: temporary removed jcenter coordinates because they currently do not work 2019-10-09 11:56:29 +02:00
Karl Tauber
49a574a8d7 macOS: use native screen menu bar if system property apple.laf.useScreenMenuBar is true 2019-10-08 23:41:51 +02:00
Karl Tauber
9216997bba screenshots updated 2019-10-08 23:32:26 +02:00
18 changed files with 442 additions and 53 deletions

View File

@@ -1,6 +1,21 @@
FlatLaf Change Log
==================
## 0.13
- Added developer information to Maven POM for Maven Central publishing.
## 0.12
- Support Linux. (issue #2)
- Added `Flat*Laf.install()` methods.
- macOS: Use native screen menu bar if system property
`apple.laf.useScreenMenuBar` is `true`.
- Windows: Update fonts (and scaling) when user changes Windows text size
(Settings > Ease of Access > Display > Make text bigger).
## 0.11
- Changed Maven groupId to `com.formdev` and artifactId to `flatlaf`.

View File

@@ -19,10 +19,10 @@ IntelliJ IDEA 2019.2+ and uses mostly the same colors and icons.
Demo
----
Download
[flatlaf-demo-0.11.jar](https://download.formdev.com/flatlaf/flatlaf-demo-0.11.jar)
and run it with `java -jar flatlaf-demo-0.11.jar` (or double-click it). Requires
Java 8 or newer.
[![Download Demo](https://download.formdev.com/flatlaf/images/download-demo.svg)](https://download.formdev.com/flatlaf/flatlaf-demo-latest.jar)
Run demo with `java -jar flatlaf-demo-<version>.jar` (or double-click it).
Requires Java 8 or newer.
Download
@@ -30,15 +30,11 @@ Download
[![Download](https://api.bintray.com/packages/jformdesigner/flatlaf/flatlaf/images/download.svg)](https://bintray.com/jformdesigner/flatlaf/flatlaf/_latestVersion)
For Maven or Gradle use:
Repository: jcenter (https://jcenter.bintray.com/)
Group Id: com.formdev
Artifact Id: flatlaf
Version: 0.11
Download from JCenter and Maven Central is coming soon.
License
-------
Documentation
-------------
FlatLaf is open source licensed under the [Apache 2.0 License](LICENSE)
For more information and documentation visit
[FlatLaf Home](https://www.formdev.com/flatlaf/)

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
version = "0.11"
version = "0.13"
// check required Java version
if( JavaVersion.current() < JavaVersion.VERSION_1_8 )

View File

@@ -117,6 +117,14 @@ publishing {
}
}
developers {
developer {
name.set( "Karl Tauber" )
organization.set( "FormDev Software GmbH" )
organizationUrl.set( "https://www.formdev.com/" )
}
}
scm {
url.set( "https://github.com/JFormDesigner/FlatLaf" )
}

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

@@ -21,6 +21,7 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
@@ -28,6 +29,8 @@ import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.AWTEventListener;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -39,9 +42,11 @@ 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;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.UIDefaults.LazyValue;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.DimensionUIResource;
@@ -70,9 +75,22 @@ public abstract class FlatLaf
private BasicLookAndFeel base;
private String desktopPropertyName;
private PropertyChangeListener desktopPropertyListener;
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();
@@ -100,10 +118,35 @@ public abstract class FlatLaf
altKeyChanged( e.getID() == KeyEvent.KEY_PRESSED );
};
Toolkit.getDefaultToolkit().addAWTEventListener( mnemonicListener, AWTEvent.KEY_EVENT_MASK );
// listen to desktop property changes to update UI if system font or scaling changes
if( SystemInfo.IS_WINDOWS ) {
// Windows 10 allows increasing font size independent of scaling:
// Settings > Ease of Access > Display > Make text bigger (100% - 225%)
desktopPropertyName = "win.messagebox.font";
} else if( SystemInfo.IS_LINUX ) {
// Linux/Gnome allows extra scaling and larger text:
// Settings > Devices > Displays > Scale (100% or 200%)
// Settings > Universal access > Large Text (off or on, 125%)
desktopPropertyName = "gnome.Xft/DPI";
}
if( desktopPropertyName != null ) {
desktopPropertyListener = e -> {
reSetLookAndFeel();
};
Toolkit.getDefaultToolkit().addPropertyChangeListener( desktopPropertyName, desktopPropertyListener );
}
}
@Override
public void uninitialize() {
// remove desktop property listener
if( desktopPropertyListener != null ) {
Toolkit.getDefaultToolkit().removePropertyChangeListener( desktopPropertyName, desktopPropertyListener );
desktopPropertyName = null;
desktopPropertyListener = null;
}
// remove mnemonic listener
if( mnemonicListener != null ) {
Toolkit.getDefaultToolkit().removeAWTEventListener( mnemonicListener );
@@ -157,9 +200,17 @@ public abstract class FlatLaf
defaults.put( "Spinner.disabledBackground", control );
defaults.put( "Spinner.disabledForeground", control );
// remember MenuBarUI from Mac Aqua LaF if Mac screen menubar is enabled
boolean useScreenMenuBar = SystemInfo.IS_MAC && "true".equals( System.getProperty( "apple.laf.useScreenMenuBar" ) );
Object aquaMenuBarUI = useScreenMenuBar ? defaults.get( "MenuBarUI" ) : null;
initFonts( defaults );
loadDefaultsFromProperties( defaults );
// use Aqua MenuBarUI if Mac screen menubar is enabled
if( useScreenMenuBar )
defaults.put( "MenuBarUI", aquaMenuBarUI );
return defaults;
}
@@ -182,7 +233,8 @@ public abstract class FlatLaf
uiFont = (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font );
} else if( SystemInfo.IS_LINUX ) {
System.err.println( "WARNING: FlatLaf is not yet tested on Linux!" );
Font font = LinuxFontPolicy.getFont();
uiFont = (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font );
}
if( uiFont == null )
@@ -458,6 +510,35 @@ public abstract class FlatLaf
return strs;
}
private static void reSetLookAndFeel() {
EventQueue.invokeLater( () -> {
try {
// re-set current LaF
LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
UIManager.setLookAndFeel( lookAndFeel );
// must fire property change events ourself because old and new LaF are the same
PropertyChangeEvent e = new PropertyChangeEvent( UIManager.class, "lookAndFeel", lookAndFeel, lookAndFeel );
for( PropertyChangeListener l : UIManager.getPropertyChangeListeners() )
l.propertyChange( e );
// update UI
updateUI();
} catch( UnsupportedLookAndFeelException ex ) {
ex.printStackTrace();
}
} );
}
/**
* Update UI of all application windows.
* Invoke after changing LaF.
*/
public static void updateUI() {
for( Window w : Window.getWindows() )
SwingUtilities.updateComponentTreeUI( w );
}
public static boolean isShowMnemonics() {
return altKeyPressed || !UIManager.getBoolean( "Component.hideMnemonics" );
}

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

@@ -0,0 +1,248 @@
/*
* Copyright 2019 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
import javax.swing.text.StyleContext;
import com.formdev.flatlaf.util.SystemInfo;
/**
* @author Karl Tauber
*/
class LinuxFontPolicy
{
static Font getFont() {
return SystemInfo.IS_KDE ? getKDEFont() : getGnomeFont();
}
/**
* Gets the default font for Gnome.
*/
private static Font getGnomeFont() {
// see class com.sun.java.swing.plaf.gtk.PangoFonts background information
Object fontName = Toolkit.getDefaultToolkit().getDesktopProperty( "gnome.Gtk/FontName" );
if( !(fontName instanceof String) )
fontName = "sans 10";
String family = "";
int style = Font.PLAIN;
int size = 10;
StringTokenizer st = new StringTokenizer( (String) fontName );
while( st.hasMoreTokens() ) {
String word = st.nextToken();
if( word.equalsIgnoreCase( "italic" ) )
style |= Font.ITALIC;
else if( word.equalsIgnoreCase( "bold" ) )
style |= Font.BOLD;
else if( Character.isDigit( word.charAt( 0 ) ) ) {
try {
size = Integer.parseInt( word );
} catch( NumberFormatException ex ) {
// ignore
}
} else
family = family.isEmpty() ? word : (family + ' ' + word);
}
// scale font size
double dsize = size * getGnomeFontScale();
size = (int) (dsize + 0.5);
if( size < 1 )
size = 1;
// handle logical font names
String logicalFamily = mapFcName( family.toLowerCase() );
if( logicalFamily != null )
family = logicalFamily;
return createFont( family, style, size, dsize );
}
private static Font createFont( String family, int style, int size, double dsize ) {
// using StyleContext.getFont() here because it uses
// sun.font.FontUtilities.getCompositeFontUIResource()
Font font = new StyleContext().getFont( family, style, size );
// set font size in floating points
font = font.deriveFont( style, (float) dsize );
return font;
}
private static double getGnomeFontScale() {
// see class com.sun.java.swing.plaf.gtk.PangoFonts background information
Object value = Toolkit.getDefaultToolkit().getDesktopProperty( "gnome.Xft/DPI" );
if( value instanceof Integer ) {
int dpi = ((Integer)value).intValue() / 1024;
if( dpi == -1 )
dpi = 96;
if( dpi < 50 )
dpi = 50;
return dpi / 72.0;
} else {
return GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration()
.getNormalizingTransform().getScaleY();
}
}
/**
* map GTK/fontconfig names to equivalent JDK logical font name
*/
private static String mapFcName( String name ) {
switch( name ) {
case "sans": return "sansserif";
case "sans-serif": return "sansserif";
case "serif": return "serif";
case "monospace": return "monospaced";
}
return null;
}
/**
* Gets the default font for KDE for KDE configuration files.
*
* The Swing fonts are not updated when the user changes system font size
* (System Settings > Fonts > Force Font DPI). A application restart is necessary.
* This is the same behavior as in native KDE applications.
*
* The "display scale factor" (kdeglobals: [KScreen] > ScaleFactor) is not used
* KDE also does not use it to calculate font size. Only forceFontDPI is used by KDE.
* If user changes "display scale factor" (System Settings > Display and Monitors >
* Displays > Scale Display), the forceFontDPI is also changed to reflect the scale factor.
*/
private static Font getKDEFont() {
List<String> kdeglobals = readConfig( "kdeglobals" );
List<String> kcmfonts = readConfig( "kcmfonts" );
String generalFont = getConfigEntry( kdeglobals, "General", "font" );
String forceFontDPI = getConfigEntry( kcmfonts, "General", "forceFontDPI" );
String family = "sansserif";
int style = Font.PLAIN;
int size = 10;
if( generalFont != null ) {
List<String> strs = FlatLaf.split( generalFont, ',' );
try {
family = strs.get( 0 );
size = Integer.parseInt( strs.get( 1 ) );
if( "75".equals( strs.get( 4 ) ) )
style |= Font.BOLD;
if( "1".equals( strs.get( 5 ) ) )
style |= Font.ITALIC;
} catch( RuntimeException ex ) {
ex.printStackTrace();
}
}
// font dpi
int dpi = 96;
if( forceFontDPI != null ) {
try {
dpi = Integer.parseInt( forceFontDPI );
if( dpi <= 0 )
dpi = 96;
if( dpi < 50 )
dpi = 50;
} catch( NumberFormatException ex ) {
ex.printStackTrace();
}
}
// scale font size
double fontScale = dpi / 72.0;
double dsize = size * fontScale;
size = (int) (dsize + 0.5);
if( size < 1 )
size = 1;
return createFont( family, style, size, dsize );
}
private static List<String> readConfig( String filename ) {
File userHome = new File( System.getProperty( "user.home" ) );
// search for config file
String[] configDirs = {
".config", // KDE 5
".kde4/share/config", // KDE 4
".kde/share/config"// KDE 3
};
File file = null;
for( String configDir : configDirs ) {
file = new File( userHome, configDir + "/" + filename );
if( file.isFile() )
break;
}
if( !file.isFile() )
return Collections.emptyList();
// read config file
ArrayList<String> lines = new ArrayList<>( 200 );
try( BufferedReader reader = new BufferedReader( new FileReader( file ) ) ) {
String line = null;
while( (line = reader.readLine()) != null )
lines.add( line );
} catch( IOException ex ) {
ex.printStackTrace();
}
return lines;
}
private static String getConfigEntry( List<String> config, String group, String key ) {
int groupLength = group.length();
int keyLength = key.length();
boolean inGroup = false;
for( String line : config ) {
if( !inGroup ) {
if( line.length() >= groupLength + 2 &&
line.charAt( 0 ) == '[' &&
line.charAt( groupLength + 1 ) == ']' &&
line.indexOf( group ) == 1 )
{
inGroup = true;
}
} else {
if( line.startsWith( "[" ) )
return null;
if( line.length() >= keyLength + 2 &&
line.charAt( keyLength ) == '=' &&
line.startsWith( key ) )
{
return line.substring( keyLength + 1 );
}
}
}
return null;
}
}

View File

@@ -40,6 +40,9 @@ public class SystemInfo
// Java VMs
public static final boolean IS_JETBRAINS_JVM;
// UI toolkits
public static final boolean IS_KDE;
static {
// platforms
String osName = System.getProperty( "os.name" ).toLowerCase( Locale.ENGLISH );
@@ -58,6 +61,9 @@ public class SystemInfo
// Java VMs
IS_JETBRAINS_JVM = System.getProperty( "java.vm.vendor", "Unknown" )
.toLowerCase( Locale.ENGLISH ).contains( "jetbrains" );
// UI toolkits
IS_KDE = (IS_LINUX && System.getenv( "KDE_FULL_SESSION" ) != null);
}
private static long scanVersion( String version ) {

View File

@@ -48,8 +48,7 @@ import javax.swing.plaf.UIResource;
*
* 2) user scaling mode
*
* This mode is for Java 8 compatibility and can be removed when changing minimum
* required Java version to 9.
* This mode is mainly for Java 8 compatibility, but is also used on Linux.
* The user scale factor is computed based on the used font.
* The JRE does not scale anything.
* So we have to invoke {@link #scale(float)} where necessary.
@@ -66,7 +65,7 @@ public class UIScale
private static Boolean jreHiDPI;
public static boolean isJreHiDPIEnabled() {
public static boolean isSystemScalingEnabled() {
if( jreHiDPI != null )
return jreHiDPI;
@@ -94,11 +93,11 @@ public class UIScale
}
public static double getSystemScaleFactor( Graphics2D g ) {
return isJreHiDPIEnabled() ? g.getDeviceConfiguration().getDefaultTransform().getScaleX() : 1;
return isSystemScalingEnabled() ? g.getDeviceConfiguration().getDefaultTransform().getScaleX() : 1;
}
public static double getSystemScaleFactor( GraphicsConfiguration gc ) {
return isJreHiDPIEnabled() ? gc.getDefaultTransform().getScaleX() : 1;
return isSystemScalingEnabled() ? gc.getDefaultTransform().getScaleX() : 1;
}
//---- user scaling (Java 8) ----------------------------------------------
@@ -111,7 +110,7 @@ public class UIScale
return;
initialized = true;
if( isEnabled() ) {
if( isUserScalingEnabled() ) {
// listener to update scale factor if LaF changed or if Label.font changed
// (e.g. option "Override default fonts" in IntelliJ IDEA)
PropertyChangeListener listener = new PropertyChangeListener() {
@@ -135,7 +134,7 @@ public class UIScale
}
private static void updateScaleFactor() {
if( !isEnabled() )
if( !isUserScalingEnabled() )
return;
// use font size to calculate scale factor (instead of DPI)
@@ -158,15 +157,15 @@ public class UIScale
if( "Tahoma".equals( font.getFamily() ) )
fontSizeDivider = 11f;
} else if( SystemInfo.IS_LINUX ) {
// default font size for Unity and Gnome is 15
fontSizeDivider = 15f;
// default font size for Unity and Gnome is 15 and for KDE it is 13
fontSizeDivider = SystemInfo.IS_KDE ? 13f : 15f;
}
return font.getSize() / fontSizeDivider;
}
private static boolean isEnabled() {
if( isJreHiDPIEnabled() )
private static boolean isUserScalingEnabled() {
if( isSystemScalingEnabled() && !SystemInfo.IS_LINUX )
return false; // disable user scaling if JRE scales
// same as in IntelliJ IDEA
@@ -179,7 +178,7 @@ public class UIScale
* or "sun.java2d.uiScale" to the given font.
*/
public static FontUIResource applyCustomScaleFactor( FontUIResource font ) {
if( UIScale.isJreHiDPIEnabled() )
if( UIScale.isSystemScalingEnabled() )
return font;
String uiScale = System.getProperty( "flatlaf.uiScale" );

View File

@@ -23,6 +23,7 @@ import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
@@ -41,6 +42,7 @@ import javax.swing.border.LineBorder;
import javax.swing.plaf.UIResource;
import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.ui.FlatToolTipUI;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.UIScale;
/**
@@ -103,7 +105,7 @@ public class FlatInspector
private void inspect( int x, int y ) {
Container contentPane = rootPane.getContentPane();
Component c = SwingUtilities.getDeepestComponentAt( contentPane, x, y );
if( c == contentPane || c.getParent() == contentPane )
if( c == contentPane || (c != null && c.getParent() == contentPane) )
c = null;
if( c == lastComponent )
@@ -137,6 +139,12 @@ public class FlatInspector
g.setColor( getBackground() );
g.fillRect( 0, 0, getWidth(), getHeight() );
}
@Override
protected void paintBorder( Graphics g ) {
FlatUIUtils.setRenderingHints( (Graphics2D) g );
super.paintBorder( g );
}
};
c.setBackground( new Color( 255, 0, 0, 32 ) );
c.setBorder( new LineBorder( Color.red ) );

View File

@@ -22,6 +22,8 @@ import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.prefs.Preferences;
import javax.swing.*;
import javax.swing.plaf.ColorUIResource;
@@ -68,11 +70,7 @@ public class FlatTestFrame
ex.printStackTrace();
// fallback
try {
UIManager.setLookAndFeel( new FlatLightLaf() );
} catch( Exception ex2 ) {
ex2.printStackTrace();
}
FlatLightLaf.install();
}
// create frame
@@ -101,7 +99,8 @@ public class FlatTestFrame
continue;
if( (SystemInfo.IS_WINDOWS && className.equals( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" )) ||
(SystemInfo.IS_MAC && className.equals( "com.apple.laf.AquaLookAndFeel") ) )
(SystemInfo.IS_MAC && className.equals( "com.apple.laf.AquaLookAndFeel") ) ||
(SystemInfo.IS_LINUX && className.equals( "com.sun.java.swing.plaf.gtk.GTKLookAndFeel") ) )
name += " (F9)";
else if( className.equals( MetalLookAndFeel.class.getName() ) )
name += " (F10)";
@@ -139,6 +138,8 @@ public class FlatTestFrame
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
else if( SystemInfo.IS_MAC )
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.apple.laf.AquaLookAndFeel" );
else if( SystemInfo.IS_LINUX )
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" );
registerSwitchToLookAndFeel( KeyEvent.VK_F10, MetalLookAndFeel.class.getName() );
registerSwitchToLookAndFeel( KeyEvent.VK_F11, NimbusLookAndFeel.class.getName() );
@@ -168,6 +169,18 @@ public class FlatTestFrame
updateTitle();
}
} );
UIManager.addPropertyChangeListener( e -> {
if( "lookAndFeel".equals( e.getPropertyName() ) ) {
EventQueue.invokeLater( () -> {
// update title because user scale factor may change
updateTitle();
// enable/disable scale factor combobox
updateScaleFactorComboBox();
} );
}
} );
}
private void updateTitle() {
@@ -234,14 +247,8 @@ public class FlatTestFrame
// change look and feel
UIManager.setLookAndFeel( lafClassName );
// update title because user scale factor may change
updateTitle();
// enable/disable scale factor combobox
updateScaleFactorComboBox();
// update all components
SwingUtilities.updateComponentTreeUI( this );
FlatLaf.updateUI();
// increase size of frame if necessary
if( pack )
@@ -394,7 +401,7 @@ public class FlatTestFrame
}
private void updateScaleFactorComboBox() {
scaleFactorComboBox.setEnabled( !UIScale.isJreHiDPIEnabled() && UIManager.getLookAndFeel() instanceof FlatLaf );
scaleFactorComboBox.setEnabled( !UIScale.isSystemScalingEnabled() && UIManager.getLookAndFeel() instanceof FlatLaf );
}
private void initComponents() {

View File

@@ -58,7 +58,8 @@ class ControlBar
continue;
if( (SystemInfo.IS_WINDOWS && className.equals( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" )) ||
(SystemInfo.IS_MAC && className.equals( "com.apple.laf.AquaLookAndFeel") ) )
(SystemInfo.IS_MAC && className.equals( "com.apple.laf.AquaLookAndFeel") ) ||
(SystemInfo.IS_LINUX && className.equals( "com.sun.java.swing.plaf.gtk.GTKLookAndFeel") ) )
name += " (F9)";
else if( className.equals( MetalLookAndFeel.class.getName() ) )
name += " (F10)";
@@ -78,6 +79,15 @@ class ControlBar
lafModel.setSelectedItem( lafModel.getElementAt( sel ) );
lookAndFeelComboBox.setModel( lafModel );
UIManager.addPropertyChangeListener( e -> {
if( "lookAndFeel".equals( e.getPropertyName() ) ) {
EventQueue.invokeLater( () -> {
// update info label because user scale factor may change
updateInfoLabel();
} );
}
} );
}
void initialize( JFrame frame, JTabbedPane tabbedPane ) {
@@ -94,6 +104,8 @@ class ControlBar
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
else if( SystemInfo.IS_MAC )
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.apple.laf.AquaLookAndFeel" );
else if( SystemInfo.IS_LINUX )
registerSwitchToLookAndFeel( KeyEvent.VK_F9, "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" );
registerSwitchToLookAndFeel( KeyEvent.VK_F10, MetalLookAndFeel.class.getName() );
registerSwitchToLookAndFeel( KeyEvent.VK_F11, NimbusLookAndFeel.class.getName() );
@@ -170,11 +182,8 @@ class ControlBar
// change look and feel
UIManager.setLookAndFeel( newLaf.className );
// update info label because user scale factor may change
updateInfoLabel();
// update all components
SwingUtilities.updateComponentTreeUI( frame );
FlatLaf.updateUI();
// increase size of frame if necessary
int width = frame.getWidth();

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB