Strange Behavior of the JPasswordField

The JPasswordField included in Swing exhibits a strange behavior?it moves the caret to the right as far as the width of the character you already typed. The problem is that the component doesn’t show that character, but only an asterisk (*). This, added to the fact that the field has the same default font as the JTextField (in NT, Arial) which is not of constant width, results in the visual effect that the caret doesn’t move with the latest typed character, but only a little more.

This can be tested typing the string “mmmmmmmmm” (the character of maximum-width in Java). To fix this (a workaround), set the font property of the JPasswordField to a fixed-width (non-TrueType) font, for example: the monospaced font.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS