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

  • Home
  • SEARCH
  • 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 8808957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:45:06+00:00 2026-06-14T02:45:06+00:00

if(e.getActionCommand().equals(save to file)) { System.out.println(save is pressed); StringBuffer fileContent = new StringBuffer(); TableModel tModel

  • 0
if(e.getActionCommand().equals("save to file"))
    {
        System.out.println("save is pressed");
        StringBuffer fileContent = new StringBuffer();
        TableModel tModel = m_table.getModel();
        for (int i = 1; i < tModel.getRowCount(); i++) 
        {
         for(int j=0;j<tModel.getColumnCount();j++)
         {
            Object cellValue = tModel.getValueAt(i, j);
            // ... continue to read each cell in a row
            fileContent.append(cellValue);
            // ... continue to append each cell value
            fileContent.append(" ");
         }
         fileContent.append("\n");
        }
        FileWriter fileWriter;
        try {
            fileWriter = new FileWriter(new File("data.txt"));
            fileWriter.write(fileContent.toString());
            fileWriter.flush();
            fileWriter.close();
            }
        catch (IOException e1) 
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

I have created a JDialog in which there is a table. I am able to save the table data into the file on a button click, but what i want to do is to keep that data persisted in the table so when the next time the program is run, that data is available and displayed in the table when a confirm button is pressed. Though I read about Java persistence and Java serialization concepts, I’m not getting the clear idea which technique is appropriate and how to use for this problem.

  • 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-14T02:45:07+00:00Added an answer on June 14, 2026 at 2:45 am

    Consider saving just the TableModel data using java.util.Preferences, exemplified here, or javax.jnlp.PersistenceService, cited here.

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

Sidebar

Related Questions

I want to create a system that has a time in/time out feature. I
I am new to java swing. I have pasted my code below for your
I'm very new to Java and am having some issues looping through JCheckBoxes on
What is getSource? and what does it return? and what is getActionCommand() and what
I searched for tutorials for adding button in jtable and found a class file
i want to open .chm help file when click on Help button on swing
I have a HashMap of JButtons which represents pictures. this.nahledy.put(s.getName(), new JButton()); this.nahledy.get(s.getName()).addActionListener(); but
I want to update a JLabel each time with the name of the file
I'm new to graphics programming and am having some difficluties with using a KeyListener
A shout out to the Swing gurus out there!! I've been doing Swing programming

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.