FlatLaf 是用于 Java Swing 桌面應(yīng)用程序的現(xiàn)代開源跨平臺(tái)外觀。
它看起來幾乎是平的(沒有陰影或漸變)、干凈、簡(jiǎn)單和優(yōu)雅。 FlatLaf 帶有 Light、Dark、IntelliJ 和 Darcula 主題,可在 HiDPI 顯示器上縮放并在 Java 8 或更高版本上運(yùn)行。
外觀的靈感來自 IntelliJ IDEA 2019.2+ 的 Darcula 和 IntelliJ 主題,并使用幾乎相同的顏色和圖標(biāo)。
要啟用 FlatLaf,請(qǐng)?jiān)趧?chuàng)建任何 Swing 組件之前將以下代碼添加到 main 方法中:
FlatLightLaf.setup();
// create UI here...
或
try {
UIManager.setLookAndFeel( new FlatLightLaf() );
} catch( Exception ex ) {
System.err.println( "Failed to initialize LaF" );
}
// create UI here...
平光
扁平智能
平暗
扁Darcula
基于 IntelliJ 平臺(tái)的產(chǎn)品(例如 IntelliJ IDEA 或 WebStorm)通過插件支持 3rd 方主題,這些插件在內(nèi)部使用 JSON 文件(擴(kuò)展名為 .theme.json)來描述 UI 主題。
FlatLaf 支持加載此類 3rd 方 .theme.json 文件并將它們用作 Laf。
FlatLaf 的這個(gè)插件將來自 JetBrains 插件庫的許多流行的開源 3rd 方主題捆綁到一個(gè) JAR 中,并提供 Java 類來使用它們。
使用 FlatLaf Demo 試用它們。
如果您使用 Maven 或 Gradle,請(qǐng)將具有以下坐標(biāo)的依賴項(xiàng)添加到您的構(gòu)建腳本中:
groupId: com.formdev
artifactId: flatlaf-intellij-themes
version: (see button below)
使用 FlatLaf 演示,它捆綁了來自 JetBrains 插件存儲(chǔ)庫的許多流行的開源 3rd 方主題,可以試用它們。
您還可以轉(zhuǎn)到 JetBrains 插件庫并在 plugins.jetbrains.com/search?tags=Theme 上瀏覽可用的 IntelliJ 主題插件。 如果你找到了一個(gè)好的,點(diǎn)擊主題頁面底部的“源代碼”鏈接,它會(huì)將你重定向到主題的源代碼存儲(chǔ)庫。 您可以在那里搜索 .theme.json 文件并下載它。
提示:如果您將 .theme.json 文件復(fù)制到與 FlatLaf 演示 JAR 相同的文件夾中,您可以在演示中嘗試此主題。 從主題列表的“當(dāng)前目錄”部分選擇主題。
如何使用第 3 方 IntelliJ 主題?
要在您的應(yīng)用程序中使用 .theme.json 文件(該文件未包含在 FlatLaf IntelliJ 主題包中),請(qǐng)將其保存在應(yīng)用程序的資源(或 src)文件夾中的某個(gè)位置,并使用以下代碼加載和初始化它:
IntelliJTheme.setup( MyApp.class.getResourceAsStream(
"/com/myapp/themes/arc-theme-orange.theme.json" ) );
// create UI here...
您可以通過設(shè)置 UI 默認(rèn)值在一定程度上自定義 FlatLaf 的外觀:
UIManager.put( "someKey", someValue );
默認(rèn)情況下,按鈕、切換按鈕、組合框和微調(diào)器使用圓角。 如果您更喜歡方角,請(qǐng)使用:
Java Properties
UIManager.put( "Button.arc", 0 );
UIManager.put( "Component.arc", 0 );
UIManager.put( "CheckBox.arc", 0 );
UIManager.put( "ProgressBar.arc", 0 );
Button.arc 是按鈕和切換按鈕的角弧直徑(默認(rèn)為 6),Component.arc 用于其他組件,如組合框和微調(diào)器(默認(rèn)為 5),CheckBox.arc 用于復(fù)選框圖標(biāo)(默認(rèn)為 4) ProgressBar.arc 用于進(jìn)度條(默認(rèn)為 4)。
默認(rèn)情況下,文本字段使用方角。 如果您更喜歡圓角,請(qǐng)使用:
Java Properties
UIManager.put( "TextComponent.arc", 5 );
對(duì) arc 使用大值以獲得“圓形”組件:
Java Properties
UIManager.put( "Button.arc", 999 );
UIManager.put( "Component.arc", 999 );
UIManager.put( "ProgressBar.arc", 999 );
UIManager.put( "TextComponent.arc", 999 );
您還可以通過以下方式在單個(gè)組件上啟用圓角:
myButton.putClientProperty( "JButton.buttonType", "roundRect" );
myComboBox.putClientProperty( "JComponent.roundRect", true );
mySpinner.putClientProperty( "JComponent.roundRect", true );
myTextField.putClientProperty( "JComponent.roundRect", true );

雪佛龍

