mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 22:40:53 +03:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8df8c9631 | ||
|
|
f61a7288eb | ||
|
|
47a1122f04 | ||
|
|
e1bfabbce5 | ||
|
|
9708fec0e0 | ||
|
|
7f4efaf0a3 | ||
|
|
269eb0ba29 | ||
|
|
7dac3825d7 | ||
|
|
6c0b122fbc | ||
|
|
4da2bd90cb | ||
|
|
cb70fb4e82 | ||
|
|
2593a43d72 | ||
|
|
e44ff5b72a | ||
|
|
22cb1b50a6 |
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@@ -34,6 +34,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: gradle/wrapper-validation-action@v1
|
||||
if: matrix.java == '1.8'
|
||||
|
||||
- name: Setup Java ${{ matrix.java }}
|
||||
uses: actions/setup-java@v1
|
||||
@@ -72,7 +73,7 @@ jobs:
|
||||
needs: build
|
||||
if: |
|
||||
github.event_name == 'push' &&
|
||||
github.ref == 'refs/heads/main' &&
|
||||
(github.ref == 'refs/heads/main' || startsWith( github.ref, 'refs/heads/develop-' )) &&
|
||||
github.repository == 'JFormDesigner/FlatLaf'
|
||||
|
||||
steps:
|
||||
|
||||
38
CHANGELOG.md
38
CHANGELOG.md
@@ -1,6 +1,44 @@
|
||||
FlatLaf Change Log
|
||||
==================
|
||||
|
||||
## 1.6.5
|
||||
|
||||
#### Fixed bugs
|
||||
|
||||
- Linux: Fixed font problems when running on Oracle Java (OpenJDK is not
|
||||
affected):
|
||||
- oversized text if system font is "Inter" (issue #427)
|
||||
- missing text if system font is "Cantarell" (on Fedora)
|
||||
- MenuItem: Changed accelerator delimiter from `-` to `+`. (Windows and Linux).
|
||||
- ComboBox: Fixed occasional `StackOverflowError` when modifying combo box not
|
||||
on AWT thread. (issue #432)
|
||||
- macOS: Fixed `NullPointerException` when using AWT component
|
||||
`java.awt.Choice`. (issue #439)
|
||||
- Native window decorations: Do not exit application with `UnsatisfiedLinkError`
|
||||
in case that FlatLaf DLL cannot be executed because of restrictions on
|
||||
temporary directory. Instead, continue with default window decorations. (issue
|
||||
#436)
|
||||
|
||||
|
||||
## 1.6.4
|
||||
|
||||
#### Fixed bugs
|
||||
|
||||
- ComboBox: Fixed regression in FlatLaf 1.6.3 that makes selected item invisible
|
||||
in popup list if `DefaultListCellRenderer` is used as renderer. If using
|
||||
default renderer, it works. (issue #426)
|
||||
|
||||
|
||||
## 1.6.3
|
||||
|
||||
#### Fixed bugs
|
||||
|
||||
- ComboBox (not editable): Fixed regression in FlatLaf 1.6.2 that may display
|
||||
text in non-editable combo boxes in bold. (issue #423)
|
||||
- Tree: Fixed editing cell issue with custom cell renderer and cell editor that
|
||||
use same component for rendering and editing. (issue #385)
|
||||
|
||||
|
||||
## 1.6.2
|
||||
|
||||
#### Fixed bugs
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
val releaseVersion = "1.6.2"
|
||||
val developmentVersion = "2.0-SNAPSHOT"
|
||||
val releaseVersion = "1.6.5"
|
||||
val developmentVersion = "1.6.6-SNAPSHOT"
|
||||
|
||||
version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.PopupFactory;
|
||||
import javax.swing.RootPaneContainer;
|
||||
@@ -878,12 +879,23 @@ public abstract class FlatLaf
|
||||
|
||||
/**
|
||||
* Revalidate and repaint all displayable frames and dialogs.
|
||||
* <p>
|
||||
* Useful to update UI after changing {@code TitlePane.menuBarEmbedded}.
|
||||
*
|
||||
* @since 1.1.2
|
||||
*/
|
||||
public static void revalidateAndRepaintAllFramesAndDialogs() {
|
||||
for( Window w : Window.getWindows() ) {
|
||||
if( isDisplayableFrameOrDialog( w ) ) {
|
||||
// revalidate menu bar
|
||||
JMenuBar menuBar = (w instanceof JFrame)
|
||||
? ((JFrame)w).getJMenuBar()
|
||||
: (w instanceof JDialog
|
||||
? ((JDialog)w).getJMenuBar()
|
||||
: null);
|
||||
if( menuBar != null )
|
||||
menuBar.revalidate();
|
||||
|
||||
w.revalidate();
|
||||
w.repaint();
|
||||
}
|
||||
@@ -892,6 +904,9 @@ public abstract class FlatLaf
|
||||
|
||||
/**
|
||||
* Repaint all displayable frames and dialogs.
|
||||
* <p>
|
||||
* Useful to update UI after changing {@code TitlePane.unifiedBackground},
|
||||
* {@code MenuItem.selectionType} or {@code Component.hideMnemonics}.
|
||||
*
|
||||
* @since 1.1.2
|
||||
*/
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.formdev.flatlaf;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Toolkit;
|
||||
@@ -28,7 +29,7 @@ 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.LoggingFacade;
|
||||
import com.formdev.flatlaf.util.StringUtils;
|
||||
import com.formdev.flatlaf.util.SystemInfo;
|
||||
@@ -121,14 +122,25 @@ class LinuxFontPolicy
|
||||
for(;;) {
|
||||
Font font = createFont( family, style, size, dsize );
|
||||
|
||||
// if the font family does not match any font on the system, "Dialog" family is returned
|
||||
if( !"Dialog".equals( font.getFamily() ) || "Dialog".equals( family ) )
|
||||
if( Font.DIALOG.equals( family ) )
|
||||
return font;
|
||||
|
||||
// if the font family does not match any font on the system, "Dialog" family is returned
|
||||
if( !Font.DIALOG.equals( font.getFamily() ) ) {
|
||||
// check for font problems
|
||||
// - font height much larger than expected (e.g. font Inter; Oracle Java 8)
|
||||
// - character width is zero (e.g. font Cantarell; Fedora; Oracle Java 8)
|
||||
FontMetrics fm = StyleContext.getDefaultStyleContext().getFontMetrics( font );
|
||||
if( fm.getHeight() > size * 2 || fm.stringWidth( "a" ) == 0 )
|
||||
return createFont( Font.DIALOG, style, size, dsize );
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
// find last word in family
|
||||
int index = family.lastIndexOf( ' ' );
|
||||
if( index < 0 )
|
||||
return createFont( "Dialog", style, size, dsize );
|
||||
return createFont( Font.DIALOG, style, size, dsize );
|
||||
|
||||
// check whether last work contains some font weight (e.g. Ultra-Bold or Heavy)
|
||||
String lastWord = family.substring( index + 1 ).toLowerCase();
|
||||
|
||||
@@ -260,7 +260,10 @@ public class FlatComboBoxUI
|
||||
public void layoutContainer( Container parent ) {
|
||||
super.layoutContainer( parent );
|
||||
|
||||
if( arrowButton != null ) {
|
||||
// on macOS, a Swing combo box is used for AWT component java.awt.Choice
|
||||
// and the font may be (temporary) null
|
||||
|
||||
if( arrowButton != null && comboBox.getFont() != null ) {
|
||||
// limit button width to height of a raw combobox (without insets)
|
||||
FontMetrics fm = comboBox.getFontMetrics( comboBox.getFont() );
|
||||
int maxButtonWidth = fm.getHeight() + scale( padding.top ) + scale( padding.bottom );
|
||||
@@ -482,22 +485,6 @@ public class FlatComboBoxUI
|
||||
@Override
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public void paintCurrentValue( Graphics g, Rectangle bounds, boolean hasFocus ) {
|
||||
// apply clipping using rounded rectangle to avoid that renderer paints
|
||||
// outside of border if combobox uses larger arc for edges
|
||||
// (e.g. FlatClientProperties.COMPONENT_ROUND_RECT is true)
|
||||
FlatBorder border = FlatUIUtils.getOutsideFlatBorder( comboBox );
|
||||
if( border != null ) {
|
||||
int clipArc = border.getArc( comboBox ) - (border.getLineWidth( comboBox ) * 2);
|
||||
if( clipArc > 0 ) {
|
||||
int x = bounds.x;
|
||||
int width = bounds.width + bounds.height;
|
||||
if( !comboBox.getComponentOrientation().isLeftToRight() )
|
||||
x -= bounds.height;
|
||||
((Graphics2D)g).clip( FlatUIUtils.createComponentRectangle(
|
||||
x, bounds.y, width, bounds.height, scale( (float) clipArc ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
paddingBorder.uninstall();
|
||||
|
||||
ListCellRenderer<Object> renderer = comboBox.getRenderer();
|
||||
@@ -511,11 +498,20 @@ public class FlatComboBoxUI
|
||||
c.setBackground( getBackground( enabled ) );
|
||||
c.setForeground( getForeground( enabled ) );
|
||||
|
||||
// make renderer component temporary non-opaque to avoid that renderer paints
|
||||
// background outside of border if combobox uses larger arc for edges
|
||||
// (e.g. FlatClientProperties.COMPONENT_ROUND_RECT is true)
|
||||
if( c instanceof JComponent )
|
||||
((JComponent)c).setOpaque( false );
|
||||
|
||||
boolean shouldValidate = (c instanceof JPanel);
|
||||
|
||||
paddingBorder.install( c );
|
||||
currentValuePane.paintComponent( g, c, comboBox, bounds.x, bounds.y, bounds.width, bounds.height, shouldValidate );
|
||||
paddingBorder.uninstall();
|
||||
|
||||
if( c instanceof JComponent )
|
||||
((JComponent)c).setOpaque( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -812,7 +808,9 @@ public class FlatComboBoxUI
|
||||
this.padding = padding;
|
||||
}
|
||||
|
||||
void install( Component c ) {
|
||||
// using synchronized to avoid problems with code that modifies combo box
|
||||
// (model, selection, etc) not on AWT thread (which should be not done)
|
||||
synchronized void install( Component c ) {
|
||||
if( !(c instanceof JComponent) )
|
||||
return;
|
||||
|
||||
@@ -844,7 +842,7 @@ public class FlatComboBoxUI
|
||||
* there is no single place to uninstall it.
|
||||
* This is the reason why this method is called from various places.
|
||||
*/
|
||||
void uninstall() {
|
||||
synchronized void uninstall() {
|
||||
if( rendererComponent == null )
|
||||
return;
|
||||
|
||||
@@ -855,9 +853,9 @@ public class FlatComboBoxUI
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
||||
synchronized public Insets getBorderInsets( Component c, Insets insets ) {
|
||||
Insets padding = scale( this.padding );
|
||||
if( rendererBorder != null ) {
|
||||
if( rendererBorder != null && !(rendererBorder instanceof CellPaddingBorder) ) {
|
||||
Insets insideInsets = rendererBorder.getBorderInsets( c );
|
||||
insets.top = Math.max( padding.top, insideInsets.top );
|
||||
insets.left = Math.max( padding.left, insideInsets.left );
|
||||
|
||||
@@ -121,6 +121,10 @@ public class FlatPopupFactory
|
||||
popupWindow.getGraphicsConfiguration() == owner.getGraphicsConfiguration() )
|
||||
return popup;
|
||||
|
||||
// avoid endless loop (should newer happen; PopupFactory cache size is 5)
|
||||
if( ++count > 10 )
|
||||
return popup;
|
||||
|
||||
// remove contents component from popup window
|
||||
if( popupWindow instanceof JWindow )
|
||||
((JWindow)popupWindow).getContentPane().removeAll();
|
||||
@@ -128,10 +132,6 @@ public class FlatPopupFactory
|
||||
// dispose unused popup
|
||||
// (do not invoke popup.hide() because this would cache the popup window)
|
||||
popupWindow.dispose();
|
||||
|
||||
// avoid endless loop (should newer happen; PopupFactory cache size is 5)
|
||||
if( ++count > 10 )
|
||||
return popup;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -263,9 +263,19 @@ public class FlatTreeUI
|
||||
boolean isDropRow = isDropRow( row );
|
||||
boolean needsSelectionPainting = (isSelected || isDropRow) && isPaintSelection();
|
||||
|
||||
// do not paint row if editing, except if selection needs painted
|
||||
if( isEditing && !needsSelectionPainting )
|
||||
// do not paint row if editing
|
||||
if( isEditing ) {
|
||||
// paint wide selection
|
||||
// (do not access cell renderer here to avoid side effect
|
||||
// if renderer component is also used as editor component)
|
||||
if( isSelected && isWideSelection() ) {
|
||||
Color oldColor = g.getColor();
|
||||
g.setColor( selectionInactiveBackground );
|
||||
paintWideSelection( g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf );
|
||||
g.setColor( oldColor );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
boolean hasFocus = FlatUIUtils.isPermanentFocusOwner( tree );
|
||||
boolean cellHasFocus = hasFocus && (row == getLeadSelectionRow());
|
||||
@@ -322,14 +332,7 @@ public class FlatTreeUI
|
||||
|
||||
if( isWideSelection() ) {
|
||||
// wide selection
|
||||
g.fillRect( 0, bounds.y, tree.getWidth(), bounds.height );
|
||||
|
||||
// paint expand/collapse icon
|
||||
// (was already painted before, but painted over with wide selection)
|
||||
if( shouldPaintExpandControl( path, row, isExpanded, hasBeenExpanded, isLeaf ) ) {
|
||||
paintExpandControl( g, clipBounds, insets, bounds,
|
||||
path, row, isExpanded, hasBeenExpanded, isLeaf );
|
||||
}
|
||||
paintWideSelection( g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf );
|
||||
} else {
|
||||
// non-wide selection
|
||||
paintCellBackground( g, rendererComponent, bounds );
|
||||
@@ -353,8 +356,7 @@ public class FlatTreeUI
|
||||
}
|
||||
|
||||
// paint renderer
|
||||
if( !isEditing )
|
||||
rendererPane.paintComponent( g, rendererComponent, tree, bounds.x, bounds.y, bounds.width, bounds.height, true );
|
||||
rendererPane.paintComponent( g, rendererComponent, tree, bounds.x, bounds.y, bounds.width, bounds.height, true );
|
||||
|
||||
// restore background selection color and border selection color
|
||||
if( oldBackgroundSelectionColor != null )
|
||||
@@ -363,6 +365,19 @@ public class FlatTreeUI
|
||||
((DefaultTreeCellRenderer)rendererComponent).setBorderSelectionColor( oldBorderSelectionColor );
|
||||
}
|
||||
|
||||
private void paintWideSelection( Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds,
|
||||
TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf )
|
||||
{
|
||||
g.fillRect( 0, bounds.y, tree.getWidth(), bounds.height );
|
||||
|
||||
// paint expand/collapse icon
|
||||
// (was already painted before, but painted over with wide selection)
|
||||
if( shouldPaintExpandControl( path, row, isExpanded, hasBeenExpanded, isLeaf ) ) {
|
||||
paintExpandControl( g, clipBounds, insets, bounds,
|
||||
path, row, isExpanded, hasBeenExpanded, isLeaf );
|
||||
}
|
||||
}
|
||||
|
||||
private void paintCellBackground( Graphics g, Component rendererComponent, Rectangle bounds ) {
|
||||
int xOffset = 0;
|
||||
int imageOffset = 0;
|
||||
|
||||
@@ -163,11 +163,18 @@ class FlatWindowsNativeWindowBorder
|
||||
return;
|
||||
|
||||
// install
|
||||
WndProc wndProc = new WndProc( window );
|
||||
if( wndProc.hwnd == 0 )
|
||||
return;
|
||||
try {
|
||||
WndProc wndProc = new WndProc( window );
|
||||
if( wndProc.hwnd == 0 )
|
||||
return;
|
||||
|
||||
windowsMap.put( window, wndProc );
|
||||
windowsMap.put( window, wndProc );
|
||||
} catch( UnsatisfiedLinkError ex ) {
|
||||
// catch for the case that the operating system prevents execution of DLL
|
||||
// (e.g. if DLLs in temp folder are restricted)
|
||||
// --> continue application without custom decorations
|
||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||
}
|
||||
}
|
||||
|
||||
private void uninstall( Window window ) {
|
||||
|
||||
@@ -374,7 +374,7 @@ MenuItem.iconTextGap = 6
|
||||
MenuItem.textAcceleratorGap = 24
|
||||
MenuItem.textNoAcceleratorGap = 6
|
||||
MenuItem.acceleratorArrowGap = 2
|
||||
MenuItem.acceleratorDelimiter = -
|
||||
MenuItem.acceleratorDelimiter = +
|
||||
[mac]MenuItem.acceleratorDelimiter =
|
||||
|
||||
# for MenuItem.selectionType = underline
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2021 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
|
||||
*
|
||||
* https://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.testing;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import com.formdev.flatlaf.FlatLightLaf;
|
||||
|
||||
/**
|
||||
* Used to test AWT components on macOS, which internally use Swing.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatAWTTest
|
||||
{
|
||||
public static void main( String[] args ) {
|
||||
EventQueue.invokeLater( () -> {
|
||||
FlatLightLaf.setup();
|
||||
|
||||
Frame frame = new Frame( "FlatAWTTest" );
|
||||
frame.addWindowListener( new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing( WindowEvent e ) {
|
||||
System.exit( 0 );
|
||||
}
|
||||
} );
|
||||
frame.setLayout( new FlowLayout() );
|
||||
|
||||
frame.add( new Label( "text" ) );
|
||||
frame.add( new Button( "text" ) );
|
||||
frame.add( new Checkbox( "text" ) );
|
||||
|
||||
CheckboxGroup checkboxGroup = new CheckboxGroup();
|
||||
frame.add( new Checkbox( "radio 1", true, checkboxGroup ) );
|
||||
frame.add( new Checkbox( "radio 2", false, checkboxGroup ) );
|
||||
frame.add( new Checkbox( "radio 3", false, checkboxGroup ) );
|
||||
|
||||
Choice choice = new Choice();
|
||||
choice.add( "item 1" );
|
||||
choice.add( "item 2" );
|
||||
choice.add( "item 3" );
|
||||
frame.add( choice );
|
||||
|
||||
frame.add( new TextField( "text" ) );
|
||||
frame.add( new TextArea( "text" ) );
|
||||
|
||||
List list = new List();
|
||||
list.add( "item 1" );
|
||||
list.add( "item 2" );
|
||||
frame.add( list );
|
||||
|
||||
frame.add( new Scrollbar() );
|
||||
frame.add( new ScrollPane() );
|
||||
frame.add( new Panel() );
|
||||
frame.add( new Canvas() );
|
||||
|
||||
frame.setSize( 800, 600 );
|
||||
frame.setVisible( true );
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1621,6 +1621,7 @@ public class FlatComponentsTest
|
||||
// customRenderer.setBorder( new LineBorder( Color.red ) );
|
||||
// comboBox1.setRenderer( customRenderer );
|
||||
// comboBox3.setRenderer( customRenderer );
|
||||
// comboBox5.setRenderer( new DefaultListCellRenderer() );
|
||||
|
||||
// for testing issue #382
|
||||
// spinner1.setModel( new SpinnerNumberModel( 0, null, 100, 1 ) );
|
||||
|
||||
@@ -34,7 +34,7 @@ public class FlatCustomBordersTest
|
||||
private static final Color RED = new Color( 0x60ff0000, true );
|
||||
private static final Color GREEN = new Color( 0x6000ff00, true );
|
||||
private static final Color MAGENTA = new Color( 0x60ff00ff, true );
|
||||
private static final Color ORANGE = new Color( 0x60ffc800, true );
|
||||
private static final Color BLUE = new Color( 0x300000ff, true );
|
||||
|
||||
public static void main( String[] args ) {
|
||||
SwingUtilities.invokeLater( () -> {
|
||||
@@ -127,7 +127,7 @@ public class FlatCustomBordersTest
|
||||
@SuppressWarnings( "unchecked" )
|
||||
private void applySpecialComboBoxRenderers() {
|
||||
BasicComboBoxRenderer sharedRenderer = new BasicComboBoxRenderer();
|
||||
sharedRenderer.setBorder( new LineBorder( ORANGE, UIScale.scale( 2 ) ) );
|
||||
sharedRenderer.setBorder( new LineBorder( BLUE, UIScale.scale( 2 ) ) );
|
||||
comboBox29.setRenderer( sharedRenderer );
|
||||
comboBox30.setRenderer( sharedRenderer );
|
||||
|
||||
@@ -160,7 +160,7 @@ public class FlatCustomBordersTest
|
||||
}
|
||||
|
||||
private void applyCustomComboBoxEditorBorder( JComboBox<String> comboBox ) {
|
||||
applyCustomComboBoxEditorBorder( comboBox, new LineBorder( ORANGE, UIScale.scale( 6 ) ) );
|
||||
applyCustomComboBoxEditorBorder( comboBox, new LineBorder( BLUE, UIScale.scale( 6 ) ) );
|
||||
}
|
||||
|
||||
private void applyCustomComboBoxEditorBorderWithIcon( JComboBox<String> comboBox ) {
|
||||
@@ -180,7 +180,7 @@ public class FlatCustomBordersTest
|
||||
}
|
||||
|
||||
private void applyCustomComboBoxRendererBorder( JComboBox<String> comboBox ) {
|
||||
applyCustomComboBoxRendererBorder( comboBox, new LineBorder( ORANGE, UIScale.scale( 6 ) ) );
|
||||
applyCustomComboBoxRendererBorder( comboBox, new LineBorder( BLUE, UIScale.scale( 6 ) ) );
|
||||
}
|
||||
|
||||
private void applyCustomComboBoxRendererBorderWithIcon( JComboBox<String> comboBox ) {
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2021 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
|
||||
*
|
||||
* https://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.testing;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.awt.FlowLayout;
|
||||
import java.util.Random;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
import com.formdev.flatlaf.FlatClientProperties;
|
||||
import com.formdev.flatlaf.FlatLightLaf;
|
||||
|
||||
/**
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatStressTest
|
||||
{
|
||||
public static void main( String[] args ) {
|
||||
SwingUtilities.invokeLater( () -> {
|
||||
FlatLightLaf.setup();
|
||||
new FlatStressTest();
|
||||
} );
|
||||
}
|
||||
|
||||
protected FlatStressTest() {
|
||||
JFrame frame = new JFrame( "FlatStressTest" );
|
||||
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
|
||||
|
||||
Container contentPane = frame.getContentPane();
|
||||
contentPane.setLayout( new FlowLayout() );
|
||||
|
||||
contentPane.add( createStressTest() );
|
||||
|
||||
frame.setSize( 800, 600 );
|
||||
frame.setLocationRelativeTo( null );
|
||||
frame.setVisible( true );
|
||||
}
|
||||
|
||||
private JComponent createStressTest() {
|
||||
return createComboBoxStressTest();
|
||||
}
|
||||
|
||||
// for https://github.com/JFormDesigner/FlatLaf/issues/432
|
||||
// simulates StackOverflowError in FlatComboBoxUI when doing stuff in various threads
|
||||
//
|
||||
// requires adding `Thread.sleep( 1 );` to `FlatComboBoxUI.CellPaddingBorder.install()`
|
||||
// after invocation of `uninstall()`
|
||||
private JComponent createComboBoxStressTest() {
|
||||
Random random = new Random();
|
||||
|
||||
JComboBox<String> comboBox = new JComboBox<>();
|
||||
comboBox.putClientProperty( FlatClientProperties.MINIMUM_WIDTH, 0 );
|
||||
for( int i = 0; i < 100; i++ )
|
||||
comboBox.addItem( Integer.toString( random.nextInt() ) );
|
||||
|
||||
Thread thread = new Thread( () -> {
|
||||
for(;;) {
|
||||
comboBox.setSelectedIndex( random.nextInt( comboBox.getItemCount() ) );
|
||||
comboBox.putClientProperty( FlatClientProperties.MINIMUM_WIDTH, random.nextInt( 500 ) );
|
||||
}
|
||||
});
|
||||
thread.setDaemon( true );
|
||||
thread.start();
|
||||
|
||||
return comboBox;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user