Compare commits

..

6 Commits
0.39 ... 0.40

17 changed files with 315 additions and 29 deletions

View File

@@ -1,6 +1,24 @@
FlatLaf Change Log FlatLaf Change Log
================== ==================
## 0.40
#### New features
- Table: Detect whether component is used in cell editor and automatically
disable round border style and reduce cell editor outer border width (used for
focus indicator) to zero. (issue #148)
- ComboBox, Spinner and TextField: Support disabling round border style per
component, if globally enabled (set client property `JComponent.roundRect` to
`false`). (issue #148)
#### Fixed bugs
- Custom window decorations: Embedded menu bar did not always respond to mouse
events after adding menus and when running in JetBrains Runtime. (issue #151)
- IntelliJ Themes: Fixed NPE in Solarized themes on scroll bar hover.
## 0.39 ## 0.39
#### New features #### New features

View File

@@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
val releaseVersion = "0.39" val releaseVersion = "0.40"
val developmentVersion = "0.40-SNAPSHOT" val developmentVersion = "0.41-SNAPSHOT"
version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion

View File

@@ -314,6 +314,15 @@ public interface FlatClientProperties
return (value instanceof Boolean) ? (boolean) value : defaultValue; return (value instanceof Boolean) ? (boolean) value : defaultValue;
} }
/**
* Checks whether a client property of a component is a {@link Boolean} and returns its value.
* If the client property is not set, or not a {@link Boolean}, defaultValue is returned.
*/
static Boolean clientPropertyBooleanStrict( JComponent c, String key, Boolean defaultValue ) {
Object value = c.getClientProperty( key );
return (value instanceof Boolean) ? (Boolean) value : defaultValue;
}
/** /**
* Checks whether a client property of a component is an integer and returns its value. * Checks whether a client property of a component is an integer and returns its value.
* If the client property is not set, or not an integer, defaultValue is returned. * If the client property is not set, or not an integer, defaultValue is returned.

View File

@@ -263,6 +263,9 @@ public class IntelliJTheme
for( Map.Entry<String, Object> e : ((Map<String, Object>)value).entrySet() ) for( Map.Entry<String, Object> e : ((Map<String, Object>)value).entrySet() )
apply( key + '.' + e.getKey(), e.getValue(), defaults, defaultsKeysCache, uiKeys ); apply( key + '.' + e.getKey(), e.getValue(), defaults, defaultsKeysCache, uiKeys );
} else { } else {
if( "".equals( value ) )
return; // ignore empty value
uiKeys.add( key ); uiKeys.add( key );
// fix ComboBox size and Spinner border in all Material UI Lite themes // fix ComboBox size and Spinner border in all Material UI Lite themes

View File

@@ -87,15 +87,14 @@ public class FlatBorder
try { try {
FlatUIUtils.setRenderingHints( g2 ); FlatUIUtils.setRenderingHints( g2 );
boolean isCellEditor = isCellEditor( c ); float focusWidth = scale( (float) getFocusWidth( c ) );
float focusWidth = isCellEditor ? 0 : scale( (float) getFocusWidth( c ) );
float borderWidth = scale( (float) getBorderWidth( c ) ); float borderWidth = scale( (float) getBorderWidth( c ) );
float arc = isCellEditor ? 0 : scale( (float) getArc( c ) ); float arc = scale( (float) getArc( c ) );
Color outlineColor = getOutlineColor( c ); Color outlineColor = getOutlineColor( c );
// paint outer border // paint outer border
if( outlineColor != null || isFocused( c ) ) { if( outlineColor != null || isFocused( c ) ) {
float innerWidth = !isCellEditor && !(c instanceof JScrollPane) float innerWidth = !isCellEditor( c ) && !(c instanceof JScrollPane)
? (outlineColor != null ? innerOutlineWidth : innerFocusWidth) ? (outlineColor != null ? innerOutlineWidth : innerFocusWidth)
: 0; : 0;
@@ -204,8 +203,7 @@ public class FlatBorder
@Override @Override
public Insets getBorderInsets( Component c, Insets insets ) { public Insets getBorderInsets( Component c, Insets insets ) {
boolean isCellEditor = isCellEditor( c ); float focusWidth = scale( (float) getFocusWidth( c ) );
float focusWidth = isCellEditor ? 0 : scale( (float) getFocusWidth( c ) );
float ow = focusWidth + scale( (float) getLineWidth( c ) ); float ow = focusWidth + scale( (float) getLineWidth( c ) );
insets = super.getBorderInsets( c, insets ); insets = super.getBorderInsets( c, insets );
@@ -214,7 +212,7 @@ public class FlatBorder
insets.bottom = Math.round( scale( (float) insets.bottom ) + ow ); insets.bottom = Math.round( scale( (float) insets.bottom ) + ow );
insets.right = Math.round( scale( (float) insets.right ) + ow ); insets.right = Math.round( scale( (float) insets.right ) + ow );
if( isCellEditor ) { if( isCellEditor( c ) ) {
// remove top and bottom insets if used as cell editor // remove top and bottom insets if used as cell editor
insets.top = insets.bottom = 0; insets.top = insets.bottom = 0;
@@ -232,6 +230,9 @@ public class FlatBorder
* Returns the (unscaled) thickness of the outer focus border. * Returns the (unscaled) thickness of the outer focus border.
*/ */
protected int getFocusWidth( Component c ) { protected int getFocusWidth( Component c ) {
if( isCellEditor( c ) )
return 0;
return focusWidth; return focusWidth;
} }

View File

@@ -141,6 +141,9 @@ public class FlatButtonBorder
@Override @Override
protected int getArc( Component c ) { protected int getArc( Component c ) {
if( isCellEditor( c ) )
return 0;
switch( FlatButtonUI.getButtonType( c ) ) { switch( FlatButtonUI.getButtonType( c ) ) {
case FlatButtonUI.TYPE_SQUARE: return 0; case FlatButtonUI.TYPE_SQUARE: return 0;
case FlatButtonUI.TYPE_ROUND_RECT: return Short.MAX_VALUE; case FlatButtonUI.TYPE_ROUND_RECT: return Short.MAX_VALUE;

View File

@@ -123,6 +123,14 @@ public class FlatMenuUI
}; };
} }
@Override
public Dimension getMinimumSize( JComponent c ) {
// avoid that top-level menus (in menu bar) are made smaller if horizontal space is rare
// same code is in BasicMenuUI since Java 10
// see https://bugs.openjdk.java.net/browse/JDK-8178430
return ((JMenu)menuItem).isTopLevelMenu() ? c.getPreferredSize() : null;
}
@Override @Override
protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) {
return renderer.getPreferredMenuItemSize(); return renderer.getPreferredMenuItemSize();

View File

@@ -304,6 +304,9 @@ public class FlatRootPaneUI
Container contentPane = rootPane.getContentPane(); Container contentPane = rootPane.getContentPane();
if( contentPane != null ) if( contentPane != null )
contentPane.setBounds( 0, nextY, width, Math.max( height - nextY, 0 ) ); contentPane.setBounds( 0, nextY, width, Math.max( height - nextY, 0 ) );
if( titlePane != null )
titlePane.menuBarLayouted();
} }
@Override @Override

