Wrox Programmer Forums
|
BOOK: Beginning Java 2
This is the forum to discuss the Wrox book Beginning Java 2, SDK 1.4 Edition by Ivor Horton; ISBN: 9780764543654
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2003, 10:04 PM
Registered User
 
Join Date: Oct 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default refreshing the table

does anyone knows how to refresh a table I tried to refresh but after
I input a data but it doesn't seem to work
thank you very much for your assistance
anyway here's the source code i've been working on
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class InputAbook2 extends JPanel
{

       final JTextField FieldName = new JTextField(20);
    final JTextField FieldLastName = new JTextField(20);
    final JTextField FieldAddress = new JTextField(20);
    final JTextField FieldPhNum = new JTextField(20);
    final JTextArea TAreaNotes = new JTextArea(5,20);

   public InputAbook2(){

    setLayout(new GridBagLayout());
    JLabel lName = new JLabel("First Name");
    JLabel lLastName = new JLabel("Last Name");
    JLabel lAddress = new JLabel("Address");
    JLabel lPhNum = new JLabel("Phone Number");
    JLabel lNotes = new JLabel("Notes");
    JButton InButton = new JButton("Input");
    InButton.setMnemonic('I');
    InButton.addActionListener(new InButtonListener());
     JButton ClButton = new JButton("Clear");
    ClButton.setMnemonic('C');
      ClButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          FieldName.setText("");
          FieldLastName.setText("");
          FieldAddress.setText("");
          FieldPhNum.setText("");
          TAreaNotes.setText("");
          FieldName.requestFocus();
        }
      });



  GridBagConstraints pos = new GridBagConstraints();
  pos.anchor = GridBagConstraints.WEST;

  pos.gridx = 1;
  pos.gridy = 1;
  add(lName,pos);
  pos.gridx++;
  add(FieldName,pos);
  pos.gridy++;
  pos.gridx=1;
  add(lLastName,pos);
  pos.gridx++;
  add(FieldLastName,pos);
  pos.gridy++;
  pos.gridx=1;
  add(lAddress,pos);
  pos.gridx++;
  add(FieldAddress,pos);
  pos.gridy++;
  pos.gridx=1;
  add(lPhNum,pos);
  pos.gridx++;
  add(FieldPhNum,pos);
  pos.gridy++;
  pos.gridx=1;
  add(lNotes,pos);
  pos.gridx++;
  add(TAreaNotes,pos);
  pos.gridy++;
  pos.gridx=1;
  add(InButton,pos);
  pos.gridx++;
  add(ClButton,pos);

 }
private class InButtonListener implements ActionListener
{
    public void actionPerformed(ActionEvent e)
     {
             AddressBook addbook =new AddressBook();
             ArrayList talist=addbook.inputData(FieldName.getText(),Field LastName.getText(),
             FieldAddress.getText(),FieldPhNum.getText(),TAreaN otes.getText());
             try
            {
            String file="Addressbook.nad";
            FileWriter fw = new FileWriter (file);
              BufferedWriter bw = new BufferedWriter (fw);
              PrintWriter outFile = new PrintWriter (bw,false);
            Iterator taliterator =talist.iterator();

            while(taliterator.hasNext())
            {

                 outFile.println(FieldName.getText() + "~" +
                 FieldLastName.getText() + "~" +
                 FieldAddress.getText() + "~" +
                 FieldPhNum.getText() + "~" +
                 TAreaNotes.getText());
                 outFile.close();

            }
            }
            catch (IOException exception)
            {
         System.out.println (exception);
              }
            FieldName.setText("");
          FieldLastName.setText("");
          FieldAddress.setText("");
          FieldPhNum.setText("");
          TAreaNotes.setText("");
          FieldName.requestFocus();

             addbook.readFile();
             AddressTable addtable =new AddressTable();
             addtable.showTable();
             addtable.refreshTable();
    }
}


import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
import java.util.Vector;


public class AddressTable extends JPanel
{
    AddressBook addbook =new AddressBook();
    DefaultTableModel tablemodel = new DefaultTableModel();
public AddressTable()
    {



    tablemodel.addColumn("Firstname");
    tablemodel.addColumn("Lastname");
    tablemodel.addColumn("Address");
    tablemodel.addColumn("Phone Number");
    tablemodel.addColumn("Notes");
    showTable();
    JTable jt = new JTable(tablemodel);
    add(new JScrollPane(jt));
    setLayout(new FlowLayout());

    }
public void showTable()
    {
    for(int i=0;i<addbook.getAsize();i++)
        {
            String temp= (addbook.getName(i));
            String temp2=(addbook.getFamName(i));
            String temp3= (addbook.getAddress(i));
            String temp4=(addbook.getPhnum(i));
            String temp5= (addbook.getNotes(i));
            String tadd[] = {temp,temp2,temp3,temp4,temp5};
            tablemodel.addRow(tadd);
        }


    }
}

 
Old October 24th, 2003, 10:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have a look at AbstractTableModel.fireTableStructureChanged()

Cheers

Martyn





Similar Threads
Thread Thread Starter Forum Replies Last Post
ODBC linked table showing old data (not refreshing d-fxt Access 3 November 14th, 2007 05:56 PM
Refreshing Forms Brendan Bartley Access 5 June 27th, 2007 07:47 AM
Refreshing AutoNumber kuznickic Access VBA 3 February 12th, 2007 08:40 AM
img not refreshing austinf XSLT 1 June 13th, 2006 03:55 AM
refreshing XML withour refreshing the page sasidhar79 XML 1 January 12th, 2005 05:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.