Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Problem with updating empty JTable

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with updating empty JTable

    hi

    i'm using this class as a model for my JTable:
    PHP Code:
    import java.awt.Dimension
    import java.sql.Date
    import java.util.ArrayList

    import javax.swing.JFrame
    import javax.swing.JTable
    import javax.swing.table.AbstractTableModel

    import GUI.Statiques

    public class 
    TabPresenceModelFiltre extends AbstractTableModel 

        
    Date                        dateMax
        
    Date                        dateMin
        
    String                        shift
        private 
    ArrayList<FichePresence>    data
        private 
    String[]    names = { "Date""Shift""Op présent""Op absent""Op arrêté" }; 

        public 
    TabPresenceModelFiltre(Date dateMaxDate dateMinString shift
        { 
            
    super(); 
            
    this.dateMax dateMax
            
    this.dateMin dateMin
            
    this.shift shift

            
    data FichePresence.getFiles(dateMindateMaxshift); 
        } 

        public 
    String getColumnName(int col
        { 
            return 
    names[col]; 
        } 

        public 
    int getRowCount() 
        { 
            return 
    data.size(); 
        } 

        public 
    int getColumnCount() 
        { 
            return 
    names.length
        } 

        public Class 
    getColumnClass(int c
        { 
            try 
            { 
                switch (
    c
                { 
                case 
    0
                    return Class.
    forName("Date"); 
                case 
    1
                    return Class.
    forName("String"); 
                case 
    2
                    return Class.
    forName("Integer"); 
                case 
    3
                    return Class.
    forName("Integer"); 
                case 
    4
                    return Class.
    forName("Integer"); 
                default: 
                    return 
    null// Ne devrait jamais arriver 
                

            } catch (
    ClassNotFoundException e
            { 
                return 
    getValueAt(0c).getClass(); 
            } 
        } 

        public 
    Object getValueAt(int rowIndexint columnIndex
        { 
            switch (
    columnIndex
            { 
            case 
    0
                return 
    data.get(rowIndex).getDate(); 
            case 
    1
                return 
    data.get(rowIndex).getposte(); 
            case 
    2
                return 
    data.get(rowIndex).getNbrPresent(); 
            case 
    3
                return 
    data.get(rowIndex).getNbrAbsent(); 
            case 
    4
                return 
    data.get(rowIndex).getNbrArrete(); 
            default: 
                return 
    null// Ne devrait jamais arriver 
            

        } 

        public 
    boolean isCellEditable(int rowint col
        { 
            return 
    false
        } 

    i use setModel to update my JTable... but it only works if the table is not empty.
    in other words i can update the table it's not empty, but i get IndexOutOfBoundsException if my table is empty.

    thank you


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Problem with updating empty JTable

    Cross posted
    Problem with updating empty JTable - Java Forums

    db

Similar Threads

  1. How to show empty directories in JTree ?
    By ni4ni in forum AWT / Java Swing
    Replies: 1
    Last Post: April 30th, 2010, 01:55 AM
  2. [SOLVED] Supressing empty lines and does not do until the end! Why ?
    By lumpy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 18th, 2010, 07:38 AM
  3. updating database
    By gurpreetm13 in forum JDBC & Databases
    Replies: 3
    Last Post: October 9th, 2009, 12:43 PM
  4. application Task problem - updating JTree
    By idandush in forum AWT / Java Swing
    Replies: 2
    Last Post: June 18th, 2009, 04:15 AM
  5. Problem of getting result than SQL to JTable
    By MS_Dark in forum Exceptions
    Replies: 1
    Last Post: March 10th, 2009, 07:26 AM