Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Exception while displaying text file data to JTable

$
0
0
Hi
I have written a code to display the contents of a text file to a JTable. The file content is being displayed to the JTable but there are large number of extra rows also being displayed and when I scroll through table or click on the extra rows of table some exception takes place.

this is my code:
 public class InsertFileDataToJTable extends AbstractTableModel 
{

	
	/**
	 * 
	 */
int getcount=0;
	private static final long serialVersionUID = 1L;
	Vector data= new Vector();
	Vector columns= new Vector();
	String[] s;
	String str;
	
	 private Object[] columnNames= {"Attribute"," #", "Position", "Transformation","Assignment","Field","Constant"};
    @SuppressWarnings("unchecked")

   
    public InsertFileDataToJTable() {
            String line;
            
            
            
            try {
                  FileInputStream fis = new FileInputStream("sample.config");
                    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                    StringTokenizer st1 = new StringTokenizer(br.readLine(), " ");
                    while (st1.hasMoreTokens())
                           columns.addElement(st1.nextToken());
                    while ((line = br.readLine()) != null) {
                            StringTokenizer st2 = new StringTokenizer(line, " ");
                            while (st2.hasMoreTokens())
                                    data.addElement(st2.nextToken());
                    }
                    br.close();
                   
                   
           
            
            } catch (Exception e) {
                    e.printStackTrace();
            }
    }

    public int getRowCount() {
    	 
       //  System.out.println("size of data"+ data.size());
			
    	return data.size();//getColumnCount();
    }

    public int getColumnCount() {
    //	System.out.println("no. of columns"+ columns.size());
    	return columns.size();
    }

    public Object getValueAt(int rowIndex, int columnIndex) 
    {
    	
    	
    	return (String) data.elementAt((rowIndex * getColumnCount())
        + columnIndex);

        
    }
    public String getColumnName(int column) {
        return (String) columnNames[column];
    }
    public void addRow(String value)
    {
        fireTableRowsInserted(data.size() - 1, data.size() - 1);
        int row = data.size() -1 ;
        int col = 1;
        setValueAt(value, row, col);            
    }

    public void removeRow(int row)
    {           
    	 data.remove(row);
        fireTableRowsDeleted(row, row);
        
    }
    public boolean isCellEditable(int row, int col) 
    { 
        return true; 
   }

}


this is the exception
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 180 >= 180
	at java.util.Vector.elementAt(Unknown Source)
	at com.ibm.is.cc.gui.InsertFileDataToJTable.getValueAt(InsertFileDataToJTable.java:74)
	at javax.swing.JTable.getValueAt(Unknown Source)
	at javax.swing.JTable.prepareRenderer(Unknown Source)
	at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
	at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
	at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
	at javax.swing.plaf.ComponentUI.update(Unknown Source)
	at javax.swing.JComponent.paintComponent(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
	at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
	at javax.swing.RepaintManager.paint(Unknown Source)
	at javax.swing.JComponent.paintForceDoubleBuffered(Unknown Source)
	at javax.swing.JViewport.blitDoubleBuffered(Unknown Source)
	at javax.swing.JViewport.windowBlitPaint(Unknown Source)
	at javax.swing.JViewport.setViewPosition(Unknown Source)
	at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.vsbStateChanged(Unknown Source)
	at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(Unknown Source)
	at javax.swing.DefaultBoundedRangeModel.fireStateChanged(Unknown Source)
	at javax.swing.DefaultBoundedRangeModel.setRangeProperties(Unknown Source)
	at javax.swing.DefaultBoundedRangeModel.setValue(Unknown Source)
	at javax.swing.JScrollBar.setValue(Unknown Source)
	at javax.swing.plaf.basic.BasicScrollBarUI$TrackListener.setValueFrom(Unknown Source)
	at javax.swing.plaf.basic.BasicScrollBarUI$TrackListener.mouseDragged(Unknown Source)
	at java.awt.Component.processMouseMotionEvent(Unknown Source)
	at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$2.run(Unknown Source)
	at java.awt.EventQueue$2.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)


please help

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>