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 8004961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:04:43+00:00 2026-06-04T17:04:43+00:00

I am working on an swing application and struck at deciding what could be

  • 0

I am working on an swing application and struck at deciding what could be the best way to save values of large number of JTextFields.
The application reads a property file from some network location. Property file have around 10-12 properties for each particular user say propertyA_1 is property for user 1 and propertA_2 for user 2. There will be around 10-12 users in a properties, So it will make around 80 JTextField to show values. Each user’s properties will be shown on a JTabbedPane.
What I want to do now is that when user changes value of any JTextField for any user shown in each JTabbedPane and clicks on “Save” buttton, the value for the property should be saved.
Tell me what could be the best way to handle large number of JtextField. I think of doing it 2 ways

  1. On Click of “Save” button save each value of property by getting value from all JTextFields.
  2. Some way to get only those JTextFields for which text is changed and save their values.

I am not sure how to do the thing by Option 2.But I think this is the best way.

Here is my code :

public class IOSAutomationTool1 implements ActionListener {

       JButton saveButton  = new JButton("Click to Save");

    /**
     * @param args the command line arguments
     */

    public  void Test() throws IOException {

         File file = new File("C:\\Documents and Settings\\test\\Desktop\\test.properties");

         if( file != null ){

             Properties property = new Properties();

             property.load(new FileInputStream(file));

              JFrame frame = new JFrame("IOSAutomationToolFourthPage");
              frame.setLayout(new FlowLayout());
              JPanel framePanel = new JPanel();
              JPanel buttonPanel = new JPanel();
              framePanel.setSize(700,700);
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              String numberOfClients = property.getProperty("numberOfClients");
              System.out.println("number of clients: "+numberOfClients);


                saveButton.addActionListener(this);
                buttonPanel.add(saveButton);
              if (!numberOfClients.isEmpty()) {

                   int numberOfClientNumb = Integer.parseInt(numberOfClients);

                      System.out.println("numberOfClientNumb ::" + numberOfClientNumb);

                       JTabbedPane tab = new JTabbedPane();

                      // JTabbedPane tab2 = new JTabbedPane();
                    for( int i=1; i<=numberOfClientNumb; i++){

                       JPanel panel = new JPanel();
                      panel.setSize(400, 400);
                      panel.setLayout(new GridBagLayout());
                      GridBagConstraints gbc = new GridBagConstraints();
                       gbc.insets = new Insets(1, 1, 1, 1);

                        gbc.fill = GridBagConstraints.BOTH;
                        gbc.weightx = 0;
                        gbc.gridx = 0;

                      //Remote IP 
                      JLabel remoteIPLbl = new JLabel("Remote IP : ");
                      panel.add(remoteIPLbl,gbc);
                      JLabel userNameLbl = new JLabel("User Name : ");
                      panel.add(userNameLbl,gbc);
                      JLabel remotePasswordLbl = new JLabel("Remote Password : ");
                      panel.add(remotePasswordLbl,gbc);
                      JLabel remotePathLbl = new JLabel("Remote Path : ");
                      panel.add(remotePathLbl,gbc);
                      JLabel deviceOrSimulatorLbl = new JLabel("Device or Simulator : ");
                      panel.add(deviceOrSimulatorLbl,gbc);

                      gbc.gridx = 1;
                      gbc.weightx = 1;

                      String remoteIPVal = property.getProperty("remoteIP_"+i);
                      JTextField remoteIPField = new JTextField(remoteIPVal);
                      //remoteIPLbl.setBounds(50, 100, 2, 2);
                     remoteIPField.setBounds(200, 100, 2, 2);
                      remoteIPField.setColumns(30);
                      panel.add(remoteIPField,gbc);    

                      //Remote User Name


                      String userNameVal = property.getProperty("remoteUserName_"+i);
                      JTextField userNameField = new JTextField(userNameVal);
                     // userNameLbl.setBounds(50, 200, 2, 2);
                      userNameField.setBounds(200, 200, 2, 2);
                      userNameField.setColumns(20);
                      panel.add(userNameField,gbc);   

                      //Remote Password

                      String remotePasswordVal = property.getProperty("remotePassword_"+i);
                      JTextField remotePasswordField = new JTextField(remotePasswordVal);
                     // remotePasswordLbl.setBounds(50, 300, 2, 2);
                      remotePasswordField.setBounds(200, 300, 2, 2);
                      remotePasswordField.setColumns(20);
                      panel.add(remotePasswordField,gbc); 


                      //Remote Path

                      String remotePathVal = property.getProperty("remotePath_"+i);
                      JTextField remotePathField = new JTextField(remotePathVal);
                     // remotePathLbl.setBounds(50, 400, 2, 2);
                     remotePathField.setBounds(200, 400, 2, 2);
                      remotePathField.setColumns(100);
                      panel.add(remotePathField,gbc); 



                      //deviceOrSimulator

                      String deviceOrSimulatorVal = property.getProperty("deviceOrSimulator_"+i);
                      JTextField deviceOrSimulatorField = new JTextField(deviceOrSimulatorVal);
                      //deviceOrSimulatorLbl.setBounds(50, 500, 2, 2);
                      deviceOrSimulatorField.setBounds(200, 500, 2, 2);
                      deviceOrSimulatorField.setColumns(1);
                      panel.add(deviceOrSimulatorField,gbc); 


                      tab.add("Client "+i,panel);
                      System.out.println(""+i);                     
                   }

                    framePanel.add(tab);

                    frame.add(framePanel);

                   // frame.setLayout(new Lay);
              }
               //frame.add(saveButton);
               frame.add(buttonPanel);
              frame.setSize(800, 800);
              frame.pack();
              frame.setVisible(true);

         }
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");

        if(e.getSource() == saveButton){
            System.out.print("button clicked...........");
        }
    }