View File

@@ -33,6 +33,10 @@ public class FlatRoundBorder
@Override @Override
protected int getArc( Component c ) { protected int getArc( Component c ) {
return FlatUIUtils.isRoundRect( c ) ? Short.MAX_VALUE : arc; if( isCellEditor( c ) )
return 0;
Boolean roundRect = FlatUIUtils.isRoundRect( c );
return roundRect != null ? (roundRect ? Short.MAX_VALUE : 0) : arc;
} }
} }

View File

@@ -33,6 +33,10 @@ public class FlatTextBorder
@Override @Override
protected int getArc( Component c ) { protected int getArc( Component c ) {
return FlatUIUtils.isRoundRect( c ) ? Short.MAX_VALUE : arc; if( isCellEditor( c ) )
return 0;
Boolean roundRect = FlatUIUtils.isRoundRect( c );
return roundRect != null ? (roundRect ? Short.MAX_VALUE : 0) : arc;
} }
} }

View File

@@ -19,6 +19,7 @@ package com.formdev.flatlaf.ui;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Container;
import java.awt.Dialog; import java.awt.Dialog;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.EventQueue; import java.awt.EventQueue;
@@ -165,7 +166,25 @@ public class FlatTitlePane
createButtons(); createButtons();
setLayout( new BorderLayout() ); setLayout( new BorderLayout() {
@Override
public void layoutContainer( Container target ) {
super.layoutContainer( target );
// make left panel (with embedded menu bar) smaller if horizontal space is rare
// to avoid that embedded menu bar overlaps button bar
Insets insets = target.getInsets();
int width = target.getWidth() - insets.left - insets.right;
if( leftPanel.getWidth() + buttonPanel.getWidth() > width ) {
int oldWidth = leftPanel.getWidth();
int newWidth = Math.max( width - buttonPanel.getWidth(), 0 );
leftPanel.setSize( newWidth, leftPanel.getHeight() );
if( !getComponentOrientation().isLeftToRight() )
leftPanel.setLocation( leftPanel.getX() + (oldWidth - newWidth), leftPanel.getY() );
}
}
} );
add( leftPanel, BorderLayout.LINE_START ); add( leftPanel, BorderLayout.LINE_START );
add( titleLabel, BorderLayout.CENTER ); add( titleLabel, BorderLayout.CENTER );
add( buttonPanel, BorderLayout.LINE_END ); add( buttonPanel, BorderLayout.LINE_END );
@@ -391,6 +410,12 @@ public class FlatTitlePane
return FlatUIUtils.subtractInsets( bounds, UIScale.scale( getMenuBarMargins() ) ); return FlatUIUtils.subtractInsets( bounds, UIScale.scale( getMenuBarMargins() ) );
} }
protected Insets getMenuBarMargins() {
return getComponentOrientation().isLeftToRight()
? menuBarMargins
: new Insets( menuBarMargins.top, menuBarMargins.right, menuBarMargins.bottom, menuBarMargins.left );
}
protected void menuBarChanged() { protected void menuBarChanged() {
menuBarPlaceholder.invalidate(); menuBarPlaceholder.invalidate();
@@ -400,12 +425,27 @@ public class FlatTitlePane
} ); } );
} }
protected Insets getMenuBarMargins() { protected void menuBarLayouted() {
return getComponentOrientation().isLeftToRight() updateJBRHitTestSpotsAndTitleBarHeightLater();
? menuBarMargins
: new Insets( menuBarMargins.top, menuBarMargins.right, menuBarMargins.bottom, menuBarMargins.left );
} }
/*debug
@Override
public void paint( Graphics g ) {
super.paint( g );
if( debugTitleBarHeight > 0 ) {
g.setColor( Color.green );
g.drawLine( 0, debugTitleBarHeight, getWidth(), debugTitleBarHeight );
}
if( debugHitTestSpots != null ) {
g.setColor( Color.blue );
for( Rectangle r : debugHitTestSpots )
g.drawRect( r.x, r.y, r.width, r.height );
}
}
debug*/
@Override @Override
protected void paintComponent( Graphics g ) { protected void paintComponent( Graphics g ) {
g.setColor( getBackground() ); g.setColor( getBackground() );
@@ -583,6 +623,12 @@ public class FlatTitlePane
titleBarHeight--; titleBarHeight--;
JBRCustomDecorations.setHitTestSpotsAndTitleBarHeight( window, hitTestSpots, titleBarHeight ); JBRCustomDecorations.setHitTestSpotsAndTitleBarHeight( window, hitTestSpots, titleBarHeight );
/*debug
debugHitTestSpots = hitTestSpots;
debugTitleBarHeight = titleBarHeight;
repaint();
debug*/
} }
protected void addJBRHitTestSpot( JComponent c, boolean subtractMenuBarMargins, List<Rectangle> hitTestSpots ) { protected void addJBRHitTestSpot( JComponent c, boolean subtractMenuBarMargins, List<Rectangle> hitTestSpots ) {
@@ -599,6 +645,11 @@ public class FlatTitlePane
hitTestSpots.add( r ); hitTestSpots.add( r );
} }
/*debug
private List<Rectangle> debugHitTestSpots;
private int debugTitleBarHeight;
debug*/
//---- class TitlePaneBorder ---------------------------------------------- //---- class TitlePaneBorder ----------------------------------------------
protected class FlatTitlePaneBorder protected class FlatTitlePaneBorder