三角形
一些組件(例如組合框、微調(diào)器、樹等)使用箭頭。 FlatLaf 支持兩種類型的箭頭:人字形和三角形。
要更改 FlatLaf 中所有箭頭的箭頭類型,請(qǐng)使用:
Java Properties
UIManager.put( "Component.arrowType", "chevron" );
or
UIManager.put( "Component.arrowType", "triangle" );
FlatLaf 中的大多數(shù)可聚焦組件(例如按鈕、組合框、文本字段等)都用特殊邊框表示聚焦?fàn)顟B(tài)。 Flat Light 和 Flat Dark 主題在現(xiàn)有邊框上使用不同的顏色(外焦點(diǎn)寬度為 0)。 另一方面,F(xiàn)lat IntelliJ 和 Flat Darcula 主題使用寬度為 2 的外邊框,這些邊框繪制在組件的外部。
您可以通過以下方式控制所有主題中外部焦點(diǎn)邊框的寬度:
Java Properties
UIManager.put( "Component.focusWidth", 1 );
注意:使用外部焦點(diǎn)邊框會(huì)增加組件的大小。
除了外部焦點(diǎn)邊框,F(xiàn)latLaf 還支持內(nèi)部焦點(diǎn)邊框,不會(huì)增加組件的大小。 默認(rèn)內(nèi)部焦點(diǎn)寬度為 0。
您可以使用以下方法更改內(nèi)部焦點(diǎn)寬度:
Java Properties
UIManager.put( "Component.innerFocusWidth", 1 );
默認(rèn)情況下,助記符是隱藏的,按下 Alt 鍵時(shí)會(huì)顯示。 要使助記符始終可見,請(qǐng)使用:
Java Properties
UIManager.put( "Component.hideMnemonics", false );
默認(rèn)情況下隱藏滾動(dòng)條的上一個(gè)/下一個(gè)箭頭按鈕。 要使它們對(duì)應(yīng)用程序中的所有滾動(dòng)條可見,請(qǐng)使用:
Java Properties
UIManager.put( "ScrollBar.showButtons", true );
或者在單個(gè)組件(JScrollPane 或 JScrollBar)上啟用它們:
myScrollPane.putClientProperty( "JScrollBar.showButtons", true );
or
myScrollBar.putClientProperty( "JScrollBar.showButtons", true );
滾動(dòng)條的默認(rèn)寬度為 10。要使其更寬(或更?。?,請(qǐng)使用:
Java Properties
UIManager.put( "ScrollBar.width", 16 );
拇指插圖在拇指周圍添加空白空間:
Java Properties
UIManager.put( "ScrollBar.thumbInsets", new Insets( 2, 2, 2, 2 ) );
軌道插入在軌道周圍添加空白空間:
Java Properties
UIManager.put( "ScrollBar.trackInsets", new Insets( 2, 4, 2, 4 ) );
UIManager.put( "ScrollBar.thumbInsets", new Insets( 2, 2, 2, 2 ) );
UIManager.put( "ScrollBar.track", new Color( 0xe0e0e0 ) );
注意:必須為垂直滾動(dòng)條指定軌道和拇指插入。 它們?yōu)樗綕L動(dòng)條旋轉(zhuǎn)。
拇指可以四舍五入:
Java Properties
UIManager.put( "ScrollBar.thumbArc", 3 );
UIManager.put( "ScrollBar.thumbInsets", new Insets( 2, 2, 2, 2 ) );
或圓:
Java Properties
UIManager.put( "ScrollBar.thumbArc", 999 );
UIManager.put( "ScrollBar.thumbInsets", new Insets( 2, 2, 2, 2 ) );
軌道也可以是圓形的:
Java Properties
UIManager.put( "ScrollBar.trackArc", 999 );
UIManager.put( "ScrollBar.thumbArc", 999 );
UIManager.put( "ScrollBar.trackInsets", new Insets( 2, 4, 2, 4 ) );
UIManager.put( "ScrollBar.thumbInsets", new Insets( 2, 2, 2, 2 ) );
UIManager.put( "ScrollBar.track", new Color( 0xe0e0e0 ) );
選項(xiàng)卡式窗格
制表符分隔符
可以在選項(xiàng)卡之間顯示分隔線:
Java Properties
UIManager.put( "TabbedPane.showTabSeparators", true );
如果您喜歡這種外觀,分隔線可以全高:
Java Properties
UIManager.put( "TabbedPane.tabSeparatorsFullHeight", true );
所選標(biāo)簽背景
要使所選標(biāo)簽脫穎而出,請(qǐng)更改所選標(biāo)簽背景:
Java Properties
UIManager.put( "TabbedPane.selectedBackground", Color.white );
京ICP備09015132號(hào)-996 | 違法和不良信息舉報(bào)電話:4006561155
© Copyright 2000-2026 北京哲想軟件有限公司版權(quán)所有 | 地址:北京市海淀區(qū)西三環(huán)北路50號(hào)豪柏大廈C2座11層1105室
北京哲想軟件集團(tuán)旗下網(wǎng)站:哲想軟件 | 哲想動(dòng)畫