    public static void main(String[] args) throws IOException{

        IOSAutomationTool1 obj = new IOSAutomationTool1();
        obj.Test();
    }
}
  • 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-06-04T17:04:44+00:00Added an answer on June 4, 2026 at 5:04 pm

    To elaborate a bit over what @nlcE cOw is suggesting, what you could do is something like this:

    1) Make your property final:

            final Properties property = new Properties();
    

    2) Before your for-loop, create a DocumentListener:

        DocumentListener listener = new DocumentListener() {
    
            private void updatePropertyForEvent(final Properties property, DocumentEvent e) {
                Document document = e.getDocument();
                Object value = document.getProperty("key");
                if (value !=null)
                    try {
                        property.setProperty((String) value, document.getText(0, document.getLength()));
                    } catch (BadLocationException e1) {
                        // Should not happpen
                        e1.printStackTrace();
                    }
            }
    
            @Override
            public void removeUpdate(DocumentEvent e) {
                updatePropertyForEvent(property, e);
            }
    
            @Override
            public void insertUpdate(DocumentEvent e) {
                updatePropertyForEvent(property, e);                
            }
    
            @Override
            public void changedUpdate(DocumentEvent e) {
                updatePropertyForEvent(property, e);                
            }
        };
    

    3) For each textfield you create, you put a property on the associated document that will store which property it represents and you add the listener as a DocumentListener:

    String remotePasswordVal = property.getProperty("remotePassword_"+i);
    JTextField remotePasswordField = new JTextField(remotePasswordVal);
    remotePasswordField.getDocument().putProperty("key", "remotePassword_"+i);
    remotePasswordField.getDocument().addDocumentListener(listener);
    

    4) When you press “Save”, you simply save property to an outputStream.

    This is the quick & dirty solution. A cleaner option would be to use a proper MVC-pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a Swing application, what is the best way to send data (interact) between
I'm working on a Swing application (currently running on Java 1.6 update 11) which
I have a really strange issue. I am working on a Java SWING application
I have a calculator application in java swing, which is working properly with mouse
So, I'm working with swing and I need to find a clean (non-CPU-hogging-way) to
I'm currently working on a (rather large) pet project of mine , a Swing
I'm working on swing application that relies on an embedded H2 database. Because I
Hey all, I'm currently working on a Java Swing application and I was looking
I'm working on Java Swing application with Google Guice as an IOC container. Things
I am working in a java swing application. In that application i have to

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.