View File

@@ -37,6 +37,7 @@ import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import java.util.function.Consumer; import java.util.function.Consumer;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
@@ -137,11 +138,21 @@ public class FlatUIUtils
} }
public static boolean isCellEditor( Component c ) { public static boolean isCellEditor( Component c ) {
// check whether used as cell editor in file chooser // check whether used in cell editor (check 3 levels up)
// Tree.cellEditor is set in sun.swing.FilePane.editFileName() Component c2 = c;
for( int i = 0; i <= 2 && c2 != null; i++ ) {
Container parent = c2.getParent();
if( parent instanceof JTable && ((JTable)parent).getEditorComponent() == c2 )
return true;
c2 = parent;
}
// check whether used as cell editor
// Table.editor is set in JTable.GenericEditor constructor // Table.editor is set in JTable.GenericEditor constructor
// Tree.cellEditor is set in sun.swing.FilePane.editFileName()
String name = c.getName(); String name = c.getName();
if( "Tree.cellEditor".equals( name ) || "Table.editor".equals( name ) ) if( "Table.editor".equals( name ) || "Tree.cellEditor".equals( name ) )
return true; return true;
// for using combo box as cell editor in table // for using combo box as cell editor in table
@@ -159,9 +170,11 @@ public class FlatUIUtils
keyboardFocusManager.getActiveWindow() == SwingUtilities.windowForComponent( c ); keyboardFocusManager.getActiveWindow() == SwingUtilities.windowForComponent( c );
} }
public static boolean isRoundRect( Component c ) { public static Boolean isRoundRect( Component c ) {
return c instanceof JComponent && FlatClientProperties.clientPropertyBoolean( return (c instanceof JComponent)
(JComponent) c, FlatClientProperties.COMPONENT_ROUND_RECT, false ); ? FlatClientProperties.clientPropertyBooleanStrict(
(JComponent) c, FlatClientProperties.COMPONENT_ROUND_RECT, null )
: null;
} }
/** /**

View File

@@ -16,6 +16,9 @@
package com.formdev.flatlaf.testing; package com.formdev.flatlaf.testing;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
@@ -91,6 +94,33 @@ public class FlatComponents2Test
table1.setColumnSelectionAllowed( columnSelectionCheckBox.isSelected() ); table1.setColumnSelectionAllowed( columnSelectionCheckBox.isSelected() );
} }
private void showHorizontalLinesChanged() {
table1.setShowHorizontalLines( showHorizontalLinesCheckBox.isSelected() );
}
private void showVerticalLinesChanged() {
table1.setShowVerticalLines( showVerticalLinesCheckBox.isSelected() );
}
private void intercellSpacingChanged() {
table1.setIntercellSpacing( intercellSpacingCheckBox.isSelected() ? new Dimension( 1, 1 ) : new Dimension() );
}
private void redGridColorChanged() {
table1.setGridColor( redGridColorCheckBox.isSelected() ? Color.red : UIManager.getColor( "Table.gridColor" ) );
}
@Override
public void updateUI() {
super.updateUI();
EventQueue.invokeLater( () -> {
showHorizontalLinesChanged();
showVerticalLinesChanged();
intercellSpacingChanged();
} );
}
@SuppressWarnings( { "unchecked", "rawtypes" } ) @SuppressWarnings( { "unchecked", "rawtypes" } )
private void initComponents() { private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
@@ -114,6 +144,10 @@ public class FlatComponents2Test
tableHeaderButtonCheckBox = new JCheckBox(); tableHeaderButtonCheckBox = new JCheckBox();
rowSelectionCheckBox = new JCheckBox(); rowSelectionCheckBox = new JCheckBox();
columnSelectionCheckBox = new JCheckBox(); columnSelectionCheckBox = new JCheckBox();
showHorizontalLinesCheckBox = new JCheckBox();
showVerticalLinesCheckBox = new JCheckBox();
intercellSpacingCheckBox = new JCheckBox();
redGridColorCheckBox = new JCheckBox();
//======== this ======== //======== this ========
setLayout(new MigLayout( setLayout(new MigLayout(
@@ -127,6 +161,7 @@ public class FlatComponents2Test
"[]" + "[]" +
"[::200]" + "[::200]" +
"[150,grow]" + "[150,grow]" +
"[]" +
"[]")); "[]"));
//---- textFieldLabel ---- //---- textFieldLabel ----
@@ -333,6 +368,26 @@ public class FlatComponents2Test
columnSelectionCheckBox.setText("column selection"); columnSelectionCheckBox.setText("column selection");
columnSelectionCheckBox.addActionListener(e -> columnSelectionChanged()); columnSelectionCheckBox.addActionListener(e -> columnSelectionChanged());
add(columnSelectionCheckBox, "cell 0 4 3 1"); add(columnSelectionCheckBox, "cell 0 4 3 1");
//---- showHorizontalLinesCheckBox ----
showHorizontalLinesCheckBox.setText("show horizontal lines");
showHorizontalLinesCheckBox.addActionListener(e -> showHorizontalLinesChanged());
add(showHorizontalLinesCheckBox, "cell 0 5 3 1");
//---- showVerticalLinesCheckBox ----
showVerticalLinesCheckBox.setText("show vertical lines");
showVerticalLinesCheckBox.addActionListener(e -> showVerticalLinesChanged());
add(showVerticalLinesCheckBox, "cell 0 5 3 1");
//---- intercellSpacingCheckBox ----
intercellSpacingCheckBox.setText("intercell spacing");
intercellSpacingCheckBox.addActionListener(e -> intercellSpacingChanged());
add(intercellSpacingCheckBox, "cell 0 5 3 1");
//---- redGridColorCheckBox ----
redGridColorCheckBox.setText("red grid color");
redGridColorCheckBox.addActionListener(e -> redGridColorChanged());
add(redGridColorCheckBox, "cell 0 5 3 1");
// JFormDesigner - End of component initialization //GEN-END:initComponents // JFormDesigner - End of component initialization //GEN-END:initComponents
((JComboBox)((DefaultCellEditor)table1.getColumnModel().getColumn( 3 ).getCellEditor()).getComponent()).setEditable( true ); ((JComboBox)((DefaultCellEditor)table1.getColumnModel().getColumn( 3 ).getCellEditor()).getComponent()).setEditable( true );
@@ -349,6 +404,10 @@ public class FlatComponents2Test
private JCheckBox tableHeaderButtonCheckBox; private JCheckBox tableHeaderButtonCheckBox;
private JCheckBox rowSelectionCheckBox; private JCheckBox rowSelectionCheckBox;
private JCheckBox columnSelectionCheckBox; private JCheckBox columnSelectionCheckBox;
private JCheckBox showHorizontalLinesCheckBox;
private JCheckBox showVerticalLinesCheckBox;
private JCheckBox intercellSpacingCheckBox;
private JCheckBox redGridColorCheckBox;
// JFormDesigner - End of variables declaration //GEN-END:variables // JFormDesigner - End of variables declaration //GEN-END:variables
//---- class DummyTransferHandler ----------------------------------------- //---- class DummyTransferHandler -----------------------------------------

View File

@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.2" encoding: "UTF-8" JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"
new FormModel { new FormModel {
contentType: "form/swing" contentType: "form/swing"
@@ -9,7 +9,7 @@ new FormModel {
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "ltr,insets dialog,hidemode 3" "$layoutConstraints": "ltr,insets dialog,hidemode 3"
"$columnConstraints": "[][200][200]" "$columnConstraints": "[][200][200]"
"$rowConstraints": "[][][::200][150,grow][]" "$rowConstraints": "[][][::200][150,grow][][]"
} ) { } ) {
name: "this" name: "this"
add( new FormComponent( "javax.swing.JLabel" ) { add( new FormComponent( "javax.swing.JLabel" ) {
@@ -316,6 +316,46 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 4 3 1" "value": "cell 0 4 3 1"
} ) } )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "showHorizontalLinesCheckBox"
"text": "show horizontal lines"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showHorizontalLinesChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 5 3 1"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "showVerticalLinesCheckBox"
"text": "show vertical lines"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showVerticalLinesChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 5 3 1"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "intercellSpacingCheckBox"
"text": "intercell spacing"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "intercellSpacingChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 5 3 1"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "redGridColorCheckBox"
"text": "red grid color"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "redGridColorChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 5 3 1"
} )
}, new FormLayoutConstraints( null ) { }, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 ) "location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 790, 715 ) "size": new java.awt.Dimension( 790, 715 )

View File

@@ -62,6 +62,7 @@ public class FlatTestFrame
private FlatInspector inspector; private FlatInspector inspector;
public boolean useApplyComponentOrientation; public boolean useApplyComponentOrientation;
public boolean applyComponentOrientationToFrame;
public static FlatTestFrame create( String[] args, String title ) { public static FlatTestFrame create( String[] args, String title ) {
DemoPrefs.init( PREFS_ROOT_PATH ); DemoPrefs.init( PREFS_ROOT_PATH );
@@ -439,7 +440,9 @@ public class FlatTestFrame
? ComponentOrientation.RIGHT_TO_LEFT ? ComponentOrientation.RIGHT_TO_LEFT
: ComponentOrientation.LEFT_TO_RIGHT; : ComponentOrientation.LEFT_TO_RIGHT;
if( useApplyComponentOrientation ) if( applyComponentOrientationToFrame )
applyComponentOrientation( orientation );
else if( useApplyComponentOrientation )
content.applyComponentOrientation( orientation ); content.applyComponentOrientation( orientation );
else { else {
updateComponentsRecur( content, (c, type) -> { updateComponentsRecur( content, (c, type) -> {

View File

@@ -22,6 +22,7 @@ import java.awt.event.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Random;
import javax.swing.*; import javax.swing.*;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import net.miginfocom.swing.*; import net.miginfocom.swing.*;
@@ -39,6 +40,7 @@ public class FlatWindowDecorationsTest
JDialog.setDefaultLookAndFeelDecorated( true ); JDialog.setDefaultLookAndFeelDecorated( true );
FlatTestFrame frame = FlatTestFrame.create( args, "FlatWindowDecorationsTest" ); FlatTestFrame frame = FlatTestFrame.create( args, "FlatWindowDecorationsTest" );
frame.applyComponentOrientationToFrame = true;
// WARNING: Do not this in real-world programs. // WARNING: Do not this in real-world programs.
// frame.setUndecorated( true ); // frame.setUndecorated( true );
@@ -117,6 +119,32 @@ public class FlatWindowDecorationsTest
rootPane.putClientProperty( FlatClientProperties.MENU_BAR_EMBEDDED, menuBarEmbeddedCheckBox.isSelected() ); rootPane.putClientProperty( FlatClientProperties.MENU_BAR_EMBEDDED, menuBarEmbeddedCheckBox.isSelected() );
} }
private void addMenu() {
JMenu menu = new JMenu( "Hello" );
menu.add( new JMenuItem( "world" ) );
menuBar.add( menu );
menuBar.revalidate();
}
private void removeMenu() {
int menuCount = menuBar.getMenuCount();
if( menuCount <= 0 )
return;
menuBar.remove( menuCount - 1 );
menuBar.revalidate();
}
private void changeMenu() {
int menuCount = menuBar.getMenuCount();
if( menuCount <= 0 )
return;
int len = new Random().nextInt( 20 );
String text = "1234567890abcdefghij".substring( 0, len + 1 );
menuBar.getMenu( menuCount - 1 ).setText( text );
}
private void resizableChanged() { private void resizableChanged() {
Window window = SwingUtilities.windowForComponent( this ); Window window = SwingUtilities.windowForComponent( this );
if( window instanceof Frame ) if( window instanceof Frame )
@@ -218,6 +246,9 @@ public class FlatWindowDecorationsTest
private void initComponents() { private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
menuBarCheckBox = new JCheckBox(); menuBarCheckBox = new JCheckBox();
JButton addMenuButton = new JButton();
JButton removeMenuButton = new JButton();
JButton changeMenuButton = new JButton();
menuBarEmbeddedCheckBox = new JCheckBox(); menuBarEmbeddedCheckBox = new JCheckBox();
resizableCheckBox = new JCheckBox(); resizableCheckBox = new JCheckBox();
maximizedBoundsCheckBox = new JCheckBox(); maximizedBoundsCheckBox = new JCheckBox();
@@ -271,7 +302,7 @@ public class FlatWindowDecorationsTest
"ltr,insets dialog,hidemode 3", "ltr,insets dialog,hidemode 3",
// columns // columns
"[left]para" + "[left]para" +
"[fill]", "[left]",
// rows // rows
"para[]0" + "para[]0" +
"[]0" + "[]0" +
@@ -287,6 +318,21 @@ public class FlatWindowDecorationsTest
menuBarCheckBox.addActionListener(e -> menuBarChanged()); menuBarCheckBox.addActionListener(e -> menuBarChanged());
add(menuBarCheckBox, "cell 0 0"); add(menuBarCheckBox, "cell 0 0");
//---- addMenuButton ----
addMenuButton.setText("Add menu");
addMenuButton.addActionListener(e -> addMenu());
add(addMenuButton, "cell 1 0 1 2,align left top,grow 0 0");
//---- removeMenuButton ----
removeMenuButton.setText("Remove menu");
removeMenuButton.addActionListener(e -> removeMenu());
add(removeMenuButton, "cell 1 0 1 2,align left top,grow 0 0");
//---- changeMenuButton ----
changeMenuButton.setText("Change menu");
changeMenuButton.addActionListener(e -> changeMenu());
add(changeMenuButton, "cell 1 0 1 2,align left top,grow 0 0");
//---- menuBarEmbeddedCheckBox ---- //---- menuBarEmbeddedCheckBox ----
menuBarEmbeddedCheckBox.setText("embedded menu bar"); menuBarEmbeddedCheckBox.setText("embedded menu bar");
menuBarEmbeddedCheckBox.setSelected(true); menuBarEmbeddedCheckBox.setSelected(true);

View File

@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.2.0.298" Java: "13.0.2" encoding: "UTF-8" JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"
new FormModel { new FormModel {
contentType: "form/swing" contentType: "form/swing"
@@ -8,7 +8,7 @@ new FormModel {
} }
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "ltr,insets dialog,hidemode 3" "$layoutConstraints": "ltr,insets dialog,hidemode 3"
"$columnConstraints": "[left]para[fill]" "$columnConstraints": "[left]para[left]"
"$rowConstraints": "para[]0[]0[]0[][][top][]" "$rowConstraints": "para[]0[]0[]0[][][top][]"
} ) { } ) {
name: "this" name: "this"
@@ -23,6 +23,27 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 0" "value": "cell 0 0"
} ) } )
add( new FormComponent( "javax.swing.JButton" ) {
name: "addMenuButton"
"text": "Add menu"
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "addMenu", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 0 1 2,align left top,grow 0 0"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "removeMenuButton"
"text": "Remove menu"
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "removeMenu", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 0 1 2,align left top,grow 0 0"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "changeMenuButton"
"text": "Change menu"
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "changeMenu", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 0 1 2,align left top,grow 0 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) { add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "menuBarEmbeddedCheckBox" name: "menuBarEmbeddedCheckBox"
"text": "embedded menu bar" "text": "embedded menu bar"
@@ -238,7 +259,7 @@ new FormModel {
} ) } )
}, new FormLayoutConstraints( null ) { }, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 ) "location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 450, 380 ) "size": new java.awt.Dimension( 550, 380 )
} ) } )
add( new FormContainer( "javax.swing.JMenuBar", new FormLayoutManager( class javax.swing.JMenuBar ) ) { add( new FormContainer( "javax.swing.JMenuBar", new FormLayoutManager( class javax.swing.JMenuBar ) ) {
name: "menuBar" name: "menuBar"