mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 22:47:13 -06:00
TextField: support leading and trailing icons (issue #368)
This commit is contained in:
@@ -19,6 +19,9 @@ package com.formdev.flatlaf.demo;
|
||||
import java.awt.Component;
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.DefaultEditorKit;
|
||||
import com.formdev.flatlaf.FlatClientProperties;
|
||||
import com.formdev.flatlaf.extras.FlatSVGIcon;
|
||||
import com.formdev.flatlaf.icons.FlatSearchIcon;
|
||||
import net.miginfocom.swing.*;
|
||||
|
||||
/**
|
||||
@@ -123,6 +126,10 @@ class BasicComponentsPanel
|
||||
JTextField warningHintsTextField = new JTextField();
|
||||
JComboBox<String> warningHintsComboBox = new JComboBox<>();
|
||||
JSpinner warningHintsSpinner = new JSpinner();
|
||||
JLabel iconsLabel = new JLabel();
|
||||
JTextField leadingIconTextField = new JTextField();
|
||||
JTextField trailingIconTextField = new JTextField();
|
||||
JTextField iconsTextField = new JTextField();
|
||||
JPopupMenu popupMenu1 = new JPopupMenu();
|
||||
JMenuItem cutMenuItem = new JMenuItem();
|
||||
JMenuItem copyMenuItem = new JMenuItem();
|
||||
@@ -132,7 +139,7 @@ class BasicComponentsPanel
|
||||
setLayout(new MigLayout(
|
||||
"insets dialog,hidemode 3",
|
||||
// columns
|
||||
"[sizegroup 1]" +
|
||||
"[]" +
|
||||
"[sizegroup 1]" +
|
||||
"[sizegroup 1]" +
|
||||
"[sizegroup 1]" +
|
||||
@@ -152,6 +159,7 @@ class BasicComponentsPanel
|
||||
"[]" +
|
||||
"[]para" +
|
||||
"[]" +
|
||||
"[]" +
|
||||
"[]"));
|
||||
|
||||
//---- labelLabel ----
|
||||
@@ -646,6 +654,19 @@ class BasicComponentsPanel
|
||||
warningHintsSpinner.putClientProperty("JComponent.outline", "warning");
|
||||
add(warningHintsSpinner, "cell 3 13,growx");
|
||||
|
||||
//---- iconsLabel ----
|
||||
iconsLabel.setText("Leading/trailing icons:");
|
||||
add(iconsLabel, "cell 0 14");
|
||||
add(leadingIconTextField, "cell 1 14,growx");
|
||||
|
||||
//---- trailingIconTextField ----
|
||||
trailingIconTextField.setText("text");
|
||||
add(trailingIconTextField, "cell 2 14,growx");
|
||||
|
||||
//---- iconsTextField ----
|
||||
iconsTextField.setText("text");
|
||||
add(iconsTextField, "cell 3 14,growx");
|
||||
|
||||
//======== popupMenu1 ========
|
||||
{
|
||||
|
||||
@@ -670,8 +691,20 @@ class BasicComponentsPanel
|
||||
copyMenuItem.addActionListener( new DefaultEditorKit.CopyAction() );
|
||||
pasteMenuItem.addActionListener( new DefaultEditorKit.PasteAction() );
|
||||
|
||||
// add leading/trailing icons to text fields
|
||||
leadingIconTextField.putClientProperty( FlatClientProperties.PLACEHOLDER_TEXT, "Search" );
|
||||
leadingIconTextField.putClientProperty( FlatClientProperties.TEXT_FIELD_LEADING_ICON,
|
||||
new FlatSearchIcon() );
|
||||
trailingIconTextField.putClientProperty( FlatClientProperties.TEXT_FIELD_TRAILING_ICON,
|
||||
new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/DataTables.svg" ) );
|
||||
iconsTextField.putClientProperty( FlatClientProperties.TEXT_FIELD_LEADING_ICON,
|
||||
new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/user.svg" ) );
|
||||
iconsTextField.putClientProperty( FlatClientProperties.TEXT_FIELD_TRAILING_ICON,
|
||||
new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/bookmarkGroup.svg" ) );
|
||||
|
||||
if( FlatLafDemo.screenshotsMode ) {
|
||||
Component[] components = {
|
||||
// hide some components
|
||||
Component[] hiddenComponents = {
|
||||
button13, button14, button15, button16, comboBox5, comboBox6,
|
||||
textField6, passwordField5,
|
||||
|
||||
@@ -683,18 +716,26 @@ class BasicComponentsPanel
|
||||
errorHintsLabel, errorHintsTextField, errorHintsComboBox, errorHintsSpinner,
|
||||
warningHintsLabel, warningHintsTextField, warningHintsComboBox, warningHintsSpinner,
|
||||
};
|
||||
|
||||
for( Component c : components )
|
||||
for( Component c : hiddenComponents )
|
||||
c.setVisible( false );
|
||||
|
||||
// move password fields one row up
|
||||
// move leading/trailing icon fields and password fields some rows up
|
||||
Component[] formattedTextFields = { formattedTextFieldLabel, formattedTextField1, formattedTextField2, formattedTextField3, formattedTextField4 };
|
||||
Component[] passwordFields = { passwordFieldLabel, passwordField1, passwordField2, passwordField3, passwordField4 };
|
||||
Component[] iconsFields = { iconsLabel, leadingIconTextField, trailingIconTextField, iconsTextField };
|
||||
MigLayout layout = (MigLayout) getLayout();
|
||||
for( int i = 0; i < iconsFields.length; i++ ) {
|
||||
Object cons = layout.getComponentConstraints( passwordFields[i] );
|
||||
layout.setComponentConstraints( iconsFields[i], cons );
|
||||
}
|
||||
for( int i = 0; i < passwordFields.length; i++ ) {
|
||||
Object cons = layout.getComponentConstraints( formattedTextFields[i] );
|
||||
layout.setComponentConstraints( passwordFields[i], cons );
|
||||
}
|
||||
|
||||
// make "Not editable disabled" combobox smaller
|
||||
Object cons = layout.getComponentConstraints( comboBox4 );
|
||||
layout.setComponentConstraints( comboBox4, cons + ",width 50:50" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"
|
||||
JFDML JFormDesigner: "7.0.4.0.360" Java: "16" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
@@ -8,8 +8,8 @@ new FormModel {
|
||||
}
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||
"$layoutConstraints": "insets dialog,hidemode 3"
|
||||
"$columnConstraints": "[sizegroup 1][sizegroup 1][sizegroup 1][sizegroup 1][][]"
|
||||
"$rowConstraints": "[][][][][][][][][][][][]para[][]"
|
||||
"$columnConstraints": "[][sizegroup 1][sizegroup 1][sizegroup 1][][]"
|
||||
"$rowConstraints": "[][][][][][][][][][][][]para[][][]"
|
||||
} ) {
|
||||
name: "this"
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
@@ -648,9 +648,32 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 3 13,growx"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "iconsLabel"
|
||||
"text": "Leading/trailing icons:"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 14"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JTextField" ) {
|
||||
name: "leadingIconTextField"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 14,growx"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JTextField" ) {
|
||||
name: "trailingIconTextField"
|
||||
"text": "text"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 14,growx"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JTextField" ) {
|
||||
name: "iconsTextField"
|
||||
"text": "text"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 3 14,growx"
|
||||
} )
|
||||
}, new FormLayoutConstraints( null ) {
|
||||
"location": new java.awt.Point( 0, 0 )
|
||||
"size": new java.awt.Dimension( 920, 440 )
|
||||
"size": new java.awt.Dimension( 920, 480 )
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JPopupMenu", new FormLayoutManager( class javax.swing.JPopupMenu ) ) {
|
||||
name: "popupMenu1"
|
||||
|
||||
Reference in New Issue
Block a user