Masking Password Data in Non-editable Cells

Masking Password Data in Non-editable Cells

Suppose you want to store password values in a table, but you don’t want that password data to be displayed. While there are other ways to accomplish this, masking the password fields makes the logic to maintain the data easier.

The code below initializes individual columns in a table. It determines in the method if the cell is a password field by looking at the column heading:

/*** This method sets column sizes and cell renderers.**/private void initColumns(JTable table) {   XMLTableModel model = (XMLTableModel)table.getModel();   TableColumn column = null;   Vector longValues = model.columnNames;   TableCellRenderer headerRenderer =        table.getTableHeader().getDefaultRenderer();   for (int i = 0; i < longValues.size(); i++) {            // Format other column names ....            // Set password field to hide data	      if(column.getHeaderValue().equals("Password")){	  column.setCellRenderer(new PasswordCellRenderer());      }   }}

If the cell is a password field, the code sets the cell renderer for the cell to the class, like in the code below. Setting the text to any value renders asterisks in the field because it extends the JPasswordField class. It does not affect the actual value of the cell, but masks the password data.

class PasswordCellRenderer extends JPasswordField      implements TableCellRenderer {   public PasswordCellRenderer() {      super();            // This displays astericks in fields since it is a password.      // It does not affect the actual value of the cell.      this.setText("filler123");   }   public Component getTableCellRendererComponent(      JTable  arg0,      Object arg1,      boolean arg2,      boolean arg3,      int arg4,      int arg5) {            return this;   }}
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing