TextField: support leading and trailing icons (issue #368)

This commit is contained in:
Karl Tauber
2021-09-02 17:45:33 +02:00
parent 51d7bc2c37
commit dc33c26960
21 changed files with 571 additions and 73 deletions

View File

@@ -19,6 +19,7 @@ package com.formdev.flatlaf.extras.components;
import static com.formdev.flatlaf.FlatClientProperties.*;
import java.awt.Color;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.JFormattedTextField;
import com.formdev.flatlaf.extras.components.FlatTextField.SelectAllOnFocusPolicy;
@@ -46,6 +47,44 @@ public class FlatFormattedTextField
}
/**
* Returns the leading icon that will be placed at the leading edge of the text field.
*
* @since 2
*/
public Icon getLeadingIcon() {
return (Icon) getClientProperty( TEXT_FIELD_LEADING_ICON );
}
/**
* Specifies the leading icon that will be placed at the leading edge of the text field.
*
* @since 2
*/
public void setLeadingIcon( Icon leadingIcon ) {
putClientProperty( TEXT_FIELD_LEADING_ICON, leadingIcon );
}
/**
* Returns the trailing icon that will be placed at the trailing edge of the text field.
*
* @since 2
*/
public Icon getTrailingIcon() {
return (Icon) getClientProperty( TEXT_FIELD_TRAILING_ICON );
}
/**
* Specifies the trailing icon that will be placed at the trailing edge of the text field.
*
* @since 2
*/
public void setTrailingIcon( Icon trailingIcon ) {
putClientProperty( TEXT_FIELD_TRAILING_ICON, trailingIcon );
}
/**
* Returns whether all text is selected when the text component gains focus.
*/

View File

@@ -19,6 +19,7 @@ package com.formdev.flatlaf.extras.components;
import static com.formdev.flatlaf.FlatClientProperties.*;
import java.awt.Color;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.JPasswordField;
import com.formdev.flatlaf.extras.components.FlatTextField.SelectAllOnFocusPolicy;
@@ -46,6 +47,44 @@ public class FlatPasswordField
}
/**
* Returns the leading icon that will be placed at the leading edge of the text field.
*
* @since 2
*/
public Icon getLeadingIcon() {
return (Icon) getClientProperty( TEXT_FIELD_LEADING_ICON );
}
/**
* Specifies the leading icon that will be placed at the leading edge of the text field.
*
* @since 2
*/
public void setLeadingIcon( Icon leadingIcon ) {
putClientProperty( TEXT_FIELD_LEADING_ICON, leadingIcon );
}
/**
* Returns the trailing icon that will be placed at the trailing edge of the text field.
*
* @since 2
*/
public Icon getTrailingIcon() {
return (Icon) getClientProperty( TEXT_FIELD_TRAILING_ICON );
}
/**
* Specifies the trailing icon that will be placed at the trailing edge of the text field.
*
* @since 2
*/
public void setTrailingIcon( Icon trailingIcon ) {
putClientProperty( TEXT_FIELD_TRAILING_ICON, trailingIcon );
}
/**
* Returns whether all text is selected when the text component gains focus.
*/

View File

@@ -19,6 +19,7 @@ package com.formdev.flatlaf.extras.components;
import static com.formdev.flatlaf.FlatClientProperties.*;
import java.awt.Color;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.JTextField;
/**
@@ -45,6 +46,44 @@ public class FlatTextField
}
/**
* Returns the leading icon that will be placed at the leading edge of the text field.
*
* @since 2
*/
public Icon getLeadingIcon() {
return (Icon) getClientProperty( TEXT_FIELD_LEADING_ICON );
}
/**
* Specifies the leading icon that will be placed at the leading edge of the text field.
*
* @since 2
*/
public void setLeadingIcon( Icon leadingIcon ) {
putClientProperty( TEXT_FIELD_LEADING_ICON, leadingIcon );
}
/**
* Returns the trailing icon that will be placed at the trailing edge of the text field.
*
* @since 2
*/
public Icon getTrailingIcon() {
return (Icon) getClientProperty( TEXT_FIELD_TRAILING_ICON );
}
/**
* Specifies the trailing icon that will be placed at the trailing edge of the text field.
*
* @since 2
*/
public void setTrailingIcon( Icon trailingIcon ) {
putClientProperty( TEXT_FIELD_TRAILING_ICON, trailingIcon );
}
// NOTE: enum names must be equal to allowed strings
public enum SelectAllOnFocusPolicy { never, once, always };