Results 1 to 2 of 2
  1. #1
    byubi is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    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 dateMax, Date dateMin, String shift)
    	{
    		super();
    		this.dateMax = dateMax;
    		this.dateMin = dateMin;
    		this.shift = shift;
    
    		data = FichePresence.getFiles(dateMin, dateMax, shift);
    	}
    
    	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(0, c).getClass();
    		}
    	}
    
    	public Object getValueAt(int rowIndex, int 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 row, int 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
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

Similar Threads

  1. Updating the existing JTable !
    By Stephen Douglas in forum New To Java
    Replies: 2
    Last Post: 04-07-2010, 08:38 PM
  2. Problem with updating JTable
    By kwaspl in forum New To Java
    Replies: 2
    Last Post: 12-20-2009, 10:41 PM
  3. Write empty Jtable columns to disk
    By ocean in forum New To Java
    Replies: 9
    Last Post: 12-03-2009, 03:02 PM
  4. Replies: 0
    Last Post: 08-29-2008, 12:49 PM
  5. Updating database table from JTable
    By yesjava in forum New To Java
    Replies: 1
    Last Post: 08-16-2008, 10:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •