Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 23rd, 2003, 10:04 PM
Registered User
 
Join Date: Oct 2003
Location: Thai Pao Lo, , .
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);
        }


    }
}

  #2 (permalink)  
Old October 24th, 2003, 10:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have a look at AbstractTableModel.fireTableStructureChanged()

Cheers

Martyn
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:09 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.