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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:44:14+00:00 2026-06-17T01:44:14+00:00

I have a a table that show all book list from a txt file

  • 0

I have a a table that show all book list from a txt file correctly.
I add a new button to frame that when get id number an its textfield and if found, delete it record from file, but if i want to delete from table too, i shoud redisplay the table frame.
I want to, when a record deleted from file, my table automatically refresh itself and no need to redisplay table frame.
my code is this:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

public class ReadBookFileToListM {

public ReadBookFileToListM(){
   final ReadBookFileToList rbftl=new ReadBookFileToList();
   final JFrame Bframe=new JFrame("All Book List");
  final JTextField tf1=new JTextField("             ");
  final JLabel foundlable=new JLabel();
    JButton button1=new JButton("Back To Main Page");
    JButton button2=new JButton("Exit");
    JButton button3=new JButton("Delete Book");
    button1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Bframe.setVisible(false);
            new MainFrame().setVisible(true);
        }
    });
    button2.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });


    JTable Btable=new JTable(rbftl);

    button3.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            boolean find=false;
    String Bookid=tf1.getText();
    File Mf=new File("D:\\AllBookRecords.txt");
    File Tf=new File("D:\\Boutput.txt");
    try{
        FileReader Bfr=new FileReader(Mf);
        BufferedReader Bbr=new BufferedReader(Bfr);
        PrintWriter Bpw=new PrintWriter(new FileWriter(Tf));
        String Bs;
        while( (Bs=Bbr.readLine()) != null ){
                String[] Ust=Bs.split("   ");
                String Bname=Ust[0];
                String Bdate=Ust[1];
                String id=Ust[2];
            if(id.equals(Bookid.trim())){
                find=true;
                foundlable.setText("Book Found,    "+ Bname + "  " + Bdate);
            }
            if(!id.equals(Bookid.trim())){
                Bpw.println(Bs);
            }
        }
        Bpw.close();
        Bbr.close();
        Mf.delete();
        Tf.renameTo(Mf);

    } catch(FileNotFoundException fnfe){
        foundlable.setText("File Not Found");
    } catch(IOException ioe){
        foundlable.setText("IO Error");
        ioe.printStackTrace();
    }
    finally{
        rbftl.fireTableDataChanged();
        if(find)
        foundlable.setText("Book Deleted");
        else
            foundlable.setText("Book Not Found!");
            tf1.setText("     ");
    }
        }
    });

    JPanel panel=new JPanel();
    JScrollPane sp=new JScrollPane(Btable);
    button1.setToolTipText("To Go Main Page, Click here");
    button2.setToolTipText("Terminate Program");
    panel.add(sp);
    panel.add(button1);
    panel.add(button2);
    panel.add(button3);
    panel.add(tf1);
    panel.add(foundlable);
    Bframe.add(panel);
    Btable.setAutoCreateRowSorter(true);
    Bframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Bframe.setBounds(300, 60, 550, 550);
    Bframe.setVisible(true);
}

public static void main(String[] args){
    new ReadBookFileToListM();
}
  }

Thank You.

  • 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-17T01:44:15+00:00Added an answer on June 17, 2026 at 1:44 am

    addNotify() method JTable object may be useful, as it reconfigure enclosing scrollpane.

    Just add tableName.addNotify() after you delete row in table.

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

Sidebar

Related Questions

I have table that I insert data with following query (from c# code): INSERT
I have a table that contains multiple dropdown menus for a list of profile
I have a table that I need to update where all columns are optionally
Hi all I have an appointments table that has among other fields a DATE
I have a table which contains student grades (SAG). I need to show all
I have a table that holds all of the items we have sold. There
I have a table Items which stores fetched book data from Amazon. This Amazon
My question is that with example. I have to show all categories of books
I have a table that displays rows based on a drop down list option.
I have a table that displays all classes available. The TR ID for each

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.