Skip to content

JToggleablePasswordField is a Java Swing component that extends the standard JPasswordField with the ability to toggle between showing and hiding the password.

License

Notifications You must be signed in to change notification settings

Valkryst/JToggleablePasswordField

Repository files navigation

JToggleablePasswordField is a Java Swing component that extends the standard JPasswordField with the ability to toggle between showing and hiding the password. It features a clickable visibility icon that allows users to temporarily reveal their password to verify its correctness.

Requires Java 11.

Table of Contents

Installation

JToggleablePasswordField is hosted on the JitPack package repository which supports Gradle, Maven, and sbt.

Gradle Gradle

Add JitPack to your build.gradle at the end of repositories.

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Add JToggleablePasswordField as a dependency.

dependencies {
	implementation 'com.github.Valkryst:JToggleablePasswordField:2025.5.8'
}

Maven Maven

Add JitPack as a repository.

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Add JToggleablePasswordField as a dependency.

<dependency>
    <groupId>com.github.Valkryst</groupId>
    <artifactId>JToggleablePasswordField</artifactId>
    <version>2025.5.8</version>
</dependency>

Scala SBT Scala SBT

Add JitPack as a resolver.

resolvers += "jitpack" at "https://jitpack.io"

Add JToggleablePasswordField as a dependency.

libraryDependencies += "com.github.Valkryst" % "JToggleablePasswordField" % "2025.5.8"

Features

  • Adaptive styling which respects the current Look and Feel.
  • Automatic scaling of the component's font and icon size based on the component's dimensions.
  • Password visibility toggling with a clickable icon.

Example

This creates a new JToggleablePasswordField and displays it in a JFrame.

public class Driver {
    public static void main(final String[] args) {
        SwingUtilities.invokeLater(() -> {
            final JToggleablePasswordField passwordField = new JToggleablePasswordField("secret password");

            final JFrame frame = new JFrame("JToggleablePasswordField Example");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setPreferredSize(new Dimension(400, 100));

            final Container contentPane = frame.getContentPane();
            contentPane.setLayout(new BorderLayout());
            contentPane.add(passwordField, BorderLayout.CENTER);

            frame.setVisible(true);
            frame.pack();
            frame.setLocationRelativeTo(null);
        });
    }
}

About

JToggleablePasswordField is a Java Swing component that extends the standard JPasswordField with the ability to toggle between showing and hiding the password.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •  

Languages