TextField: support "clear" (or "cancel") button to empty text field

This commit is contained in:
Karl Tauber
2021-12-13 19:16:23 +01:00
parent 8d2ed3faf6
commit a4377e81cb
17 changed files with 339 additions and 36 deletions

View File

@@ -144,6 +144,26 @@ public class FlatFormattedTextField
}
/**
* Returns whether a "clear" (or "cancel") button is shown.
*
* @since 2
*/
public boolean isShowClearButton() {
return getClientPropertyBoolean( TEXT_FIELD_SHOW_CLEAR_BUTTON, false );
}
/**
* Specifies whether a "clear" (or "cancel") button is shown on the trailing side
* if the text field is not empty, editable and enabled.
*
* @since 2
*/
public void setShowClearButton( boolean showClearButton ) {
putClientPropertyBoolean( TEXT_FIELD_SHOW_CLEAR_BUTTON, showClearButton, false );
}
/**
* Returns whether all text is selected when the text component gains focus.
*/

View File

@@ -144,6 +144,26 @@ public class FlatPasswordField
}
/**
* Returns whether a "clear" (or "cancel") button is shown.
*
* @since 2
*/
public boolean isShowClearButton() {
return getClientPropertyBoolean( TEXT_FIELD_SHOW_CLEAR_BUTTON, false );
}
/**
* Specifies whether a "clear" (or "cancel") button is shown on the trailing side
* if the text field is not empty, editable and enabled.
*
* @since 2
*/
public void setShowClearButton( boolean showClearButton ) {
putClientPropertyBoolean( TEXT_FIELD_SHOW_CLEAR_BUTTON, showClearButton, false );
}
/**
* Returns whether all text is selected when the text component gains focus.
*/

View File

@@ -143,6 +143,26 @@ public class FlatTextField
}
/**
* Returns whether a "clear" (or "cancel") button is shown.
*
* @since 2
*/
public boolean isShowClearButton() {
return getClientPropertyBoolean( TEXT_FIELD_SHOW_CLEAR_BUTTON, false );
}
/**
* Specifies whether a "clear" (or "cancel") button is shown on the trailing side
* if the text field is not empty, editable and enabled.
*
* @since 2
*/
public void setShowClearButton( boolean showClearButton ) {
putClientPropertyBoolean( TEXT_FIELD_SHOW_CLEAR_BUTTON, showClearButton, false );
}
// NOTE: enum names must be equal to allowed strings
public enum SelectAllOnFocusPolicy { never, once, always };