Skip to content

Simple Swing component with placeholder called JTextFieldPlaceholder

License

Notifications You must be signed in to change notification settings

material-ui-swing/JTextFieldPlaceholder

Repository files navigation

JTextFieldPlaceholder

Maven Central

Simple Swing component with placeholder called JTextFieldPlaceholder

TODO

This component has bad design, in the future should introduce the following effect

  • Used a personal UI component as BasicTextFieldPlaceholderUI
  • Introduce a toggle button with an icon
  • Introduce rules to check the errors inside the text field and paint the line with an error color

Code Style

We live in a world where robots can drive a car, so we shouldn't just write code, we should write elegant code.

This repository use google-java-format to maintains the code of the repository elegant, so before submit the code check the Java format with the following command on the root of the directory

./gradlew verifyGoogleJavaFormat

It any error are reported please run the following command to try to fix it

./gradlew googleJavaFormat

p.s: The gradle plugin work with all the JDK version >= 9 (or better with java byte code version compatible with the version 55.0)

For more details about the JDK support see the this issue and to know more about the Google Java code Style see the this reference

Actual Style

Example with code

JTextFieldPlaceholder passwordFieldForm = new JTextFieldPlaceholder(new JPasswordField());
passwordFieldForm.setPlaceholderText("Password")
                .setIcon(
                        MaterialImageFactory.getInstance().getImage(
                                GoogleMaterialDesignIcons.VISIBILITY_OFF
                        ))
                .setSelectedIcon(
                        MaterialImageFactory.getInstance().getImage(
                                GoogleMaterialDesignIcons.VISIBILITY,
                                MaterialColors.LIGHT_BLUE_400
                        )
                )
                .setDimension(150, 35)
                .addAction(new AbstractAction() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JPasswordField passwordField = (JPasswordField) passwordFieldForm.getTextFiled();
                        if (!passwordFieldForm.isSelected()) {
                            passwordField.setEchoChar((char) UIManager.get("PasswordField.echoChar"));
                        } else {
                            passwordField.setEchoChar((char) 0);
                        }
                    }
                });

In this example is use material-ui-swing library, you can set all type icon you want, by default there are two icons, as:

List of projects that used this component

Author

This component is developer by @vincenzopalazzo

In addition, this component is developed in collaborations with Arizona State University.