mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 23:07:15 -06:00
TextField: clear button has now component name TextField.clearButton
PasswordField: reveals button has now component name `PasswordField.revealButton` and additional style class `revealButton` (issue #173) SwingUtils: added `getComponentByName()` for easy getting clear or reveal buttons
This commit is contained in:
@@ -36,6 +36,7 @@ import javax.swing.plaf.UIResource;
|
|||||||
import javax.swing.plaf.basic.BasicHTML;
|
import javax.swing.plaf.basic.BasicHTML;
|
||||||
import javax.swing.plaf.basic.BasicOptionPaneUI;
|
import javax.swing.plaf.basic.BasicOptionPaneUI;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
|
import com.formdev.flatlaf.util.SwingUtils;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,7 +157,7 @@ public class FlatOptionPaneUI
|
|||||||
|
|
||||||
// set icon-message gap
|
// set icon-message gap
|
||||||
if( iconMessageGap > 0 ) {
|
if( iconMessageGap > 0 ) {
|
||||||
Component iconMessageSeparator = findByName( messageArea, "OptionPane.separator" );
|
Component iconMessageSeparator = SwingUtils.getComponentByName( messageArea, "OptionPane.separator" );
|
||||||
if( iconMessageSeparator != null )
|
if( iconMessageSeparator != null )
|
||||||
iconMessageSeparator.setPreferredSize( new Dimension( UIScale.scale( iconMessageGap ), 1 ) );
|
iconMessageSeparator.setPreferredSize( new Dimension( UIScale.scale( iconMessageGap ), 1 ) );
|
||||||
}
|
}
|
||||||
@@ -236,20 +237,6 @@ public class FlatOptionPaneUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Component findByName( Container c, String name ) {
|
|
||||||
for( Component child : c.getComponents() ) {
|
|
||||||
if( name.equals( child.getName() ) )
|
|
||||||
return child;
|
|
||||||
|
|
||||||
if( child instanceof Container ) {
|
|
||||||
Component c2 = findByName( (Container) child, name );
|
|
||||||
if( c2 != null )
|
|
||||||
return c2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean getSizeButtonsToSameWidth() {
|
protected boolean getSizeButtonsToSameWidth() {
|
||||||
return sameSizeButtons;
|
return sameSizeButtons;
|
||||||
|
|||||||
@@ -291,7 +291,9 @@ public class FlatPasswordFieldUI
|
|||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
protected JToggleButton createRevealButton() {
|
protected JToggleButton createRevealButton() {
|
||||||
JToggleButton button = new JToggleButton( revealIcon );
|
JToggleButton button = new JToggleButton( revealIcon );
|
||||||
|
button.setName( "PasswordField.revealButton" );
|
||||||
prepareLeadingOrTrailingComponent( button );
|
prepareLeadingOrTrailingComponent( button );
|
||||||
|
button.putClientProperty( FlatClientProperties.STYLE_CLASS, "inTextField revealButton" );
|
||||||
if( FlatClientProperties.clientPropertyBoolean( getComponent(), KEY_REVEAL_SELECTED, false ) ) {
|
if( FlatClientProperties.clientPropertyBoolean( getComponent(), KEY_REVEAL_SELECTED, false ) ) {
|
||||||
button.setSelected( true );
|
button.setSelected( true );
|
||||||
updateEchoChar( true );
|
updateEchoChar( true );
|
||||||
|
|||||||
@@ -764,6 +764,7 @@ debug*/
|
|||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
protected JComponent createClearButton() {
|
protected JComponent createClearButton() {
|
||||||
JButton button = new JButton();
|
JButton button = new JButton();
|
||||||
|
button.setName( "TextField.clearButton" );
|
||||||
button.putClientProperty( STYLE_CLASS, "clearButton" );
|
button.putClientProperty( STYLE_CLASS, "clearButton" );
|
||||||
button.putClientProperty( BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON );
|
button.putClientProperty( BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON );
|
||||||
button.setCursor( Cursor.getDefaultCursor() );
|
button.setCursor( Cursor.getDefaultCursor() );
|
||||||
@@ -937,6 +938,7 @@ debug*/
|
|||||||
((LayoutManager2)delegate).invalidateLayout( target );
|
((LayoutManager2)delegate).invalidateLayout( target );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- class FlatDocumentListener -----------------------------------------
|
//---- class FlatDocumentListener -----------------------------------------
|
||||||
|
|
||||||
private class FlatDocumentListener
|
private class FlatDocumentListener
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 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.util;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Container;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility methods for Swing.
|
||||||
|
*
|
||||||
|
* @author Karl Tauber
|
||||||
|
* @since 2
|
||||||
|
*/
|
||||||
|
public class SwingUtils
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Search for a (grand) child component with the given name.
|
||||||
|
*
|
||||||
|
* @return a component; or {@code null}
|
||||||
|
*/
|
||||||
|
@SuppressWarnings( "unchecked" )
|
||||||
|
public static <T extends Component> T getComponentByName( Container parent, String name ) {
|
||||||
|
for( Component child : parent.getComponents() ) {
|
||||||
|
if( name.equals( child.getName() ) )
|
||||||
|
return (T) child;
|
||||||
|
|
||||||
|
if( child instanceof Container ) {
|
||||||
|
T c = getComponentByName( (Container) child, name );
|
||||||
|
if( c != null )
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user