PageUp/PageDown By using Default Table Model

Hi all,
iam using Default Table model for my jtable i want to do pageup and pagedown operation .
TableColumnModel cm1 = new DefaultTableColumnModel();
DefaultTablemodel md = new DefaultTableModel(row,col);
JTable t = new JTable(md,cm1);
i have 500 rows currently in my database i want to display 100 in the first page and if i press the pagedown button the next 100 has to be diplayed wether this is possible here.. if possible please help mee.

Hi,
could you please avoid double posting:
http://forum.java.sun.com/thread.jsp?forum=57&thread=566380&tstart=0&trange=15
especially with different subjects.
It considerably reduces the overall efficiency as people will try to
help you while the answer could already have been given in the another thread.
If you want to push up the stack your message, reply to it,
post more code, list the ideas that you've envisaged and so on.
regards.

Similar Messages

  • Is it posiible to paging up paging down in Jtable using Default Table Model

    Hi All!
    Is it possible to do Page up and Page down in JTable using Default Tble Model?
    Kindly reply!

    yes
    it is posiible to paging up paging down in Jtable using Default Table Model. just go thru the JAVA API you will get the results.

  • How to add image in jtable header using 'Default table model'

    Hi,
    I created a table using "DefaultTableModel".
    im able to add images in table cells but not in 'table header'.
    i added inages in table by overriding "getColumnClass" of the DefaultTableModel.
    But what to do for headers?
    please help.
    Thanks in advance.

    The 'Java 5 tutorial' is really an outstanding oneI should note the the current tutorial on the Sun website has bee updated for Java 6. It contains updates to reflect the changes made in JDK6. Once of the changes is that sorting of tables is now supported directly which is why I needed to give you the link to the old tutorial.
    http://java.sun.com/docs/books/tutorial/uiswing/TOC.html

  • JTable Problem(Default Table Model)

    Hi all,
    iam using Default Table model for my jtable i want to do pageup and pagedown operation .
    TableColumnModel cm1 = new DefaultTableColumnModel();
    DefaultTablemodel md = new DefaultTableModel(row,col);
    JTable t = new JTable(md,cm1);
    i have 500 rows currently in my database i want to display 100 in the first page and if i press the pagedown button the next 100 has to be diplayed wether this is possible here.. if possible please help mee.

    sample code :
    // PagingModel.java
    // A larger table model that performs "paging" of its data. This model reports a
    // small number of rows (e.g., 100 or so) as a "page" of data. You can switch pages
    // to view all of the rows as needed using the pageDown( ) and pageUp( ) methods.
    // Presumably, access to the other pages of data is dictated by other GUI elements
    // such as up/down buttons, or maybe a text field that allows you to enter the page
    // number you want to display.
    import javax.swing.table.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class PagingModel extends AbstractTableModel {
    protected int pageSize;
    protected int pageOffset;
    protected Record[] data;
    public PagingModel( ) {
    this(10000, 100);
    public PagingModel(int numRows, int size) {
    data = new Record[numRows];
    pageSize = size;
    // Fill our table with random data (from the Record( ) constructor).
    for (int i=0; i < data.length; i++) {
    data[i] = new Record( );
    // Return values appropriate for the visible table part.
    public int getRowCount( ) { return Math.min(pageSize, data.length); }
    public int getColumnCount( ) { return Record.getColumnCount( ); }
    // Work only on the visible part of the table.
    public Object getValueAt(int row, int col) {
    int realRow = row + (pageOffset * pageSize);
    return data[realRow].getValueAt(col);
    public String getColumnName(int col) {
    return Record.getColumnName(col);
    // Use this method to figure out which page you are on.
    public int getPageOffset( ) { return pageOffset; }
    public int getPageCount( ) {
    return (int)Math.ceil((double)data.length / pageSize);
    // Use this method if you want to know how big the real table is. You could also
    // write "getRealValueAt( )" if needed.
    public int getRealRowCount( ) {
    return data.length;
    public int getPageSize( ) { return pageSize; }
    public void setPageSize(int s) {
    if (s == pageSize) { return; }
    int oldPageSize = pageSize;
    pageSize = s;
    pageOffset=(oldPageSize * pageOffset) / pageSize;
    fireTableDataChanged( );
    // Update the page offset and fire a data changed event (all rows).
    public void pageDown( ) {
    if (pageOffset < getPageCount( ) - 1) {
    pageOffset++;
    fireTableDataChanged( );
    // Update the page offset and fire a data changed (all rows).
    public void pageUp( ) {
    if (pageOffset > 0) {
    pageOffset--;
    fireTableDataChanged( );
    // We provide our own version of a scrollpane that includes
    // the Page Up and Page Down buttons by default.
    public static JScrollPane createPagingScrollPaneForTable(JTable jt) {
    JScrollPane jsp = new JScrollPane(jt);
    TableModel tmodel = jt.getModel( );
    // Don't choke if this is called on a regular table . . .
    if (! (tmodel instanceof PagingModel)) {
    return jsp;
    // Go ahead and build the real scrollpane.
    final PagingModel model = (PagingModel)tmodel;
    final JButton upButton = new JButton("Up");
    upButton.setEnabled(false); // Starts off at 0, so can't go up
    final JButton downButton = new JButton("Down");
    if (model.getPageCount( ) <= 1) {
    downButton.setEnabled(false); // One page...can't scroll down
    upButton.addActionListener(new ActionListener( ) {
    public void actionPerformed(ActionEvent ae) {
    model.pageUp( );
    // If we hit the top of the data, disable the Page Up button.
    if (model.getPageOffset( ) == 0) {
    upButton.setEnabled(false);
    downButton.setEnabled(true);
    downButton.addActionListener(new ActionListener( ) {
    public void actionPerformed(ActionEvent ae) {
    model.pageDown( );
    // If we hit the bottom of the data, disable the Page Down button.
    if (model.getPageOffset( ) == (model.getPageCount( ) - 1)) {
    downButton.setEnabled(false);
    upButton.setEnabled(true);
    // Turn on the scrollbars; otherwise, we won't get our corners.
    jsp.setVerticalScrollBarPolicy
    (ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    jsp.setHorizontalScrollBarPolicy
    (ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    // Add in the corners (page up/down).
    jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton);
    jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton);
    return jsp;
    // Record.java
    // A simple data structure for use with the PagingModel demo
    class Record {
    static String[] headers = { "Record Number", "Batch Number", "Reserved" };
    static int counter;
    String[] data;
    public Record( ) {
    data = new String[] { "" + (counter++), "" + System.currentTimeMillis( ),
    "Reserved" };
    public String getValueAt(int i) { return data[i]; }
    public static String getColumnName(int i) { return headers[i]; }
    public static int getColumnCount( ) { return headers.length; }
    class PagingTester extends JFrame {
    public PagingTester( ) {
    super("Paged JTable Test");
    setSize(300, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    PagingModel pm = new PagingModel( );
    JTable jt = new JTable(pm);
    // Use our own custom scrollpane.
    JScrollPane jsp = PagingModel.createPagingScrollPaneForTable(jt);
    getContentPane( ).add(jsp, BorderLayout.CENTER);
    public static void main(String args[]) {
    PagingTester pt = new PagingTester( );
    pt.setVisible(true);
    }

  • How to Add and delete a row while using Abstract Table Model

    Hi,
    I need to do the following functionalities in JTable.I've done tht but a small problem.
    1. Adding a row (Using addRow() method from DefaultTableModel).
    2. Deleting a row(Using setRowCount() method from Default Table Model).
    3. Sorting the table based on the selection of column(Using TableSorter which is using AbstracTableModel).
    As the sorting is mandatory i've to change my model to Abtract Table Model
    The problem is this Abstract Table Model doesn't have any methods to Add a row or deleting a row (setRowCount()).If anybody has written any utility method for this using Abstract Table Model help me.

    Using TableSorter which is using AbstracTableModel).If your talking about the TableSorter class from the Swing tutorial, then you create the TableSorter class by passing it a TableModel. There is no reason you can't use the DefaltTableModel.
    I changed the code in TableSorterDemo as follows:
            String[] columnNames = {"First Name",
                                            "Last Name",
                                            "Sport",
                                            "# of Years",
                                            "Vegetarian"};
            Object[][] data = {
                {"Mary", "Campione",
                 "Snowboarding", new BigDecimal(1), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new BigDecimal(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new BigDecimal(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new BigDecimal(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new BigDecimal(10), new Boolean(false)}
              DefaultTableModel model = new DefaultTableModel(data, columnNames)
                   public Class getColumnClass(int c)
                        return getValueAt(0, c).getClass();
            TableSorter sorter = new TableSorter(model);
    //        TableSorter sorter = new TableSorter(new MyTableModel()); //ADDED THIS

  • Jtable, sql, default table model

    Hi all,
    I need help. How do I create JTable, generaly Default table model and query which will work with the database. Thx.

    Look to this example
    [http://jfxstudio.wordpress.com/2009/05/25/the-graphic-database-front-end-ii/|http://jfxstudio.wordpress.com/2009/05/25/the-graphic-database-front-end-ii/]
    tables, database and advanced graphics

  • Setting row identifiers in default table model

    hey i'm making a default table model and i cant figure out how to make a row have an identifier. the column one is setColumnIdentifiers but there isn't a code that i could find for a row.. please help thanx kevin

    You are correct, JTable does not support a TableRowModel, therefore it does not support setRowIdentifiers.
    I'm not sure exactly what your requirement is so its hard to make a suggestion. You could add an extra column to your table to contain a row identifier. You could then remove this column from the TableColumnModel to prevent this column from being painted. This [url http://forum.java.sun.com/thread.jsp?forum=31&thread=411506]thread shows how to remove a column from the table.

  • Using custom table model with the Net Beans JTable

    I am using the net beans editor to create an application. For the JTable that net beans provides, I would like to use my own Table Model instead of the default one that is provided. How do I specify to the form editor that I want to use my own TableModel instead of the DeafaultTableModel?

    I am using the net beans editor to create an application. For the JTable that net beans provides, I would like to use my own Table Model instead of the default one that is provided. How do I specify to the form editor that I want to use my own TableModel instead of the DeafaultTableModel?

  • Custom Table Model from Default Table Model

    I'm creating a customised table model to create a table with column header and empty rows.But it is throwing Component paint_imediatly error.If i pass in empty string to the row vector then setNumRows then no problem. If i do like this later it throws me error in my addNewRow method which was working fine before.Can anyone help?I would realy apreaciate it.Thank you.
    Kavitha

    This must be your lucky day :)
    Here is my version of an EditableTableModel which displays an emptyline as the last line
    import java.io.*;
    import java.util.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    * Custom TableModel, allows addition and removal of records/rows and editting of existing values.
    * it also keeps track over which rows have been altered.
    * column 0 is a boolean indicating wheter or not to keep this row/record
    * @author Maurice Marrink
    * @version 1.0
    public class EditableTableModel extends AbstractTableModel implements Serializable, TableModelListener
         protected ArrayList keep,changed;          //houden bij of een rij gedel moet worden en of ie is veranderd (false = delete)
         protected ArrayList[] DATA;
         protected int emptyLineIndex;
         protected String[] kolomNamen;
         protected Object[] kolomTypen;          // bevat een object van dezelfde class als die kolom
         protected int newRowsIndex;               // houd bij vanaf welke rij niewe regels zijn toegevoegd ivm het opslaan in de db
         protected int[]primecolumns;          //houd bij welke kolommen ingevuld moeten worden voordat de volgende regel getoond wordt (default= kolom 1)
         public EditableTableModel()
              keep = new ArrayList();               //visible
              changed=new ArrayList();               // not visisble
              primecolumns=new int[0];
              DATA=new ArrayList[0];
              kolomNamen =new String[0];
              kolomTypen=new Object[0];
              emptyLineIndex=-1;
              newRowsIndex=-1;
         * the constructor, creates a new EditableTableModel
         *@param data          an array of ArrayLists each arrayList contains the values of an entire column
         *@param names          an array containg the names of the columns
         *@param type          an array containing Objects which correspond to the objects in the columns
         public EditableTableModel(ArrayList[] data, String[] names, Object[] type)
              keep = new ArrayList();               //visible
              changed=new ArrayList();               // not visisble     
              primecolumns=new int[1];
              primecolumns[0]=1;
              DATA=data;
              for(int i=0;i<getRowCount();i++)
                   keep.add(new Boolean(true));
                   changed.add(new Boolean(false));
              kolomNamen=names;
              kolomTypen=type;
              emptyLineIndex=getRowCount()-1;
              addNewLine();
              newRowsIndex=emptyLineIndex;               // nieuwe regels beginnen op de lege regel
              addTableModelListener(this);
         * @return the number of rows/records
         public int getRowCount()
              return DATA[0].size();
         *@return the number of columns
         public int getColumnCount()
              return DATA.length+1;
         * returns the object containing the value for this cell
         * indexes start at 0 (wheter or not to keep this row), but the actual data starts at 1
         *@param row          the row in which the cell resides
         *@param column     the column in which the cell resides
         *@return the value of the cell wrapped in the appropiate Object
         public Object getValueAt(int row, int column)
              if(column==0)
                   return keep.get(row);
              else
                   return DATA[column-1].get(row);
         * allows editing of an existing value
         *@param value          the new value, should be of the same Object Type as the existing one
         *@param row               the row nr of the cell
         *@param col               the column nr of the cell
         public void setValueAt(Object value, int row, int col)
              if(col==0)
                   keep.set(row,value);
              else
                   DATA[col-1].set(row,value);
                   changed.set(row, new Boolean(true));
              fireTableCellUpdated(row, col);
         * adds a new "empty" row after all the PrimeColums of the last row have been filled with an acceptable value
         *@see setPrimeColumns
         protected void addNewLine()
              try
                   for(int i=0;i<DATA.length;i++)
                        if(kolomTypen[i] instanceof Integer)
                             DATA.add(new Integer(-1));
                        else
                        if(kolomTypen[i] instanceof Boolean)
                             DATA[i].add(new Boolean(false));
                        else
                        if(kolomTypen[i] instanceof Long)
                             DATA[i].add(new Long(-1));          //displayed as "" by cellrenderer
                        else
                             DATA[i].add(kolomTypen[i].getClass().newInstance());          //nieuw object aanmaken van het type dat gespecificeerd is, Integers en Booleans moet een waarde meegegeven worden
                   keep.add(new Boolean(true));
                   changed.add(new Boolean(false));
                   emptyLineIndex++;
              catch(Exception e)
                   e.printStackTrace();
         public void tableChanged(TableModelEvent e)
              if(e.getFirstRow()==emptyLineIndex)//alleen als de emptyLine ge?dit wordt een regel toevoegen
                   boolean primesfilled=true;
                   for(int i=0;i<primecolumns.length;i++)
                        if(getValueAt(emptyLineIndex,primecolumns[i]).equals(null) || getValueAt(emptyLineIndex,primecolumns[i]).toString().equals("")|| getValueAt(emptyLineIndex,primecolumns[i]).toString().equals("-1"))
                             primesfilled=false;
                             break;
                   if(primesfilled)     //alleen als de primaire sleutel kolommen ingevuld zijn
                        addNewLine();
         * returns the Class type of the Objects representing the column type
         *@param c     the column nr
         public Class getColumnClass(int c)
              if(c==0)
                   return new Boolean(true).getClass();
              else
                   return kolomTypen[c-1].getClass();
         *@param rowIndex the index of the row
         *@param columnIndex     the index of the column
         *@return true if a cell is Editable,false otherwise (all cells are Editable)
         public boolean isCellEditable(int rowIndex, int columnIndex)
              return true;
         * returns the name of the column
         *@param column     the column index
         *@return a String containing the name of the column
         public String getColumnName(int column)
              if(column==0)
                   return "";
              else
                   return kolomNamen[column-1];
         *@return wheter or not 1 or rows is marked for deletion
         public boolean deletionNeeded()
              Boolean B;
              for(int i=0;i<emptyLineIndex;i++)
                   B=(Boolean)keep.get(i);
                   if(!B.booleanValue())
                        return true;
              return false;
         * Deletes all rows which are marked for deletion
         *@return the number of rows that have been deleted
         public int deleteMarkedRows()          // zou niets uit moeten maken of je eerst deleteMarkedRows() of isSavedToDB(true) aanroept
              int aantalRows=0;
              Boolean B;
              for(int i=0;i<emptyLineIndex;i++)
                   B=(Boolean)keep.get(i);
                   if(!B.booleanValue())
                        if(deleteRow(i))
                             aantalRows++;
                             i--;
              return aantalRows;
         * deletes a single row
         *@param row     the row index
         *@return     true if the row was deleted, false otherwise
         protected boolean deleteRow(int row)
              boolean result=false;
              if(row==emptyLineIndex)               // emptyline kan niet gedelete worden
                   return result;
              try
                   for(int j=0;j<DATA.length;j++)
                        DATA[j].remove(row);
                   changed.remove(row);
                   keep.remove(row);
                   emptyLineIndex--;
                   if(row < newRowsIndex)
                        newRowsIndex--;
                   result=true;
              catch(Exception e)
                   e.printStackTrace();
              return result;
         * returns if the row has changed or not
         *@param row          the row index
         *@return true if 1 or more cells in this row had their value changed or if 1 or more rows were added, false otherwise
         public boolean hasChanged(int row)
              Boolean B=(Boolean)changed.get(row);
              return B.booleanValue();
         * Methode waarmee men kan bepalen of 1 van de originele waarden ook veranderd is.
         * Het geeft dus niet aan of er ook nieuwe rijen zijn toegevoegd.
         public boolean hasChanged()
              Boolean B;
              for(int i=0;i<newRowsIndex;i++)
                   B=(Boolean)changed.get(i);
                   if(B.booleanValue())
                        return true;
              return false;
         * if true it sets all flags indicating a change to false, else nothing
         *@param saved     boolean indicating all changes are now to be considerd to be the original values, or not
         public void isSavedToDB(boolean saved)
              if(saved)
                   for(int i=0; i<changed.size();i++)
                        changed.set(i,new Boolean(false));
                   newRowsIndex=emptyLineIndex;
         * @return the row nr. at which newly added entrys begin, updated after isSavedToDB(true) is called
         public int getNewRowsIndex()
              return newRowsIndex;
         * allows the specification of certain columns that need to be filled in, if not a new row will not be made vissible
         *@param columns     an array containing the column indexes which must be set to a valid value
         public void setPrimeColumns(int[] columns)
              primecolumns=columns;
         * allows retrieval of the PrimeColumns
         *@return an arrayof int containing the column indexes
         public int[] getPrimeColumns()
              return primecolumns;
    Ok some of the comments are in dutch go ahead an blame me :(
    if you have any questions, just ask.
    i also have a TableModel which can use automatic numbering
    Oh numbers (currently only Integer and Long) are initiated wth a value of -1 if you want to display them as blank cells like i wanted to you modify a cellrenderer (or use mine)
    Mr Mean

  • JTable column headers not displaying using custom table model

    Hi,
    I'm attempting to use a custom table model (by extending AbstractTableModel) to display the contents of a data set in a JTable. The table is displaying the data itself correctly but there are no column headers appearing. I have overridden getColumnName of the table model to return the correct header and have tried playing with the ColumnModel for the table but have not been able to get the headers to display (at all).
    Any ideas?
    Cheers

    Class PublicationTableModel:
    public class PublicationTableModel extends AbstractTableModel
        PublicationManager pubManager;
        /** Creates a new instance of PublicationTableModel */
        public PublicationTableModel(PublicationManager pm)
            super();
            pubManager = pm;
        public int getColumnCount()
            return GUISettings.getDisplayedFieldCount();
        public int getRowCount()
            return pubManager.getPublicationCount();
        public Class getColumnClass(int columnIndex)
            Object o = getValueAt(0, columnIndex);
            if (o != null) return o.getClass();
            return (new String()).getClass();
        public String getColumnName(int columnIndex)
            System.out.println("asked for column name "+columnIndex+" --> "+GUISettings.getColumnName(columnIndex));
            return GUISettings.getColumnName(columnIndex);
        public Publication getPublicationAt(int rowIndex)
            return pubManager.getPublicationAt(rowIndex);
        public Object getValueAt(int rowIndex, int columnIndex)
            Publication pub = (Publication)pubManager.getPublicationAt(rowIndex);
            String columnName = getColumnName(columnIndex);
            if (columnName.equals("Address"))
                if (pub instanceof Address) return ((Address)pub).getAddress();
                else return null;
            else if (columnName.equals("Annotation"))
                if (pub instanceof Annotation) return ((Annotation)pub).getAnnotation();
                else return null;
            etc
           else if (columnName.equals("Title"))
                return pub.getTitle();
            else if (columnName.equals("Key"))
                return pub.getKey();
            return null;
        public boolean isCellEditable(int rowIndex, int colIndex)
            return false;
        public void setValueAt(Object vValue, int rowIndex, int colIndex)
        }Class GUISettings:
    public class GUISettings {
        private static Vector fields = new Vector();
        private static Vector classes = new Vector();
        /** Creates a new instance of GUISettings */
        public GUISettings() {
        public static void setFields(Vector f)
            fields=f;
        public static int getDisplayedFieldCount()
            return fields.size();
        public static String getColumnName(int columnIndex)
            return (String)fields.elementAt(columnIndex);
        public static Vector getFields()
            return fields;
    }GUISettings.setFields has been called before table is displayed.
    Cheers,
    garsher

  • Table model and default model

    Hi All,
    can u tell me how to use table model or default table model. where i can references about it???
    thanks for all

    [http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#data]

  • Table & Models

    hi all
    i have a list of doubts
    im designing an appln which displays a JTable , the data for the table is got from the database server, im using the Abstracttable model
    i went for abstract table model since in my application the contents of the table very frequently , so i can handle it using the
    firetabledatachanged or some fire functions
    1)my doubt is where and when we have to use the abstracttable model and when we have to go for default table model
    2) Now im keeping a button in my application if i press that ,a new row
    have to be added at the end of that table , how i can carry it on using abstract table model(i think ,In default table model we can do it using
    addrow ( )or insert row())
    thnks in advance
    keon

    Hi,
    You can use DefaultTableModel in place of AbstractTableModel, coz the method fireDataChanged() which you need is present in DefaultTableModel also(inherited from AbstractTableModel , since it is its parent model), apart from that DefaultTableModel gives you convenience methods such as addRow(), insertRow(), removeRow(), which you can override to your convenience.
    However the only constraint is that the DefaultTableModel uses a Vector of Vectors to hold its Model/Data, if you want a different datastructure to be used as underlying model then you should be careful enough to implement all the methods that you are going to call on that instance of DefaultTableModel, this is becuase all the default implementations of the methods of DefaultTableModel assume that the underlying datastructure is a Vector, so if you replace it with a Map or a List then you should provide appropriate implementation to all its methods that manipulate the underlying datastructure

  • Copyig Data from a TABLE MODEL (TABLE) TO A FILE

    Hi guys,
    I wont to copy data from a Default Table Model to a File can someone write a pease of code that will do that for me.
    DefaultTableModel model = new DefaultTableModel();
    JTable table;
    public basic()
              super();
                  model.addColumn("Full Name");
                  model.addColumn("House No");
                  model.addColumn("Address");
                  model.addColumn("Town/County");
                  model.addColumn("Postcode");
                  model.addColumn("Telephone Number");
                  model.addColumn("Email Address");             
                  String[] socrates = { "Example", "33", "York RD", "Poole", "BH18 9RE", "01202776655", "[email protected]" };
                  model.addRow(socrates);
              /**This is the main setup for the Address Book
              *This has the main settings for the size, title
              *And main features of the Address book.
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              this.setSize(new Dimension(800, 600));
              this.setTitle("Large Print Address Book");
              this.setLayout(new FlowLayout ());
              //Main Application Parts
              JLabel welcome = new JLabel("Welcome to Thomas's Address Book v2.0.1");
              welcome.setFont(arial20);
              this.add(welcome);
              //Menu Bar
              JMenuBar mb = new JMenuBar();
              this.setJMenuBar(mb);
              //Table
              table = new JTable(model);
              this.add(table);
              JMenu fm = new JMenu("File");
              fm.setFont(arial20);
              mb.add(fm);
              //Menu Items          
              JMenuItem Add = new JMenuItem("Add Record");
              Add.setFont(arial20);
              Add.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e) 
                        addw a = new addw();                    
              fm.add(Add);
              //Import from a file
              JMenuItem inp = new JMenuItem("Import Records");
              inp.setFont(arial20);
              inp.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e) 
                        //Opens Import Window.
                        inportw i = new inportw();                    
              fm.add(inp);
              JMenuItem quit = new JMenuItem("Exit");
              quit.setFont(arial20);
              fm.add(quit);
              quit.addActionListener(this);
    class inportw extends JFrame
              //*Add Window Properties and Settings
              public inportw ()
                   this.setSize(new Dimension(400, 150));
                   this.setTitle("Inport Records");
                   this.setLayout(new FlowLayout ());
                   this.setVisible(true);
                   //Nmae
                   JLabel error_note = new JLabel("Error Here - Need to make table final!?");
                   error_note.setFont(arial20);
                   this.add(error_note);
                   //Add Button
                   JButton binport = new JButton("Inport");
                   binport.addActionListener(new ActionListener()
                        public void actionPerformed(ActionEvent e) 
                             ArrayList data = new ArrayList();          
                   this.add(binport);
         public void actionPerformed(ActionEvent e)
              System.out.println("Application Exit");
              System.exit(0);
         public static void main(String[] args)
              basic b = new basic();
              The information from the atable needs to go into a .txt file with each row on a new line. It also needs to be in the inport/export window that is in a class on its own when someone clicks export.
    A complete peace of code would be helpfull that would do this for me. Thankyou guys.

    Rite then,
    In answer to both post yes i have done my own homework if thats what you wont to call it.
    And to the second post yes i have put in a File to export to. the code has not be pasted on my origanal post.
    //Export Button - Export Window
                   JButton bexport = new JButton("Export (BUAB)");
                   bexport.addActionListener(new ActionListener()
                        public void actionPerformed(ActionEvent e) 
                             System.out.println("Export Pressed ");
                             try
                                 FileWriter file = new FileWriter("AddressData.txt");
                                BufferedWriter out = new BufferedWriter(file);
                                 out.write("AddressBook data File");
                                out.close();
                             catch (Exception ei)
                             System.err.println("Error: " + ei.getMessage());
                   this.add(bexport);This is the export button,
    I think the code for the table model should be something like this:
    I wont to do something like this
    model.getModel().getValueAt(0, 0);
    Arrylist data = new arrylist();
    try
                                 FileWriter ffile = new FileWriter("AddressData.txt");
                                BufferedWriter out = new BufferedWriter(file);
                                 out.write(data);
                                out.close();
                             catch (Exception ei)
                             System.err.println("Error: " + ei.getMessage());
                                 }          Im not 100% sure how to get the information from the model into the arrylist, though a loop.
    If there is a section of a webpage that may help could someone please post it for me.
    Unfortunatly for me Im visualy impaired and find some of this hard. I learn though looking at examples and creating my own programs that do something similar.
    If no one wonts to help then that fine with me !

  • Problem with Table Model Listener

    I hava a JTable with three columns and dynamic number of rows. The first column has a text. Second column has check box and each third column has three radio buttons. I am using the table model listener to fetch the row and column which the user clicked. here is the code
    public void tableChanged(TableModelEvent e)
    row = e.getFirstRow();
    column = e.getColumn();
    TableModel model = (TableModel)e.getSource();
    String columnName = model.getColumnName(column);
    Object value = model.getValueAt(row, column);
    System.err.println("Value: "<em>value.toString()</em>" Row: "<em>row</em>" Column: "+column);
    attendanceModel.setHolidays(row, value.toString());
    }Here is the problem
    {color:#ff0000}Case 1{color}: When I click the first radio button in first row and third column it works and the output of print statement is
    *{color:#993300}Value:0 Row:0 Column:2{color}*
    {color:#ff0000}Case 2{color}: Next I clicked the first radio button in second row and third column the method is not called nothing is printed
    {color:#ff0000}Case 3{color}: Now I clicked the first radio button in third row and thrid column, the method is called and the output of print statement is
    {color:#993300}*Value:0 Row:1 Column:2*{color} ; but the actual value of row should be 2*. Here it is showing the row and column of the previously selected item.
    But in {color:#ff0000}case 2{color} instead of first radio button if I selected the second radio button the print statement will print the correct value i.e
    {color:#993300}*Value:1 Row:1 Column:2*{color}
    ie If I select different radio button in each row the print statement shows the correct value. But if in each row the same radio button is selected its not working properly. For first row it prints properly. If same radio button is selected in second row the method is not called. But from next row onwards the row value is showing the previously selected row as in {color:#ff0000}case 3{color}.
    But for the checkboxes in column 2 the same is working properly. Each column has only one check box. So when I select the check box in each row the row and column values are getting changed accordingly.
    Could some one help please?
    Thanks,
    Zach.

    To get better help sooner, post a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://mindprod.com/jgloss/sscce.html] that demonstrates the incorrect behaviour.
    db

  • Table model problem

    I have a Jpanel in that there are two Jtables iam using same Table model for both tables.
    when i entered text in one table and clik on second table the first table data showing in second table how to do this one

    vitta wrote:
    I have a Jpanel in that there are two Jtables iam using same Table model for both tables.and
    vitta wrote:
    i dont want to get the first table values reflected in the second tableIn all honesty how is the answer to this question not exceedingly obvious?

Maybe you are looking for

  • IPad not recognized by iTunes, recognized by Windows as a camera

    I first started using my iPad yesterday. Yesterday I was up until 2:30 in the morning trying to find a solution, to no avail. I had apple support call me today, but I missed their calls and now I have to wait again until they call me. But in the mean

  • Ipod for windows

    Dear Sir, Please help to solve my problem, I have Ipod Classic 120 GB that I already install with new version of Itune software with apple computer, but I want to edit all the data with my windows computer. Please let me know what should I do. Thanks

  • Adapter Framework Problem

    Hi all, I currently have a problem with the adapter framework (AF) of the exchange infrastructure. After having configured a scenario including an inbound and an outbound SOAP adapter I'm not able to send SOAP messages to XI via the AF. The AF seems

  • Three Errors when Installing PS6: DF024, DW063, & DW050

    First I don't understand why I am getting any errors at all.  I have an enormous Mac Pro with a 32gb of ram and lots of hdd space, a good GPU, etc.  My hardware can't be in the way of the fonts and things it seems to be having trouble downloading, or

  • Macbook Air intermittent freezing problem

    My MBA would freeze up and then unfreeze and then freeze again, at an interval of about 10 to 15 seconds. This happens when I watch video on iTune, QuickTime or even those flash based videos such as YouTube. CPU monitor shows one core shutting down i