Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7032381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:55:40+00:00 2026-05-28T00:55:40+00:00

I have been facing the above mentioned problem in my java application that I

  • 0

I have been facing the above mentioned problem in my java application that I recently created. Even though I clearly set the field as JPasswordField and have tried to mask the password with astericks, I continue to face this issue. I issue does not occur when we edit the password field it occurs only when you select the row. For example I have 2 columns in a row and if I select the entire row and try to copy paste the row in notepad the pasword appears. I’m new in the world of java programming, if someone can help will be of great help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:55:41+00:00Added an answer on May 28, 2026 at 12:55 am

    What you want is rather logical. When copy-pasting the data from your table the rendering should be respected.

    The standard copy action will use the data available in your model, where the password is available as plain text. We could start a discussion whether you want to have your model contain a password as plain text, without any hashing applied to it … but that does not answer your question.

    For your question you should modify the behavior of the cut/copy actions of the JTable. Take a look at the Drag and drop Swing tutorial, and more specifically to the Adding Cut, Copy and Paste section. Unfortunately I do not immediately find an example to refer to.

    Edit

    Find below an example of a JXTable which uses the rendered values for the copy-action (I did not copy-pasted the imports). A little side-note about the code:

    1. It uses SwingX to illustrate something for kleopatra as well
    2. The example TableModel and its elements are rather stupid. To avoid too much work I needed something similar to our real product to be able to copy some of the code
    3. The SpeedStringValue and AltitudeStringValue classes violate the StringValue interface as they return null. I was too lazy to define a new interface, and the StringValue instance I set on the SwingX DefaultTableRenderer behaves according to the documentation. I think however that having separate StringValue instances which each have knowledge for converting a specific class to String is a real-world use-case which is lacking in SwingX
    4. The TransferHandler reuses the StringValue logic to create a Table containing only String instances, and then falls back on the default JTable behavior. This allows to reuse the logic implemented in the renderer, and allows to copy the visual values instead of the model values. I am not sure whether this is the nicest solution, but it works. It would be nice however if similar behavior was standard in SwingX, as they already have the infrastructure
    5. The code lacks comments as it was already long enough. If something is unclear, leave a comment and I will try to clarify

      public class TableTransferHandlerDemo {
      
        public static void main( String[] args ) throws InvocationTargetException, InterruptedException {
          EventQueue.invokeAndWait( new Runnable() {
            public void run() {
              JFrame frame = new JFrame( "TestFrame" );
      
              JPanel contentPane = new JPanel( new BorderLayout(  ) );
              contentPane.add( createTable(), BorderLayout.CENTER );
              frame.getContentPane().add( contentPane );
      
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible( true );
            }
          } );
        }
      
        private static CompositeStringValue createStringValue() {
          CompositeStringValue stringValue = new CompositeStringValue();
          stringValue.delegates.add( new AltitudeStringValue() );
          stringValue.delegates.add( new SpeedStringValue() );
          return stringValue;
        }
      
        public static JXTable createTable(){
          final JXTable table = new JXTable(  );
          table.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
          table.setModel( createTableModel() );
          CompositeStringValue stringValue = createStringValue();
          table.setDefaultRenderer( Object.class, new DefaultTableRenderer( stringValue ) );
          table.setTransferHandler( new TableTransferHandler( table, stringValue ) );
          //make sure ctrl-c triggers a copy
          InputMap inputMap = table.getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
          inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_C, InputEvent.CTRL_MASK ), "copyAction" );
          table.getActionMap().put( "copyAction", new AbstractAction() {
            public void actionPerformed( ActionEvent e ) {
              ActionEvent event = new ActionEvent( table, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers() );
              TransferHandler.getCopyAction().actionPerformed( event );
            }
          } );
          return table;
        }
      
        public static class Speed{
          public double speed;
          public String unit = "km/h";
          public Speed( double speed ){ this.speed = speed;}
        }
        public static class Altitude{
          public double altitude;
          public String unit = "m";
          public Altitude( double altitude ){ this.altitude = altitude; }
        }
        public static class SpeedStringValue implements StringValue{
          public String getString( Object o ) {
            if ( o instanceof Speed ){
              return ( ( Speed ) o ).speed + ( ( Speed ) o ).unit;
            }
            return null;
          }
        }
        public static class AltitudeStringValue implements StringValue{
          public String getString( Object o ) {
            if ( o instanceof Altitude ){
              return ( ( Altitude ) o ).altitude + ( ( Altitude ) o ).unit;
            }
            return null;
          }
        }
        public static class CompositeStringValue implements StringValue{
          public List<StringValue> delegates = new ArrayList<StringValue>(  );
          public String getString( Object o ) {
            for ( StringValue stringValue : delegates ) {
              String string = stringValue.getString( o );
              if ( string != null ) return string;
            }
            return o != null ? o.toString() : "null";
          }
        }
        public static TableModel createTableModel(){
          return new DefaultTableModel(
              new Object[][]{ new Object[]{ new Speed( 10 ), new Altitude( 100 )},
                  new Object[]{ new Speed( 20 ), new Altitude( 200 ) }},
              new Object[]{"Speed", "Altitude"} );
        }
        public static class TableTransferHandler extends TransferHandler{
          private JXTable table;
          private StringValue stringValue;
      
          public TableTransferHandler( JXTable aTable, StringValue aStringValue ) {
            table = aTable;
            stringValue = aStringValue;
          }
          @Override
          public void exportToClipboard( JComponent aComponent, Clipboard aClipboard, int aAction ) throws IllegalStateException {
            JTable table = createTable();
            table.getTransferHandler().exportToClipboard( table, aClipboard, aAction );
          }
          @Override
          public void exportAsDrag( JComponent aComponent, InputEvent aEvent, int aAction ) {
            JTable table = createTable();
            table.getTransferHandler().exportAsDrag( table, aEvent, aAction );
          }
          @Override
          protected Transferable createTransferable( JComponent c ) {
            //this transfer handler should not create any transferables
            return null;
          }
          /**
           * Create a table, representing the JXTable containing only Strings
           */
          private JTable createTable() {
            JTable table = new JTable( new StringTableModel( this.table, stringValue ) );
            table.setSelectionModel( this.table.getSelectionModel() );//make sure the selection is synced
            return table;
          }
        }
      
        private static class StringTableModel extends AbstractTableModel {
          private JXTable delegateTable;
          private StringValue stringValue;
      
          private StringTableModel( JXTable aTable, StringValue aStringValue ) {
            delegateTable = aTable;
            stringValue = aStringValue;
          }
      
          public int getRowCount() {
            return delegateTable.getModel().getRowCount();
          }
      
          public int getColumnCount() {
            return delegateTable.getModel().getColumnCount();
          }
      
          public Object getValueAt( int aRowIndex, int aColumnIndex ) {
            return stringValue.getString( delegateTable.getValueAt( aRowIndex, aColumnIndex ) );
          }
        }
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently, I have been facing a problem with throwing exception in JDBC topic. I
I have a public facing website that has been receiving a number of SQL
I have been facing a scenario where I have observed that Android's TelephonyManager is
I am working on a Google App Engine application, and have been facing some
I have a problem about weblogic console. I have been facing with this problem
We have been facing a small problem in MySQL procedure. We have placed some
I have been facing a problem since 40days . i didn't get a solution
Context: An ongoing problem we have been facing is unit testing our market data
So, I have been facing a problem with using subprocess for a python app
Here is the problem I am facing. I have been tasked with testing the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.