JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

43 Replies - 3746 Views - Last Post: 14 May 2012 - 12:30 PM Rate Topic: -----

#1 Examiner12  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 89
  • Joined: 02-February 12

JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 04 May 2012 - 09:26 AM

I've got a major problem. I've put in weeks of work on my first real java application which pulls a .csv file into a JTable. I've been using small sample data sets to be able to test code quickly. Yesterday I attempted to run the app using the full data set, a .csv containing 342697 rows and 53 columns of data, and encountered heap space Out of Memory. The table uses DefaultTableModel model; built from Object[][] data and String[] colNames. What I'm attempting to do to resolve is to Scan in chunks of 100000 records into a Object[][] data 1, add that set to table model, then do
data1 = null;


in an attempt to get the garbage collector to clear it out of memory. I'm still receiving the heap space Memory error. I've increased the memory allocation in my .ini file as well. I'm at my wits end here because if I can't pull this off, all my work has been for nill. Below is the snippet of code as I've tried to implement to use garbage collection to resolve. I know this isn't an SSCCE, but can anyone weigh in on why the garbage collector isn't clearing the unneeded objects from memory? Possible solutions? I'd really appreciate any help I can get!


//Get the JTable and return it    
    JTable getTable() throws IOException    { 
    	
    	File f = new File("C:\\PCQ\\A_R.csv");
    	Scanner s = new Scanner(f);
    	
    	String[] colNames = { 
    			/*
    			"PRINT", "ECN", "CUSTOMER", "MODEL", "SERIAL", "NOMENCLATURE", "MFR_CD",
    			"SUB_CUSTODIAN", "SCHED_LAB", "ON_SITE_SERVICE", "CAL_STD",
    			"SERVICE_LABEL_CD", "PHASE_ID", "METRL_CYCLE", "WORKLOAD_NORM_HRS", 
    			"CLASS_STD" 
    			*/				
    			"PRINT", 
    			"SERVICED_LAB", 
    			"CUSTOMER_ID", 
    			"MODEL_NO", 
    			"SERIAL_NO", 
    			"ECN", 
    			"NOMENCLATURE", 
    			"SUB_CUSTODIAN", 
    			"METRL_CYCLE", 
    			"MFR_CD", 
    			"UIC", 
    			"SCHED_LAB", 
    			"PROCEDURE_USED", 
    			"VALUE_FIXED", 
    			"NSN", 
    			"PART_OF", 
    			"ON_SITE_SERVICE", 
    			"CAL_STD", 
    			"SERVICE_LABEL_CD", 
    			"PLANT_ACCT", 
    			"SCAT_CD", 
    			"PHASE_ID", 
    			"APPROVED_PROCEDURE", 
    			"INV_SHOP_NO", 
    			"CLASS_STD", 
    			"TYPE_STD", 
    			"WIP_STATUS", 
    			"EQPMT_TYPE_CD", 
    			"ICN", 
    			"PRINT_METERCARD_FLG", 
    			"EQPMT_STATUS_CD", 
    			"DELAY_REASON_CD", 
    			"EQPMT_STATUS_CD", 
    			"SPCL_INSTR_CD", 
    			"WORKLOAD_NORM_HRS", 
    			"METRL_CYCLE", 
    			"DTC_SYS", 
    			"DTC_RCVD", 
    			"DTC_INDUCT", 
    			"DTC_DELAY", 
    			"DTC_REPTD", 
    			"DTC_LSTCAL", 
    			"DTC_NXT_DUE", 
    			"DTC_RECALL", 
    			"DT_CMPL", 
    			"DT_CREATE", 
    			"COST", 
    			"CAT_CUS", 
    			"CAT_LAB", 
    			"LAB_TYPE", 
    			"ACC_CODE", 
    			"FLAG_OFFLN", 
    			"DTC_REIND"
    	
    	};  
    	 int cols = colNames.length;    

//Import CSV File into 2d array   	  
	List<Object[]> list = new ArrayList<Object[]>();  
		int c = 0;
		while (/*s.hasNextLine() */c < 100000 ) {         
			Object[] line = s.nextLine().split(","); 
			/*
			for(int z = 0; z < 50; z++){				
				list.add(new Object[] { 
						(Boolean.FALSE),				
						(line[z])				
			});
				c++;
			}
			*/
			
			list.add(new Object[] { 

					(Boolean.FALSE),	//PRINT
					(line[0]),  //'LAB_SVC',
					(line[1]),  //'CUSTOMER',
					(line[2]),  //'MODEL',
					(line[3]),  //'SERIAL',
					(line[4]),  //'ECN',
					(line[5]),  //'NOMEN',
					(line[6]),  //'SUB_CUST',
					(line[7]),  //'METRL_C',
					(line[8]),  //'FSCM',
					(line[9]),  //'UIC',
					(line[10]),  //'LAB_SCHED',
					(line[11]),  //'PROC_USED',
					(line[12]),  //'VALUE_FIXD',
					(line[13]),  //'NSN',
					(line[14]),  //'PART_OF',
					(line[15]),  //'ON_SITE',
					(line[16]),  //'STD_CAL',
					(line[17]),  //'LABEL_SVC',
					(line[18]),  //'PLANT_ACCT',
					(line[19]),  //'SUB_CAT',
					(line[20]),  //'PHASE',
					(line[21]),  //'PROC_APPR',
					(line[22]),  //'SHOP_INV',
					(line[23]),  //'STD_CLASS',
					(line[24]),  //'STD_TYPE',
					(line[25]),  //'STATUS',
					(line[26]),  //'TYPE_EQUIP',
					(line[27]),  //'ICN',
					(line[28]),  //'FLAG_MC',
					(line[29]),  //'EQUIP_STAT',
					(line[30]),  //'DELAY_CD',
					(line[31]),  //'COND_EQUIP',
					(line[32]),  //'INST_SPCL',
					(line[33]),  //'HRS_STD',
					(line[34]),  //'METRL_N',
					(line[35]),  //'DT_SYS',
					(line[36]),  //'DT_RCVD',
					(line[37]),  //'DT_INDUCT',
					(line[38]),  //'DT_DELAY',
					(line[39]),  //'DT_REPTD',
					(line[40]),  //'DT_LSTCAL',
					(line[41]),  //'DT_NXTDUE',
					(line[42]),  //'DT_RECALL',
					(line[43]),  //'DT_CMPL',
					(line[44]),  //'DT_CREATE',
					(line[45]),  //'COST',
					(line[46]),  //'CAT_CUS',
					(line[47]),  //'CAT_LAB',
					(line[48]),  //'LAB_TYPE',
					(line[49]),  //'ACC_CODE',
					(line[50])//,  //'FLAG_OFFLN',
					//(line[51])  //'DTC_REIND',

								}
			); 
			c++;
			}         
		
		int rows = list.size();
		int numberOfColumns = 15; 
		
    	Object[][] data = new Object[rows][cols];    
		for (int i = 0; i < rows; i++) {        
			data[i] = list.get(i);     
		}
		
//Create model for JTable 		
    	model = new DefaultTableModel(data, colNames) {   		
    		public boolean isCellEditable(int rowIndex, int mColIndex) {
    			if(mColIndex > 0){
    			return false;
    			} 
    			else return true;
    		}
    	public Class getColumnClass(int col) {
    	Object o = getValueAt(0, col);     
    	if(o == null){                 
    		return Object.class;   
    		}
    	else     {         
    		return o.getClass();   
    			}
    		}  	
    	};
    	
    	data = null;
    	list = null;
		
		List<Object[]> list2 = new ArrayList<Object[]>();  
		int c2 = 99999;
		while (/*s.hasNextLine() */c2 > 99998 && c2 < 200000 ) {         
			Object[] line2 = s.nextLine().split(","); 		
			list2.add(new Object[] {

					(Boolean.FALSE),	//PRINT
					(line2[0]),  //'LAB_SVC',
					(line2[1]),  //'CUSTOMER',
					(line2[2]),  //'MODEL',
					(line2[3]),  //'SERIAL',
					(line2[4]),  //'ECN',
					(line2[5]),  //'NOMEN',
					(line2[6]),  //'SUB_CUST',
					(line2[7]),  //'METRL_C',
					(line2[8]),  //'FSCM',
					(line2[9]),  //'UIC',
					(line2[10]),  //'LAB_SCHED',
					(line2[11]),  //'PROC_USED',
					(line2[12]),  //'VALUE_FIXD',
					(line2[13]),  //'NSN',
					(line2[14]),  //'PART_OF',
					(line2[15]),  //'ON_SITE',
					(line2[16]),  //'STD_CAL',
					(line2[17]),  //'LABEL_SVC',
					(line2[18]),  //'PLANT_ACCT',
					(line2[19]),  //'SUB_CAT',
					(line2[20]),  //'PHASE',
					(line2[21]),  //'PROC_APPR',
					(line2[22]),  //'SHOP_INV',
					(line2[23]),  //'STD_CLASS',
					(line2[24]),  //'STD_TYPE',
					(line2[25]),  //'STATUS',
					(line2[26]),  //'TYPE_EQUIP',
					(line2[27]),  //'ICN',
					(line2[28]),  //'FLAG_MC',
					(line2[29]),  //'EQUIP_STAT',
					(line2[30]),  //'DELAY_CD',
					(line2[31]),  //'COND_EQUIP',
					(line2[32]),  //'INST_SPCL',
					(line2[33]),  //'HRS_STD',
					(line2[34]),  //'METRL_N',
					(line2[35]),  //'DT_SYS',
					(line2[36]),  //'DT_RCVD',
					(line2[37]),  //'DT_INDUCT',
					(line2[38]),  //'DT_DELAY',
					(line2[39]),  //'DT_REPTD',
					(line2[40]),  //'DT_LSTCAL',
					(line2[41]),  //'DT_NXTDUE',
					(line2[42]),  //'DT_RECALL',
					(line2[43]),  //'DT_CMPL',
					(line2[44]),  //'DT_CREATE',
					(line2[45]),  //'COST',
					(line2[46]),  //'CAT_CUS',
					(line2[47]),  //'CAT_LAB',
					(line2[48]),  //'LAB_TYPE',
					(line2[49]),  //'ACC_CODE',
					(line2[50])//,  //'FLAG_OFFLN',
					//(line2[51])  //'DTC_REIND',
								}
			); 
			c2++;
			}         
		int rows2 = list2.size();
    	Object[][] data2 = new Object[rows2][cols];    
		for (int i = 0; i < rows2; i++) {        
			data2[i] = list2.get(i);     
		}
		
    	for(int z = 0; z < rows2; z++){
    		model.insertRow(z, data2[z]);
    	}
    	data2 = null;
    	list2 = null;




Is This A Good Question/Topic? 0
  • +

Replies To: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 04 May 2012 - 10:22 AM

Quote

I've got a major problem


Just like the ones I like. Especially if related to JTable :)

You are creating a lot but a lot of Objects for nothing

        Object[][] data = new Object[rows][cols];    
        for (int i = 0; i < rows; i++) {        
            data[i] = list.get(i);     
        }


Why duplicating your data here ?
Write your own TableModel by extending AbstractTableModel

http://www.dreaminco...h-a-tablemodel/

Just pass the ArrayList to your TableModel

getRowCount() will return list.getSize()
getValueAt(int row, int col) will return list.get(row)[col]

also why creating nbColumn objects for every row ?
Just put the full line as String in the ArrayList
in the getValueAt() method:
- extract the line from the ArrayList
- split(",") it and return split[col] whit a check for the boolean if the col == 0

Right now you have 100000 String object (one for each line)
you have 100000 * 53 String objects in your ArrayList
100000 * 53 objects in your data array

You only need the 100000 original ones

Something like this... not tested
	//Get the JTable and return it    
	JTable getTable() throws IOException    { 

		File f = new File("C:\\PCQ\\A_R.csv");
		Scanner s = new Scanner(f);

		String[] colNames = { 
				"PRINT", 
				"SERVICED_LAB", 
				"CUSTOMER_ID", 
				"MODEL_NO", 
				"SERIAL_NO", 
				"ECN", 
				"NOMENCLATURE", 
				"SUB_CUSTODIAN", 
				"METRL_CYCLE", 
				"MFR_CD", 
				"UIC", 
				"SCHED_LAB", 
				"PROCEDURE_USED", 
				"VALUE_FIXED", 
				"NSN", 
				"PART_OF", 
				"ON_SITE_SERVICE", 
				"CAL_STD", 
				"SERVICE_LABEL_CD", 
				"PLANT_ACCT", 
				"SCAT_CD", 
				"PHASE_ID", 
				"APPROVED_PROCEDURE", 
				"INV_SHOP_NO", 
				"CLASS_STD", 
				"TYPE_STD", 
				"WIP_STATUS", 
				"EQPMT_TYPE_CD", 
				"ICN", 
				"PRINT_METERCARD_FLG", 
				"EQPMT_STATUS_CD", 
				"DELAY_REASON_CD", 
				"EQPMT_STATUS_CD", 
				"SPCL_INSTR_CD", 
				"WORKLOAD_NORM_HRS", 
				"METRL_CYCLE", 
				"DTC_SYS", 
				"DTC_RCVD", 
				"DTC_INDUCT", 
				"DTC_DELAY", 
				"DTC_REPTD", 
				"DTC_LSTCAL", 
				"DTC_NXT_DUE", 
				"DTC_RECALL", 
				"DT_CMPL", 
				"DT_CREATE", 
				"COST", 
				"CAT_CUS", 
				"CAT_LAB", 
				"LAB_TYPE", 
				"ACC_CODE", 
				"FLAG_OFFLN", 
				"DTC_REIND"

		};  

		//Import CSV File into 2d array   	  
		ArrayList<String> al = new ArrayList<String>(100000);
		int c = 0;
		while (c < 100000 ) {         
			al.add(s.nextLine()); 
			c++;
		}     

		MyModel model = new MyModel(colNames, al);
		return new JTable(model);
	}

	
	// my tableModel as an inner class
	class MyModel extends AbstractTableModel {
		String[] colName;
		ArrayList<String> al;
		ArrayList<Boolean> first;

		MyModel(String[] colName, ArrayList<String> al) {
			this.colName = colName;
			this.al = al;
			first = new ArrayList<Boolean>(al.size());
			for(int i = 0; i < al.size(); ++i)
				first.add(Boolean.valueOf(false));
		}

		@Override
		public int getColumnCount() {
			// TODO Auto-generated method stub
			return colName.length;
		}
		public String getColumnName(int col) {
			return colName[col];
		}

		@Override
		public int getRowCount() {
			return al.size();
		}

		@Override
		public Object getValueAt(int row, int col) {
			if(col == 0)
				return first.get(row);
			String line = al.get(row);
			String[] token = line.split(",");
			return token[col-1];
		}

		public void setValueAt(Object o, int row, int col) {
			// first col is the boolean
			if(col == 0) {
				first.set(row, (Boolean) o);
				return;
			}
			// other col
			String line = al.get(row);
			String[] token = line.split(",");
			token[row-1] = (String) o;         // replace with new one
			// rebuid the String
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < token.length - 1; ++i)
				sb.append(token[i]).append(',');   // with the coma
			sb.append(token[token.length-1]);     // but for the last one
			al.set(row, sb.toString());           // replace in ArrayList
		}
	}
}



Happy coding

If this is not enough, come back and we will study other alternatives :)

This post has been edited by pbl: 04 May 2012 - 10:24 AM

Was This Post Helpful? 2
  • +
  • -

#3 Examiner12  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 89
  • Joined: 02-February 12

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 04 May 2012 - 12:01 PM

This appears to be a far more efficient approach pbl! My only issues I've run into is how to implement and keep the existing characteristics of my code like transparent cells, and my custom row filter that works with text boxes in the gui class. Any ideas on how to keep these capabilities using your refined inner class approach? As you've seen, I've struggled for weeks to attain these capabilities and don't know if I'm good enough yet to revise the whole thing :( Heres the whole SearchTest class pre-changes:

//SEARCH TEST BACKUP - WITH HEAP SPACE ISSUE
package PCQ;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;



 
public class SearchTest implements ListSelectionListener, TableModelListener
{
//Main Table Object	
    JTable table;
    DefaultTableModel model;
    
    int selRows;
    int row;
    int row2;
	 RowFilter<TableModel, Object> svclabf = null;
	 RowFilter<TableModel, Object> custf = null;
	 RowFilter<TableModel, Object> modf = null;
	 RowFilter<TableModel, Object> serialf = null;
	 RowFilter<TableModel, Object> ecnf = null;
	 RowFilter<TableModel, Object> subcustf = null;
    
private TableRowSorter<TableModel> sorter ;  
    
//Search Field - Basic (Test)
    JTextField textField;
    
//Test Sorter Field
    
    JTextField svclabt;
    JTextField custt;
    JTextField modt;
    JTextField serialt;
    JTextField ecnt;
    JTextField subcustt;
    
    TransparentButton mcb = new TransparentButton("Get Meter Card(s)"); 
    TransparentButton metcb = new TransparentButton("Get MetCal Form(s)");

    
    
//Search Function - Complete
    
    JButton bs;
    JCheckBox cECN; 
    JCheckBox cCust;
    JCheckBox cMod;
    JCheckBox cSer;
    JCheckBox cNom;
    JCheckBox cSubCust;
    JTextField tECN;
    JTextField tCust;
    JTextField tMod;
    JTextField tSer;
    JTextField tNom;
    JTextField tSubCust;
    
//Text Fields for Detail Tab: Key Fields   
    JTextField dtECN;
    JTextField dtCust;
    JTextField dtMod;
    JTextField dtSer;
    JTextField dtNom;

//Text Fields for Detail Tab: Auxiliary Fields
    
    JTextField dtMFR;
    JTextField dtPARTOF;
    JTextField dtSUBCUST;
    JTextField dtSCHEDLAB;
    JTextField dtSCAT;
    JTextField dtNSN;
    JTextField dtPLANTACCT;
    JTextField dtAPPRPROC;
    JTextField dtSVCLAB;
    JTextField dtMETCYCLE;
    JTextField dtPHASE;
    JTextField dtDTCOMPL;
    JTextField dtDTLASTSER;
    JTextField dtSERVLBL;
    JTextField dtDTNEXTDUE;
    JTextField dtSTATUS;
    JTextField dtONSITE;
    JTextField dtSHOP;
    JTextField dtWLNHRS;
    JTextField dtCLASSSTD;
    JTextField dtCALSTD;
    
    

 
    public SearchTest() throws IOException 
    {
    	
    	
        table = getTable();
        table.setOpaque(false);
        
     //Search Function - Complete
        //Color bg = new Color(210, 222, 242);
        Color bg = new Color(224, 242, 252);
        bs = new JButton("  Search  ");
        mcb.setToolTipText("Get Meter Card(s) for Current PRINT Checkbox Selection");
        metcb.setToolTipText("Get MetCal Form(s) for Current PRINT Selection");
        svclabt = new JTextField(10); svclabt.setBackground(bg); svclabt.setToolTipText("Filter by Servicing Lab");
        custt = new JTextField(10); custt.setBackground(bg); custt.setToolTipText("Filter by Customer Code");
        modt= new JTextField(10); modt.setBackground(bg); modt.setToolTipText("Filter by Model Number");
        serialt = new JTextField(10); serialt.setBackground(bg); serialt.setToolTipText("Filter by Serial Number");
        ecnt = new JTextField(10); ecnt.setBackground(bg); ecnt.setToolTipText("Filter by Equipment Control Number");
        subcustt = new JTextField(10); subcustt.setBackground(bg); subcustt.setToolTipText("Filter by Sub Custodian");
        
        cECN = new JCheckBox("ECN:");
        cCust = new JCheckBox("CUSTOMER:");
        cMod = new JCheckBox("MODEL:");
        cSer = new JCheckBox("SERIAL:");
        cNom = new JCheckBox("NOMENCLATURE:");
        cSubCust = new JCheckBox("SUB CUSTODIAN:");
        tECN = new JTextField(10);
        tCust = new JTextField(10);
        tMod = new JTextField(10);
        tSer = new JTextField(10);
        tNom = new JTextField(10);
        tSubCust = new JTextField(10);
        
        
        textField = new JTextField();
        textField.setBackground(bg); 
        
//Detail Tab - Key Field Text Boxes   
                
        dtECN = new JTextField(15);	dtECN.setEditable(false);	dtECN.setBackground(bg); 
        dtCust = new JTextField(15);	dtCust.setEditable(false);	dtCust.setBackground(bg);
        dtMod = new JTextField(15);	dtMod.setEditable(false);	dtMod.setBackground(bg);
        dtSer = new JTextField(15);	dtSer.setEditable(false);	dtSer.setBackground(bg);
        dtNom = new JTextField(15);	dtNom.setEditable(false);	dtNom.setBackground(bg);

        
//Detail Tab - Auxiliary Field Text Boxes  
        dtMFR = new JTextField(15);    dtMFR.setEditable(false);    dtMFR.setBackground(bg);
        dtPARTOF = new JTextField(15);    dtPARTOF.setEditable(false);    dtPARTOF.setBackground(bg);
        dtSUBCUST = new JTextField(15);    dtSUBCUST.setEditable(false);    dtSUBCUST.setBackground(bg);
        dtSCHEDLAB = new JTextField(15);    dtSCHEDLAB.setEditable(false);    dtSCHEDLAB.setBackground(bg);
        dtSCAT = new JTextField(15);    dtSCAT.setEditable(false);    dtSCAT.setBackground(bg);
        dtNSN = new JTextField(15);    dtNSN.setEditable(false);    dtNSN.setBackground(bg);
        dtPLANTACCT = new JTextField(15);    dtPLANTACCT.setEditable(false);    dtPLANTACCT.setBackground(bg);
        dtAPPRPROC = new JTextField(15);    dtAPPRPROC.setEditable(false);    dtAPPRPROC.setBackground(bg);
        dtSVCLAB = new JTextField(15);    dtSVCLAB.setEditable(false);    dtSVCLAB.setBackground(bg);
        dtMETCYCLE = new JTextField(15);    dtMETCYCLE.setEditable(false);    dtMETCYCLE.setBackground(bg);
        dtPHASE = new JTextField(15);    dtPHASE.setEditable(false);    dtPHASE.setBackground(bg);
        dtDTCOMPL = new JTextField(15);    dtDTCOMPL.setEditable(false);    dtDTCOMPL.setBackground(bg);
        dtDTLASTSER = new JTextField(15);    dtDTLASTSER.setEditable(false);    dtDTLASTSER.setBackground(bg);
        dtSERVLBL = new JTextField(15);    dtSERVLBL.setEditable(false);    dtSERVLBL.setBackground(bg);
        dtDTNEXTDUE = new JTextField(15);    dtDTNEXTDUE.setEditable(false);    dtDTNEXTDUE.setBackground(bg);
        dtSTATUS = new JTextField(15);    dtSTATUS.setEditable(false);    dtSTATUS.setBackground(bg);
        dtONSITE = new JTextField(15);    dtONSITE.setEditable(false);    dtONSITE.setBackground(bg);
        dtSHOP = new JTextField(15);    dtSHOP.setEditable(false);    dtSHOP.setBackground(bg);
        dtWLNHRS = new JTextField(15);    dtWLNHRS.setEditable(false);    dtWLNHRS.setBackground(bg);
        dtCLASSSTD = new JTextField(15);    dtCLASSSTD.setEditable(false);    dtCLASSSTD.setBackground(bg);
        dtCALSTD = new JTextField(15);    dtCALSTD.setEditable(false);    dtCALSTD.setBackground(bg);
        

        textField.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                search();
            }
        });
        
        bs.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
            	table.repaint();
            	search2();
            }
        });
        
        svclabt.getDocument().addDocumentListener
        (  
        		   new DocumentListener()  
        		   {
        			           			   
        		      public void changedUpdate(DocumentEvent e)  
        		      {   	       		    	 
        		    	  newFilter();  
        		      }  
        		      public void insertUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void removeUpdate(DocumentEvent e)  
        		      {  
        		         newFilter();  
        		      }  
        		   }  
        		);  
        custt.getDocument().addDocumentListener
        (  
        		   new DocumentListener()  
        		   {  
        		      public void changedUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void insertUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void removeUpdate(DocumentEvent e)  
        		      {  
        		         newFilter();  
        		      }  
        		   }  
        		); 
        modt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        serialt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        ecnt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        subcustt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		);     
    mcb.addActionListener(new ActionListener()
        {
        public void actionPerformed(ActionEvent e)
        {
                 returnReportData();
               }
        });
     
    metcb.addActionListener(new ActionListener()
        {
        public void actionPerformed(ActionEvent e)
        {
                 returnReportData();
               }
        });
        
        
        
    }
 
//Get the JTable and return it    
    JTable getTable() throws IOException    { 
    	
    	File f = new File("C:\\PCQ\\A_R.csv");
    	Scanner s = new Scanner(f);
    	
    	String[] colNames = { 
    			/*
    			"PRINT", "ECN", "CUSTOMER", "MODEL", "SERIAL", "NOMENCLATURE", "MFR_CD",
    			"SUB_CUSTODIAN", "SCHED_LAB", "ON_SITE_SERVICE", "CAL_STD",
    			"SERVICE_LABEL_CD", "PHASE_ID", "METRL_CYCLE", "WORKLOAD_NORM_HRS", 
    			"CLASS_STD" 
    			*/				
    			"PRINT", 
    			"SERVICED_LAB", 
    			"CUSTOMER_ID", 
    			"MODEL_NO", 
    			"SERIAL_NO", 
    			"ECN", 
    			"NOMENCLATURE", 
    			"SUB_CUSTODIAN", 
    			"METRL_CYCLE", 
    			"MFR_CD", 
    			"UIC", 
    			"SCHED_LAB", 
    			"PROCEDURE_USED", 
    			"VALUE_FIXED", 
    			"NSN", 
    			"PART_OF", 
    			"ON_SITE_SERVICE", 
    			"CAL_STD", 
    			"SERVICE_LABEL_CD", 
    			"PLANT_ACCT", 
    			"SCAT_CD", 
    			"PHASE_ID", 
    			"APPROVED_PROCEDURE", 
    			"INV_SHOP_NO", 
    			"CLASS_STD", 
    			"TYPE_STD", 
    			"WIP_STATUS", 
    			"EQPMT_TYPE_CD", 
    			"ICN", 
    			"PRINT_METERCARD_FLG", 
    			"EQPMT_STATUS_CD", 
    			"DELAY_REASON_CD", 
    			"EQPMT_STATUS_CD", 
    			"SPCL_INSTR_CD", 
    			"WORKLOAD_NORM_HRS", 
    			"METRL_CYCLE", 
    			"DTC_SYS", 
    			"DTC_RCVD", 
    			"DTC_INDUCT", 
    			"DTC_DELAY", 
    			"DTC_REPTD", 
    			"DTC_LSTCAL", 
    			"DTC_NXT_DUE", 
    			"DTC_RECALL", 
    			"DT_CMPL", 
    			"DT_CREATE", 
    			"COST", 
    			"CAT_CUS", 
    			"CAT_LAB", 
    			"LAB_TYPE", 
    			"ACC_CODE", 
    			"FLAG_OFFLN", 
    			"DTC_REIND"
    	
    	};  
    	 int cols = colNames.length;    

//Import CSV File into 2d array   	  
	List<Object[]> list = new ArrayList<Object[]>();  
		int c = 0;
		while (/*s.hasNextLine() */c < 100000 ) {         
			Object[] line = s.nextLine().split(","); 
			/*
			for(int z = 0; z < 50; z++){				
				list.add(new Object[] { 
						(Boolean.FALSE),				
						(line[z])				
			});
				c++;
			}
			*/
			
			list.add(new Object[] { 

					(Boolean.FALSE),	//PRINT
					(line[0]),  //'LAB_SVC',
					(line[1]),  //'CUSTOMER',
					(line[2]),  //'MODEL',
					(line[3]),  //'SERIAL',
					(line[4]),  //'ECN',
					(line[5]),  //'NOMEN',
					(line[6]),  //'SUB_CUST',
					(line[7]),  //'METRL_C',
					(line[8]),  //'FSCM',
					(line[9]),  //'UIC',
					(line[10]),  //'LAB_SCHED',
					(line[11]),  //'PROC_USED',
					(line[12]),  //'VALUE_FIXD',
					(line[13]),  //'NSN',
					(line[14]),  //'PART_OF',
					(line[15]),  //'ON_SITE',
					(line[16]),  //'STD_CAL',
					(line[17]),  //'LABEL_SVC',
					(line[18]),  //'PLANT_ACCT',
					(line[19]),  //'SUB_CAT',
					(line[20]),  //'PHASE',
					(line[21]),  //'PROC_APPR',
					(line[22]),  //'SHOP_INV',
					(line[23]),  //'STD_CLASS',
					(line[24]),  //'STD_TYPE',
					(line[25]),  //'STATUS',
					(line[26]),  //'TYPE_EQUIP',
					(line[27]),  //'ICN',
					(line[28]),  //'FLAG_MC',
					(line[29]),  //'EQUIP_STAT',
					(line[30]),  //'DELAY_CD',
					(line[31]),  //'COND_EQUIP',
					(line[32]),  //'INST_SPCL',
					(line[33]),  //'HRS_STD',
					(line[34]),  //'METRL_N',
					(line[35]),  //'DT_SYS',
					(line[36]),  //'DT_RCVD',
					(line[37]),  //'DT_INDUCT',
					(line[38]),  //'DT_DELAY',
					(line[39]),  //'DT_REPTD',
					(line[40]),  //'DT_LSTCAL',
					(line[41]),  //'DT_NXTDUE',
					(line[42]),  //'DT_RECALL',
					(line[43]),  //'DT_CMPL',
					(line[44]),  //'DT_CREATE',
					(line[45]),  //'COST',
					(line[46]),  //'CAT_CUS',
					(line[47]),  //'CAT_LAB',
					(line[48]),  //'LAB_TYPE',
					(line[49]),  //'ACC_CODE',
					(line[50])//,  //'FLAG_OFFLN',
					//(line[51])  //'DTC_REIND',

								}
			); 
			c++;
			}         
		
		int rows = list.size();
		int numberOfColumns = 15; 
		
    	Object[][] data = new Object[rows][cols];    
		for (int i = 0; i < rows; i++) {        
			data[i] = list.get(i);     
		}
		
//Create model for JTable 		
    	model = new DefaultTableModel(data, colNames) {   		
    		public boolean isCellEditable(int rowIndex, int mColIndex) {
    			if(mColIndex > 0){
    			return false;
    			} 
    			else return true;
    		}
    	public Class getColumnClass(int col) {
    	Object o = getValueAt(0, col);     
    	if(o == null){                 
    		return Object.class;   
    		}
    	else     {         
    		return o.getClass();   
    			}
    		}  	
    	};
    	
    	data = null;
    	list = null;
    	Runtime.getRuntime().gc();
    	System.gc();
    	//Runtime.getRuntime().freeMemory();
    	
		List<Object[]> list2 = new ArrayList<Object[]>();  
		int c2 = 99999;
		while (/*s.hasNextLine() */c2 > 99998 && c2 < 200000 ) {         
			Object[] line2 = s.nextLine().split(","); 		
			list2.add(new Object[] {

					(Boolean.FALSE),	//PRINT
					(line2[0]),  //'LAB_SVC',
					(line2[1]),  //'CUSTOMER',
					(line2[2]),  //'MODEL',
					(line2[3]),  //'SERIAL',
					(line2[4]),  //'ECN',
					(line2[5]),  //'NOMEN',
					(line2[6]),  //'SUB_CUST',
					(line2[7]),  //'METRL_C',
					(line2[8]),  //'FSCM',
					(line2[9]),  //'UIC',
					(line2[10]),  //'LAB_SCHED',
					(line2[11]),  //'PROC_USED',
					(line2[12]),  //'VALUE_FIXD',
					(line2[13]),  //'NSN',
					(line2[14]),  //'PART_OF',
					(line2[15]),  //'ON_SITE',
					(line2[16]),  //'STD_CAL',
					(line2[17]),  //'LABEL_SVC',
					(line2[18]),  //'PLANT_ACCT',
					(line2[19]),  //'SUB_CAT',
					(line2[20]),  //'PHASE',
					(line2[21]),  //'PROC_APPR',
					(line2[22]),  //'SHOP_INV',
					(line2[23]),  //'STD_CLASS',
					(line2[24]),  //'STD_TYPE',
					(line2[25]),  //'STATUS',
					(line2[26]),  //'TYPE_EQUIP',
					(line2[27]),  //'ICN',
					(line2[28]),  //'FLAG_MC',
					(line2[29]),  //'EQUIP_STAT',
					(line2[30]),  //'DELAY_CD',
					(line2[31]),  //'COND_EQUIP',
					(line2[32]),  //'INST_SPCL',
					(line2[33]),  //'HRS_STD',
					(line2[34]),  //'METRL_N',
					(line2[35]),  //'DT_SYS',
					(line2[36]),  //'DT_RCVD',
					(line2[37]),  //'DT_INDUCT',
					(line2[38]),  //'DT_DELAY',
					(line2[39]),  //'DT_REPTD',
					(line2[40]),  //'DT_LSTCAL',
					(line2[41]),  //'DT_NXTDUE',
					(line2[42]),  //'DT_RECALL',
					(line2[43]),  //'DT_CMPL',
					(line2[44]),  //'DT_CREATE',
					(line2[45]),  //'COST',
					(line2[46]),  //'CAT_CUS',
					(line2[47]),  //'CAT_LAB',
					(line2[48]),  //'LAB_TYPE',
					(line2[49]),  //'ACC_CODE',
					(line2[50])//,  //'FLAG_OFFLN',
					//(line2[51])  //'DTC_REIND',
								}
			); 
			c2++;
			}         
		int rows2 = list2.size();
    	Object[][] data2 = new Object[rows2][cols];    
		for (int i = 0; i < rows2; i++) {        
			data2[i] = list2.get(i);     
		}
		
    	for(int z = 0; z < rows2; z++){
    		model.insertRow(z, data2[z]);
    	}

    	
		

        sorter = new TableRowSorter(model);  
        
//Populate JTable with model, containing the 2d array data

    	final JTable table = new JTable(model){
    			
//Override JTable Render component for alternate row shading   
    		final Color alphaZero = new Color(0, true);
    	
		public Component prepareRenderer(TableCellRenderer renderer,
				int rowIndex, int vColIndex) {
			setOpaque(false);
			Component c = super.prepareRenderer(renderer, rowIndex,
				vColIndex);
				if (isCellSelected(rowIndex, vColIndex)) {
					if (rowIndex % 2 == 0) {
						//c.setBackground(Color.LIGHT_GRAY );
						
						c.setBackground(alphaZero);
						
					} else {
						//c.setBackground(getSelectionBackground());
						c.setBackground(alphaZero);
					}
				} else {
				if (rowIndex % 2 == 0) {
					//c.setBackground(new Color(224, 242, 252));
					c.setBackground(alphaZero);
					} else {
						//c.setBackground(getBackground());
						c.setBackground(alphaZero);
						}
					};

				return c;
		}		};
System.out.println(table.getRowCount());

	table.getModel().addTableModelListener(new TableModelListener() {
			public void tableChanged(TableModelEvent e) {
		        int row2 = e.getFirstRow();
		        int column = e.getColumn();        
		        int columns = e.ALL_COLUMNS;
		        TableModel model = (TableModel)e.getSource();
		        String columnName = model.getColumnName(column);
		        Object data = model.getValueAt(row2, column);		      
		        Boolean val = getCBValueAt(row2, column);
				
				System.out.println(row2);
				System.out.println(column);
				System.out.println(val);
		    }

			private Boolean getCBValueAt(int row, int column) {
		    	  return (Boolean) table.getModel().getValueAt(row, column);
			} } 
	);

		table.setOpaque(false);
		table.convertRowIndexToView(row);
		table.setModel(model);
		table.getTableHeader().setBackground(new Color(174, 201, 230));
		table.getTableHeader().setFont(new Font("SansSerif", Font.BOLD, 12));
		table.setRowSorter(sorter);  
		//table.setAutoCreateRowSorter(true);
    	//table.setDefaultRenderer(String.class, new CustomRenderer());
    	table.setRowSelectionAllowed(true);       
    	table.setColumnSelectionAllowed(true);     
    	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	    ListSelectionModel listMod =  table.getSelectionModel();
	    listMod.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	    listMod.addListSelectionListener(this);

    	return table;
    
    	
    	} 
    
    
    
//Search method
	 void search()
	    {
		 
	        String target = textField.getText();
	        for(int row = 1; row < table.getRowCount(); row++)
	            for(int col = 1; col < table.getColumnCount() -1 ; col++)
	            {
	                String next = (String)table.getValueAt(row, col);
	                if(next.equals(target))
	                {
	                    showSearchResults(row, col);
	                    return;
	                }
	            }
	 
// reset table display after failed search> target null/not found <
	        CustomRenderer renderer =
	                (CustomRenderer)table.getDefaultRenderer(String.class);
	        renderer.setTargetCell(-1, -1);
	        table.repaint();
	    }
	 
	 private void newFilter()  
	 {  
   	  //row = table.convertRowIndexToView(row);

		 List<RowFilter<TableModel,Object>> filters = new ArrayList<RowFilter<TableModel,Object>>();
		 RowFilter<TableModel, Object> compoundRowFilter = null;
		 try {
		     svclabf = RowFilter.regexFilter("^" + svclabt.getText(), 1);
		     custf = RowFilter.regexFilter("^" +custt.getText(), 2);
		     modf = RowFilter.regexFilter("^" +modt.getText(), 3);
		     serialf = RowFilter.regexFilter("^" +serialt.getText(), 4);
		     ecnf = RowFilter.regexFilter("^" +ecnt.getText(), 5);
		     subcustf = RowFilter.regexFilter("^" +subcustt.getText(), 7);
		     
		     filters.add(svclabf);
		     filters.add(custf);
		     filters.add(modf);
		     filters.add(serialf);
		     filters.add(ecnf);
		     filters.add(subcustf);
		     compoundRowFilter = RowFilter.andFilter(filters); // you may also choose the OR filter
		 } catch (java.util.regex.PatternSyntaxException e) {
		     return;
		 }
		 sorter.setRowFilter(compoundRowFilter); 		 
	 }  
 
	 void search2(){
		 
// reset table display after failed search		   
	      CustomRenderer renderer = (CustomRenderer)table.getDefaultRenderer(String.class);
	      renderer.setTargetCell(-1, -1);
	      table.repaint();
		
		 String [] searchlist = new String[6];
		 Boolean match; //use as toggle for search decision tree?
		 String sECN = null; Boolean Ec = true;
		 String sCust = null; Boolean Cc = true;
		 String sMod = null; Boolean Mc = true;
		 String sSer = null; Boolean  Sc = true;
		 String sNom = null; Boolean Nc = true;
		 String sSubCust = null; Boolean Scc = true;		 
		 
//Only get Text Field value if Check box is checked		 
		 if (cECN.isSelected()){
			 sECN = tECN.getText();
		 } else if(!cECN.isSelected()) {sECN = null;}; //if needed, catch null exception so "" won't be passed to search list? -- causes null pointer exception
		 if (cCust.isSelected()){
			 sCust = tCust.getText();
		 } 
		 if (cMod.isSelected()){
			 sMod = tMod.getText();
		 }
		 if (cSer.isSelected()){
			 sSer = tSer.getText();
		 }
		 if (cNom.isSelected()){
			 sNom = tNom.getText();
		 }
		 if (cSubCust.isSelected()){
			 sSubCust = tSubCust.getText();
		 }
//After assigning String values from text fields based on check box confirmation, fill an array list with values
		searchlist[0] = sECN;
		searchlist[1] = sCust;
		searchlist[2] = sMod;
		searchlist[3] = sSer;
		searchlist[4] = sNom;
		searchlist[5] = sSubCust;		

//Need: array to hold table row values
  Object[] tbrowdata = new Object[8];
  TableModel tb = table.getModel();
  Object val;
  int selectedRow;
  
  for(int r = 0; r < table.getRowCount(); r++){ 
	  selectedRow = r;
	  
  for (int i= 1; i < 8 ; i++) {
	  val = tb.getValueAt(r, i);
	  tbrowdata [i-1] = val;
   
  		}
  if(
	 ((tbrowdata[4].equals(searchlist[0])) || searchlist[0] == null) &&
	 ((tbrowdata[1].equals(searchlist[1])) || searchlist[1] == null) &&
	 ((tbrowdata[2].equals(searchlist[2])) || searchlist[2] == null) &&
	 ((tbrowdata[3].equals(searchlist[3])) || searchlist[3] == null) &&
	 ((tbrowdata[5].equals(searchlist[4])) || searchlist[4] == null) &&
	 ((tbrowdata[6].equals(searchlist[5])) || searchlist[5] == null) 
	  
	){
	  showSearchResults(r, 5);
  	}

  }
  
//test print values from GUI Text Fields when respective Check box is checked
		 /*
  		 System.out.println(searchlist[0]);
		 System.out.println(searchlist[1]);
		 System.out.println(sMod);
		 System.out.println(sSer);
		 System.out.println(sNom);
		 System.out.println(sSubCust);
	 	*/
	 }
	 
//returnReportData 	 
	 public Object[][] returnReportData(){
		 
		 TableModel tm2 = table.getModel();
//Get count of rows with Print Box checked (counter = z) to initialize the reportData Object[][] 
		 int z = 0; 		 
		 for(int x = 0; x < tm2.getRowCount(); x++){
			 if(((Boolean)tm2.getValueAt(x, 0)) == true){
				  z++;				  				  
			 }
		 }
//Initialize Object[][]	reportData and store dimensions as tRow and tCol	 		 			 
		 int nRow = tm2.getRowCount(), nCol = tm2.getColumnCount();
		 Object[][] reportData = new Object[z][54];  
		 int tRow = reportData.length, tCol = reportData[0].length;

//Populate reportData with table model data where Checkbox = Boolean.TRUE				 
		 int index = 0;
		 for (int i = 0 ; i < nRow ; i++){
		     if(((Boolean)tm2.getValueAt(i, 0)) == true){
		         for (int j = 1 ; j < nCol ; j++){   
		              reportData[index][j] = tm2.getValueAt(i,j);  
		         }
		         ++index;
		     }
		 }
		 
//Test print reportData in rectangular form
		 int ROWS = reportData.length;
		 int COLS = reportData[0].length;
		 for (int L = 0; L < ROWS; L++) {
			 for (int M = 0; M < COLS; M++) {
				System.out.print(" " + reportData[L][M]);
		 }
		 System.out.println("");
		 }
		return reportData;		 	 
	}		 
 
//Show the search results using Custom Renderer 
		private void showSearchResults(int row, int col)
		    {
				//table.repaint();
		        CustomRenderer renderer = (CustomRenderer)table.getCellRenderer(row, col);
		        renderer.setTargetCell(row, col);
		        Rectangle r = table.getCellRect(row, col, false);
		        table.scrollRectToVisible(r);
				table.repaint();

		    }

//Main method for test purposes		
		public void main(String[] args) throws IOException
		    {
		        SearchTest test = new SearchTest();
		        JFrame f = new JFrame("-JQuery V_0.1 Beta-");
		        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
				Container cP = f.getContentPane(); 
		
				f.getContentPane().add(new JTabbedPane());
		        f.getContentPane().add(new JScrollPane(test.table));
		        f.getContentPane().add(test.textField, "North");
		        f.setSize(600,400);
		        f.setLocationRelativeTo(null);
		        f.setVisible(true);
		        test.textField.requestFocusInWindow();
		
		    }

		

		
//Mouse Event Listener for Row Selection into Detail Tab		
	Object o;
	Object[] dtlist = new Object[53];
	public void valueChanged(ListSelectionEvent e) {
		   Object value;
		   if (!e.getValueIsAdjusting()) {       	
		     selRows = table.getSelectedRow();
		     row = selRows;		     
		     
// get Table data
		     TableModel tm = table.getModel();
		     if (row > -1) {
		    	 row = table.convertRowIndexToModel(row);
		        for (int i= 1; i < 53 ; i++) {
		          value = tm.getValueAt(row,i);
		          dtlist[i-1]  = value;

		          }
//get test value in array dtlist
		        o = Array.get(dtlist, 1);
		        //System.out.println(selRows);
		        //System.out.println(row);
		        //Key Fields
		        dtECN.setText((String) Array.get(dtlist, 4));
		        dtCust.setText((String) Array.get(dtlist, 1));
		        dtMod.setText((String) Array.get(dtlist, 2));
		        dtSer.setText((String) Array.get(dtlist, 3));
		        dtNom.setText((String) Array.get(dtlist, 5));
		        
		        //Auxiliary Fields
		        dtMFR.setText((String) Array.get(dtlist, 8));
		        dtPARTOF.setText((String) Array.get(dtlist, 14));
		        dtSUBCUST.setText((String) Array.get(dtlist, 6));
		        dtSCHEDLAB.setText((String) Array.get(dtlist, 10));
		        dtSCAT.setText((String) Array.get(dtlist, 19));
		        dtNSN.setText((String) Array.get(dtlist, 13));
		        dtPLANTACCT.setText((String) Array.get(dtlist, 18));
		        dtAPPRPROC.setText((String) Array.get(dtlist, 21));
		        dtSVCLAB.setText((String) Array.get(dtlist, 0));
		        dtMETCYCLE.setText((String) Array.get(dtlist, 7));
		        dtPHASE.setText((String) Array.get(dtlist, 20));
		        dtDTCOMPL.setText((String) Array.get(dtlist, 43));
		        dtDTLASTSER.setText((String) Array.get(dtlist, 40));
		        dtSERVLBL.setText((String) Array.get(dtlist, 17));
		        dtDTNEXTDUE.setText((String) Array.get(dtlist, 41));
		        dtSTATUS.setText((String) Array.get(dtlist, 8));
		        dtONSITE.setText((String) Array.get(dtlist, 15));
		        dtSHOP.setText((String) Array.get(dtlist, 22));
		        dtWLNHRS.setText((String) Array.get(dtlist, 33));
		        dtCLASSSTD.setText((String) Array.get(dtlist, 23));
		        dtCALSTD.setText((String) Array.get(dtlist, 16));
	        
		        }
		     } 
		    }

	@Override
	public void tableChanged(TableModelEvent e) {
		if (!((ListSelectionModel) e).getValueIsAdjusting()) {
		int index = e.getFirstRow();
		model.setValueAt(Boolean.TRUE, index, 0);
		}
	} 

} //end SearchTest



class TransparentButton extends JButton {
	public TransparentButton(String text) { 
	    super(text);
	    final Color alphaZero = new Color(0, true);
	    setBackground(alphaZero);
	    setForeground(Color.black);
	    setOpaque(false); 
	    //setBorder(null);  
	    //setBorderPainted(false);    
	    setContentAreaFilled(true);     
	} 
	    
	public void paint(Graphics g) { 
	    Graphics2D g2 = (Graphics2D) g.create(); 
	    //g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); 
	    super.paint(g2); 
	    setForeground(Color.black);
	    g2.dispose(); 
	} 
}

	class CustomRenderer implements TableCellRenderer{
	    JLabel label;
	    int targetRow, targetCol;
	    final Color alphaZero = new Color(0, true);
	 
	    public CustomRenderer()
	    {
	        label = new JLabel();
	        label.setHorizontalAlignment(JLabel.CENTER);
	        label.setOpaque(true);
	        targetRow = -1;
	        targetCol = -1;
	    }

 
public Component getTableCellRendererComponent(JTable table,
                                                   Object value,
                                                   boolean isSelected,
                                                   boolean hasFocus,
                                                   int row, int column)
    {
        if(isSelected)
        {
            label.setBackground(alphaZero);
            label.setForeground(alphaZero);
            //label.setForeground(table.getSelectionForeground());
        }
        else
        {
            label.setBackground(alphaZero);
            label.setForeground(alphaZero);
            //label.setForeground(table.getForeground());
        }
        if(row == targetRow && column == targetCol)
        {
            label.setBorder(BorderFactory.createLineBorder(Color.red));
            label.setFont(table.getFont().deriveFont(Font.BOLD));
        }
        else
        {
            label.setBorder(null);
            label.setFont(table.getFont());
        }
        label.setText((String)value);
        return label;
    }

	public void setTargetRow(int row){
		targetRow = row;
	}
 
    public void setTargetCell(int row, int col)
    {
        targetRow = row;
        targetCol = col;
    }

}
	



This post has been edited by Examiner12: 04 May 2012 - 12:02 PM

Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 04 May 2012 - 12:17 PM

That shouldn't reqire that many changes if any.
The any difference is that you now provide your own TableModel rather then

model = new DefaultTableModel(data, colNames)

you have

MyModel model = new MyModel(colNams, arrayList)

so all your table.getModel() and all your cellRenderer should stay the same
Don't see what you will have to change in your code
Was This Post Helpful? 0
  • +
  • -

#5 Examiner12  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 89
  • Joined: 02-February 12

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 04 May 2012 - 01:20 PM

Ok, making some progress. I'm so grateful! Still receiving some errors with the behavior of the table:

1. When I select an item:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 51
at PCQ.SearchTest$MyModel.getValueAt(SearchTest.java:522)
at PCQ.SearchTest.valueChanged(SearchTest.java:766)
2. When I enter something in one of the Filter text boxes:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at PCQ.SearchTest.newFilter(SearchTest.java:595)
at PCQ.SearchTest.access$0(SearchTest.java:571)
at PCQ.SearchTest$3.insertUpdate(SearchTest.java:209)
3. When I select one of the col[0] (print checkbox):
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 51
at PCQ.SearchTest$MyModel.getValueAt(SearchTest.java:522)
at PCQ.SearchTest.valueChanged(SearchTest.java:766)

It appears it's bombing on the getValueAt method?

Here's the current compiled code:


//SEARCH TEST BACKUP - WITH HEAP SPACE ISSUE
package PCQ;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;



 
public class SearchTest implements ListSelectionListener, TableModelListener
{
//Main Table Object	
    JTable table;
    DefaultTableModel model;
    
    int selRows;
    int row;
    int row2;
	 RowFilter<TableModel, Object> svclabf = null;
	 RowFilter<TableModel, Object> custf = null;
	 RowFilter<TableModel, Object> modf = null;
	 RowFilter<TableModel, Object> serialf = null;
	 RowFilter<TableModel, Object> ecnf = null;
	 RowFilter<TableModel, Object> subcustf = null;
    
private TableRowSorter<TableModel> sorter ;  
    
//Search Field - Basic (Test)
    JTextField textField;
    
//Test Sorter Field
    
    JTextField svclabt;
    JTextField custt;
    JTextField modt;
    JTextField serialt;
    JTextField ecnt;
    JTextField subcustt;
    
    TransparentButton mcb = new TransparentButton("Get Meter Card(s)"); 
    TransparentButton metcb = new TransparentButton("Get MetCal Form(s)");

    
    
//Search Function - Complete
    
    JButton bs;
    JCheckBox cECN; 
    JCheckBox cCust;
    JCheckBox cMod;
    JCheckBox cSer;
    JCheckBox cNom;
    JCheckBox cSubCust;
    JTextField tECN;
    JTextField tCust;
    JTextField tMod;
    JTextField tSer;
    JTextField tNom;
    JTextField tSubCust;
    
//Text Fields for Detail Tab: Key Fields   
    JTextField dtECN;
    JTextField dtCust;
    JTextField dtMod;
    JTextField dtSer;
    JTextField dtNom;

//Text Fields for Detail Tab: Auxiliary Fields
    
    JTextField dtMFR;
    JTextField dtPARTOF;
    JTextField dtSUBCUST;
    JTextField dtSCHEDLAB;
    JTextField dtSCAT;
    JTextField dtNSN;
    JTextField dtPLANTACCT;
    JTextField dtAPPRPROC;
    JTextField dtSVCLAB;
    JTextField dtMETCYCLE;
    JTextField dtPHASE;
    JTextField dtDTCOMPL;
    JTextField dtDTLASTSER;
    JTextField dtSERVLBL;
    JTextField dtDTNEXTDUE;
    JTextField dtSTATUS;
    JTextField dtONSITE;
    JTextField dtSHOP;
    JTextField dtWLNHRS;
    JTextField dtCLASSSTD;
    JTextField dtCALSTD;
    
    

 
    public SearchTest() throws IOException 
    {
    	
    	
        table = getTable();
        table.setOpaque(false);
        
     //Search Function - Complete
        //Color bg = new Color(210, 222, 242);
        Color bg = new Color(224, 242, 252);
        bs = new JButton("  Search  ");
        mcb.setToolTipText("Get Meter Card(s) for Current PRINT Checkbox Selection");
        metcb.setToolTipText("Get MetCal Form(s) for Current PRINT Selection");
        svclabt = new JTextField(10); svclabt.setBackground(bg); svclabt.setToolTipText("Filter by Servicing Lab");
        custt = new JTextField(10); custt.setBackground(bg); custt.setToolTipText("Filter by Customer Code");
        modt= new JTextField(10); modt.setBackground(bg); modt.setToolTipText("Filter by Model Number");
        serialt = new JTextField(10); serialt.setBackground(bg); serialt.setToolTipText("Filter by Serial Number");
        ecnt = new JTextField(10); ecnt.setBackground(bg); ecnt.setToolTipText("Filter by Equipment Control Number");
        subcustt = new JTextField(10); subcustt.setBackground(bg); subcustt.setToolTipText("Filter by Sub Custodian");
        
        cECN = new JCheckBox("ECN:");
        cCust = new JCheckBox("CUSTOMER:");
        cMod = new JCheckBox("MODEL:");
        cSer = new JCheckBox("SERIAL:");
        cNom = new JCheckBox("NOMENCLATURE:");
        cSubCust = new JCheckBox("SUB CUSTODIAN:");
        tECN = new JTextField(10);
        tCust = new JTextField(10);
        tMod = new JTextField(10);
        tSer = new JTextField(10);
        tNom = new JTextField(10);
        tSubCust = new JTextField(10);
        
        
        textField = new JTextField();
        textField.setBackground(bg); 
        
//Detail Tab - Key Field Text Boxes   
                
        dtECN = new JTextField(15);	dtECN.setEditable(false);	dtECN.setBackground(bg); 
        dtCust = new JTextField(15);	dtCust.setEditable(false);	dtCust.setBackground(bg);
        dtMod = new JTextField(15);	dtMod.setEditable(false);	dtMod.setBackground(bg);
        dtSer = new JTextField(15);	dtSer.setEditable(false);	dtSer.setBackground(bg);
        dtNom = new JTextField(15);	dtNom.setEditable(false);	dtNom.setBackground(bg);

        
//Detail Tab - Auxiliary Field Text Boxes  
        dtMFR = new JTextField(15);    dtMFR.setEditable(false);    dtMFR.setBackground(bg);
        dtPARTOF = new JTextField(15);    dtPARTOF.setEditable(false);    dtPARTOF.setBackground(bg);
        dtSUBCUST = new JTextField(15);    dtSUBCUST.setEditable(false);    dtSUBCUST.setBackground(bg);
        dtSCHEDLAB = new JTextField(15);    dtSCHEDLAB.setEditable(false);    dtSCHEDLAB.setBackground(bg);
        dtSCAT = new JTextField(15);    dtSCAT.setEditable(false);    dtSCAT.setBackground(bg);
        dtNSN = new JTextField(15);    dtNSN.setEditable(false);    dtNSN.setBackground(bg);
        dtPLANTACCT = new JTextField(15);    dtPLANTACCT.setEditable(false);    dtPLANTACCT.setBackground(bg);
        dtAPPRPROC = new JTextField(15);    dtAPPRPROC.setEditable(false);    dtAPPRPROC.setBackground(bg);
        dtSVCLAB = new JTextField(15);    dtSVCLAB.setEditable(false);    dtSVCLAB.setBackground(bg);
        dtMETCYCLE = new JTextField(15);    dtMETCYCLE.setEditable(false);    dtMETCYCLE.setBackground(bg);
        dtPHASE = new JTextField(15);    dtPHASE.setEditable(false);    dtPHASE.setBackground(bg);
        dtDTCOMPL = new JTextField(15);    dtDTCOMPL.setEditable(false);    dtDTCOMPL.setBackground(bg);
        dtDTLASTSER = new JTextField(15);    dtDTLASTSER.setEditable(false);    dtDTLASTSER.setBackground(bg);
        dtSERVLBL = new JTextField(15);    dtSERVLBL.setEditable(false);    dtSERVLBL.setBackground(bg);
        dtDTNEXTDUE = new JTextField(15);    dtDTNEXTDUE.setEditable(false);    dtDTNEXTDUE.setBackground(bg);
        dtSTATUS = new JTextField(15);    dtSTATUS.setEditable(false);    dtSTATUS.setBackground(bg);
        dtONSITE = new JTextField(15);    dtONSITE.setEditable(false);    dtONSITE.setBackground(bg);
        dtSHOP = new JTextField(15);    dtSHOP.setEditable(false);    dtSHOP.setBackground(bg);
        dtWLNHRS = new JTextField(15);    dtWLNHRS.setEditable(false);    dtWLNHRS.setBackground(bg);
        dtCLASSSTD = new JTextField(15);    dtCLASSSTD.setEditable(false);    dtCLASSSTD.setBackground(bg);
        dtCALSTD = new JTextField(15);    dtCALSTD.setEditable(false);    dtCALSTD.setBackground(bg);
        

        textField.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                search();
            }
        });
        
        bs.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
            	table.repaint();
            	search2();
            }
        });
        
        svclabt.getDocument().addDocumentListener
        (  
        		   new DocumentListener()  
        		   {
        			           			   
        		      public void changedUpdate(DocumentEvent e)  
        		      {   	       		    	 
        		    	  newFilter();  
        		      }  
        		      public void insertUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void removeUpdate(DocumentEvent e)  
        		      {  
        		         newFilter();  
        		      }  
        		   }  
        		);  
        custt.getDocument().addDocumentListener
        (  
        		   new DocumentListener()  
        		   {  
        		      public void changedUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void insertUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void removeUpdate(DocumentEvent e)  
        		      {  
        		         newFilter();  
        		      }  
        		   }  
        		); 
        modt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        serialt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        ecnt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        subcustt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		);     
    mcb.addActionListener(new ActionListener()
        {
        public void actionPerformed(ActionEvent e)
        {
                 returnReportData();
               }
        });
     
    metcb.addActionListener(new ActionListener()
        {
        public void actionPerformed(ActionEvent e)
        {
                 returnReportData();
               }
        });
        
        
        
    }
 
//Get the JTable and return it    
	JTable getTable() throws IOException    { 

		File f = new File("C:\\PCQ\\A_R.csv");
		Scanner s = new Scanner(f);

		String[] colNames = { 
				"PRINT", 
				"SERVICED_LAB", 
				"CUSTOMER_ID", 
				"MODEL_NO", 
				"SERIAL_NO", 
				"ECN", 
				"NOMENCLATURE", 
				"SUB_CUSTODIAN", 
				"METRL_CYCLE", 
				"MFR_CD", 
				"UIC", 
				"SCHED_LAB", 
				"PROCEDURE_USED", 
				"VALUE_FIXED", 
				"NSN", 
				"PART_OF", 
				"ON_SITE_SERVICE", 
				"CAL_STD", 
				"SERVICE_LABEL_CD", 
				"PLANT_ACCT", 
				"SCAT_CD", 
				"PHASE_ID", 
				"APPROVED_PROCEDURE", 
				"INV_SHOP_NO", 
				"CLASS_STD", 
				"TYPE_STD", 
				"WIP_STATUS", 
				"EQPMT_TYPE_CD", 
				"ICN", 
				"PRINT_METERCARD_FLG", 
				"EQPMT_STATUS_CD", 
				"DELAY_REASON_CD", 
				"EQPMT_STATUS_CD", 
				"SPCL_INSTR_CD", 
				"WORKLOAD_NORM_HRS", 
				"METRL_CYCLE", 
				"DTC_SYS", 
				"DTC_RCVD", 
				"DTC_INDUCT", 
				"DTC_DELAY", 
				"DTC_REPTD", 
				"DTC_LSTCAL", 
				"DTC_NXT_DUE", 
				"DTC_RECALL", 
				"DT_CMPL", 
				"DT_CREATE", 
				"COST", 
				"CAT_CUS", 
				"CAT_LAB", 
				"LAB_TYPE", 
				"ACC_CODE", 
				"FLAG_OFFLN", 
				"DTC_REIND"

		};  

		LineNumberReader  lnr = new LineNumberReader(new FileReader(f)); 
		lnr.skip(Long.MAX_VALUE); 
		int ln = lnr.getLineNumber();
		
		//Import CSV File into 2d array   	  
		ArrayList<String> al = new ArrayList<String>(ln);
		int c = 0;
		while (c < ln ) {         
			al.add(s.nextLine()); 
			c++;
		}     

		MyModel model = new MyModel(colNames, al);
		final JTable table =  new JTable(model){   		
    		public boolean isCellEditable(int rowIndex, int mColIndex) {
    			if(mColIndex > 0){
    			return false;
    			} 
    			else return true;
    		}
    	public Class getColumnClass(int col) {
    	Object o = getValueAt(0, col);     
    	if(o == null){                 
    		return Object.class;   
    		}
    	else     {         
    		return o.getClass();   
    			}
    		} 
    	final Color alphaZero = new Color(0, true);
		public Component prepareRenderer(TableCellRenderer renderer,
				int rowIndex, int vColIndex) {
			setOpaque(false);
			Component c = super.prepareRenderer(renderer, rowIndex,
				vColIndex);
				if (isCellSelected(rowIndex, vColIndex)) {
					if (rowIndex % 2 == 0) {
						//c.setBackground(Color.LIGHT_GRAY );
						
						c.setBackground(alphaZero);
						
					} else {
						//c.setBackground(getSelectionBackground());
						c.setBackground(alphaZero);
					}
				} else {
				if (rowIndex % 2 == 0) {
					//c.setBackground(new Color(224, 242, 252));
					c.setBackground(alphaZero);
					} else {
						//c.setBackground(getBackground());
						c.setBackground(alphaZero);
						}
					};

				return c;
				}
    	};
    	
    	table.getModel().addTableModelListener(new TableModelListener() {
			public void tableChanged(TableModelEvent e) {
		        int row2 = e.getFirstRow();
		        int column = e.getColumn();        
		        int columns = e.ALL_COLUMNS;
		        TableModel model = (TableModel)e.getSource();
		        String columnName = model.getColumnName(column);
		        Object data = model.getValueAt(row2, column);		      
		        Boolean val = getCBValueAt(row2, column);
				
				System.out.println(row2);
				System.out.println(column);
				System.out.println(val);
		    }

			private Boolean getCBValueAt(int row, int column) {
		    	  return (Boolean) table.getModel().getValueAt(row, column);
			} } 
	);
    	
		table.setOpaque(false);
		table.convertRowIndexToView(row);
		table.setModel(model);
		table.getTableHeader().setBackground(new Color(174, 201, 230));
		table.getTableHeader().setFont(new Font("SansSerif", Font.BOLD, 12));
		table.setRowSorter(sorter);  
		//table.setAutoCreateRowSorter(true);
    	//table.setDefaultRenderer(String.class, new CustomRenderer());
    	table.setRowSelectionAllowed(true);       
    	table.setColumnSelectionAllowed(true);     
    	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	    ListSelectionModel listMod =  table.getSelectionModel();
	    listMod.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	    listMod.addListSelectionListener(this);
	    
	    
    	return table;
	}
	
// my tableModel as an inner class
	class MyModel extends AbstractTableModel {
		String[] colName;
		ArrayList<String> al;
		ArrayList<Boolean> first;

		MyModel(String[] colName, ArrayList<String> al) {
			this.colName = colName;
			this.al = al;
			first = new ArrayList<Boolean>(al.size());
			for(int i = 0; i < al.size(); ++i)
				first.add(Boolean.valueOf(false));
		}

		@Override
		public int getColumnCount() {
			// TODO Auto-generated method stub
			return colName.length -2;
		}
		public String getColumnName(int col) {
			return colName[col];
		}

		@Override
		public int getRowCount() {
			return al.size();
		}

		@Override
		public Object getValueAt(int row, int col) {
			if(col == 0)
				return first.get(row);
			String line = al.get(row);
			String[] token = line.split(",");
			return token[col-1];
		}

		public void setValueAt(Object o, int row, int col) {
			// first col is the boolean
			if(col == 0) {
				first.set(row, (Boolean) o);
				return;
			}
			// other col
			String line = al.get(row);
			String[] token = line.split(",");
			token[row-1] = (String) o;         // replace with new one
			// rebuid the String
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < token.length - 1; ++i)
				sb.append(token[i]).append(',');   // with the coma
			sb.append(token[token.length-1]);     // but for the last one
			al.set(row, sb.toString());           // replace in ArrayList
		}
		
		
	}
    
    
    
//Search method
	 void search()
	    {
		 
	        String target = textField.getText();
	        for(int row = 1; row < table.getRowCount(); row++)
	            for(int col = 1; col < table.getColumnCount() -1 ; col++)
	            {
	                String next = (String)table.getValueAt(row, col);
	                if(next.equals(target))
	                {
	                    showSearchResults(row, col);
	                    return;
	                }
	            }
	 
// reset table display after failed search> target null/not found <
	        CustomRenderer renderer =
	                (CustomRenderer)table.getDefaultRenderer(String.class);
	        renderer.setTargetCell(-1, -1);
	        table.repaint();
	    }
	 
	 private void newFilter()  
	 {  
   	  //row = table.convertRowIndexToView(row);

		 List<RowFilter<TableModel,Object>> filters = new ArrayList<RowFilter<TableModel,Object>>();
		 RowFilter<TableModel, Object> compoundRowFilter = null;
		 try {
		     svclabf = RowFilter.regexFilter("^" + svclabt.getText(), 1);
		     custf = RowFilter.regexFilter("^" +custt.getText(), 2);
		     modf = RowFilter.regexFilter("^" +modt.getText(), 3);
		     serialf = RowFilter.regexFilter("^" +serialt.getText(), 4);
		     ecnf = RowFilter.regexFilter("^" +ecnt.getText(), 5);
		     subcustf = RowFilter.regexFilter("^" +subcustt.getText(), 7);
		     
		     filters.add(svclabf);
		     filters.add(custf);
		     filters.add(modf);
		     filters.add(serialf);
		     filters.add(ecnf);
		     filters.add(subcustf);
		     compoundRowFilter = RowFilter.andFilter(filters); // you may also choose the OR filter
		 } catch (java.util.regex.PatternSyntaxException e) {
		     return;
		 }
		 sorter.setRowFilter(compoundRowFilter); 		 
	 }  
 
	 void search2(){
		 
// reset table display after failed search		   
	      CustomRenderer renderer = (CustomRenderer)table.getDefaultRenderer(String.class);
	      renderer.setTargetCell(-1, -1);
	      table.repaint();
		
		 String [] searchlist = new String[6];
		 Boolean match; //use as toggle for search decision tree?
		 String sECN = null; Boolean Ec = true;
		 String sCust = null; Boolean Cc = true;
		 String sMod = null; Boolean Mc = true;
		 String sSer = null; Boolean  Sc = true;
		 String sNom = null; Boolean Nc = true;
		 String sSubCust = null; Boolean Scc = true;		 
		 
//Only get Text Field value if Check box is checked		 
		 if (cECN.isSelected()){
			 sECN = tECN.getText();
		 } else if(!cECN.isSelected()) {sECN = null;}; //if needed, catch null exception so "" won't be passed to search list? -- causes null pointer exception
		 if (cCust.isSelected()){
			 sCust = tCust.getText();
		 } 
		 if (cMod.isSelected()){
			 sMod = tMod.getText();
		 }
		 if (cSer.isSelected()){
			 sSer = tSer.getText();
		 }
		 if (cNom.isSelected()){
			 sNom = tNom.getText();
		 }
		 if (cSubCust.isSelected()){
			 sSubCust = tSubCust.getText();
		 }
//After assigning String values from text fields based on check box confirmation, fill an array list with values
		searchlist[0] = sECN;
		searchlist[1] = sCust;
		searchlist[2] = sMod;
		searchlist[3] = sSer;
		searchlist[4] = sNom;
		searchlist[5] = sSubCust;		

//Need: array to hold table row values
  Object[] tbrowdata = new Object[8];
  TableModel tb = table.getModel();
  Object val;
  int selectedRow;
  
  for(int r = 0; r < table.getRowCount(); r++){ 
	  selectedRow = r;
	  
  for (int i= 1; i < 8 ; i++) {
	  val = tb.getValueAt(r, i);
	  tbrowdata [i-1] = val;
   
  		}
  if(
	 ((tbrowdata[4].equals(searchlist[0])) || searchlist[0] == null) &&
	 ((tbrowdata[1].equals(searchlist[1])) || searchlist[1] == null) &&
	 ((tbrowdata[2].equals(searchlist[2])) || searchlist[2] == null) &&
	 ((tbrowdata[3].equals(searchlist[3])) || searchlist[3] == null) &&
	 ((tbrowdata[5].equals(searchlist[4])) || searchlist[4] == null) &&
	 ((tbrowdata[6].equals(searchlist[5])) || searchlist[5] == null) 
	  
	){
	  showSearchResults(r, 5);
  	}

  }
  
//test print values from GUI Text Fields when respective Check box is checked
		 /*
  		 System.out.println(searchlist[0]);
		 System.out.println(searchlist[1]);
		 System.out.println(sMod);
		 System.out.println(sSer);
		 System.out.println(sNom);
		 System.out.println(sSubCust);
	 	*/
	 }
	 
//returnReportData 	 
	 public Object[][] returnReportData(){
		 
		 TableModel tm2 = table.getModel();
//Get count of rows with Print Box checked (counter = z) to initialize the reportData Object[][] 
		 int z = 0; 		 
		 for(int x = 0; x < tm2.getRowCount(); x++){
			 if(((Boolean)tm2.getValueAt(x, 0)) == true){
				  z++;				  				  
			 }
		 }
//Initialize Object[][]	reportData and store dimensions as tRow and tCol	 		 			 
		 int nRow = tm2.getRowCount(), nCol = tm2.getColumnCount();
		 Object[][] reportData = new Object[z][54];  
		 int tRow = reportData.length, tCol = reportData[0].length;

//Populate reportData with table model data where Checkbox = Boolean.TRUE				 
		 int index = 0;
		 for (int i = 0 ; i < nRow ; i++){
		     if(((Boolean)tm2.getValueAt(i, 0)) == true){
		         for (int j = 1 ; j < nCol ; j++){   
		              reportData[index][j] = tm2.getValueAt(i,j);  
		         }
		         ++index;
		     }
		 }
		 
//Test print reportData in rectangular form
		 int ROWS = reportData.length;
		 int COLS = reportData[0].length;
		 for (int L = 0; L < ROWS; L++) {
			 for (int M = 0; M < COLS; M++) {
				System.out.print(" " + reportData[L][M]);
		 }
		 System.out.println("");
		 }
		return reportData;		 	 
	}		 
 
//Show the search results using Custom Renderer 
		private void showSearchResults(int row, int col)
		    {
				//table.repaint();
		        CustomRenderer renderer = (CustomRenderer)table.getCellRenderer(row, col);
		        renderer.setTargetCell(row, col);
		        Rectangle r = table.getCellRect(row, col, false);
		        table.scrollRectToVisible(r);
				table.repaint();

		    }

//Main method for test purposes		
		public void main(String[] args) throws IOException
		    {
		        SearchTest test = new SearchTest();
		        JFrame f = new JFrame("-JQuery V_0.1 Beta-");
		        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
				Container cP = f.getContentPane(); 
		
				f.getContentPane().add(new JTabbedPane());
		        f.getContentPane().add(new JScrollPane(test.table));
		        f.getContentPane().add(test.textField, "North");
		        f.setSize(600,400);
		        f.setLocationRelativeTo(null);
		        f.setVisible(true);
		        test.textField.requestFocusInWindow();
		
		    }

		

		
//Mouse Event Listener for Row Selection into Detail Tab		
	Object o;
	Object[] dtlist = new Object[53];
	public void valueChanged(ListSelectionEvent e) {
		   Object value;
		   if (!e.getValueIsAdjusting()) {       	
		     selRows = table.getSelectedRow();
		     row = selRows;		     
		     
// get Table data
		     TableModel tm = table.getModel();
		     if (row > -1) {
		    	 row = table.convertRowIndexToModel(row);
		        for (int i= 1; i < 53 ; i++) {
		          value = tm.getValueAt(row,i);
		          dtlist[i-1]  = value;

		          }
//get test value in array dtlist
		        o = Array.get(dtlist, 1);
		        //System.out.println(selRows);
		        //System.out.println(row);
		        //Key Fields
		        dtECN.setText((String) Array.get(dtlist, 4));
		        dtCust.setText((String) Array.get(dtlist, 1));
		        dtMod.setText((String) Array.get(dtlist, 2));
		        dtSer.setText((String) Array.get(dtlist, 3));
		        dtNom.setText((String) Array.get(dtlist, 5));
		        
		        //Auxiliary Fields
		        dtMFR.setText((String) Array.get(dtlist, 8));
		        dtPARTOF.setText((String) Array.get(dtlist, 14));
		        dtSUBCUST.setText((String) Array.get(dtlist, 6));
		        dtSCHEDLAB.setText((String) Array.get(dtlist, 10));
		        dtSCAT.setText((String) Array.get(dtlist, 19));
		        dtNSN.setText((String) Array.get(dtlist, 13));
		        dtPLANTACCT.setText((String) Array.get(dtlist, 18));
		        dtAPPRPROC.setText((String) Array.get(dtlist, 21));
		        dtSVCLAB.setText((String) Array.get(dtlist, 0));
		        dtMETCYCLE.setText((String) Array.get(dtlist, 7));
		        dtPHASE.setText((String) Array.get(dtlist, 20));
		        dtDTCOMPL.setText((String) Array.get(dtlist, 43));
		        dtDTLASTSER.setText((String) Array.get(dtlist, 40));
		        dtSERVLBL.setText((String) Array.get(dtlist, 17));
		        dtDTNEXTDUE.setText((String) Array.get(dtlist, 41));
		        dtSTATUS.setText((String) Array.get(dtlist, 8));
		        dtONSITE.setText((String) Array.get(dtlist, 15));
		        dtSHOP.setText((String) Array.get(dtlist, 22));
		        dtWLNHRS.setText((String) Array.get(dtlist, 33));
		        dtCLASSSTD.setText((String) Array.get(dtlist, 23));
		        dtCALSTD.setText((String) Array.get(dtlist, 16));
	        
		        }
		     } 
		    }

	@Override
	public void tableChanged(TableModelEvent e) {
		if (!((ListSelectionModel) e).getValueIsAdjusting()) {
		int index = e.getFirstRow();
		model.setValueAt(Boolean.TRUE, index, 0);
		}
	} 

} //end SearchTest



class TransparentButton extends JButton {
	public TransparentButton(String text) { 
	    super(text);
	    final Color alphaZero = new Color(0, true);
	    setBackground(alphaZero);
	    setForeground(Color.black);
	    setOpaque(false); 
	    //setBorder(null);  
	    //setBorderPainted(false);    
	    setContentAreaFilled(true);     
	} 
	    
	public void paint(Graphics g) { 
	    Graphics2D g2 = (Graphics2D) g.create(); 
	    //g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); 
	    super.paint(g2); 
	    setForeground(Color.black);
	    g2.dispose(); 
	} 
}

	class CustomRenderer implements TableCellRenderer{
	    JLabel label;
	    int targetRow, targetCol;
	    final Color alphaZero = new Color(0, true);
	 
	    public CustomRenderer()
	    {
	        label = new JLabel();
	        label.setHorizontalAlignment(JLabel.CENTER);
	        label.setOpaque(true);
	        targetRow = -1;
	        targetCol = -1;
	    }

 
public Component getTableCellRendererComponent(JTable table,
                                                   Object value,
                                                   boolean isSelected,
                                                   boolean hasFocus,
                                                   int row, int column)
    {
        if(isSelected)
        {
            label.setBackground(alphaZero);
            label.setForeground(alphaZero);
            //label.setForeground(table.getSelectionForeground());
        }
        else
        {
            label.setBackground(alphaZero);
            label.setForeground(alphaZero);
            //label.setForeground(table.getForeground());
        }
        if(row == targetRow && column == targetCol)
        {
            label.setBorder(BorderFactory.createLineBorder(Color.red));
            label.setFont(table.getFont().deriveFont(Font.BOLD));
        }
        else
        {
            label.setBorder(null);
            label.setFont(table.getFont());
        }
        label.setText((String)value);
        return label;
    }

	public void setTargetRow(int row){
		targetRow = row;
	}
 
    public void setTargetCell(int row, int col)
    {
        targetRow = row;
        targetCol = col;
    }


    
}
	
	




Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 04 May 2012 - 01:29 PM

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 51
obviously you do not have a column 51
Try

		public Object getValueAt(int row, int col) {
			if(col == 0)
				return first.get(row);
			String line = al.get(row);
			String[] token = line.split(",");
			int actualCol = row - 1;
			System.out.println("Loking for col: " + actualCol + " Token length: " + token.length);
			if(actualCol >= token.length) {
				for(int i = 0; i < token.length; ++i)
					System.out.println(i + ") " + token[i]);
			}
			return token[actualCol];
		}


Then you will see if the error makes sense
Was This Post Helpful? 0
  • +
  • -

#7 Examiner12  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 89
  • Joined: 02-February 12

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 04 May 2012 - 02:17 PM

I looked at the source data and colNames: both have 51 columns. Im lost.

edit: I'm looking into this now. I'll post back when I have some resolution.

This post has been edited by Examiner12: 04 May 2012 - 03:08 PM

Was This Post Helpful? 0
  • +
  • -

#8 Examiner12  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 89
  • Joined: 02-February 12

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 04 May 2012 - 04:00 PM

OK. Getting much closer now. I have one remaining issue. In my GUI above the JTable, I have 6 Text Fields. A DocumentListener gets changes to the fields and applies a row filter on the table to filter what is displayed in the view to match the values in the fields.

JTextField svclabt;

        svclabt.getDocument().addDocumentListener
        (  
        		   new DocumentListener()  
        		   {
        			           			   
        		      public void changedUpdate(DocumentEvent e)  
        		      {   	       		    	 
        		    	  newFilter();  
        		      }  
        		      public void insertUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void removeUpdate(DocumentEvent e)  
        		      {  
        		         newFilter();  
        		      }  
        		   }  
        		);  



	 private void newFilter()  
	 {  
   	  //row = table.convertRowIndexToView(row);

		 List<RowFilter<TableModel,Object>> filters = new ArrayList<RowFilter<TableModel,Object>>();
		 RowFilter<TableModel, Object> compoundRowFilter = null;
		 try {
		     svclabf = RowFilter.regexFilter("^" + svclabt.getText(), 1);
		     custf = RowFilter.regexFilter("^" +custt.getText(), 2);
		     modf = RowFilter.regexFilter("^" +modt.getText(), 3);
		     serialf = RowFilter.regexFilter("^" +serialt.getText(), 4);
		     ecnf = RowFilter.regexFilter("^" +ecnt.getText(), 5);
		     subcustf = RowFilter.regexFilter("^" +subcustt.getText(), 7);
		     
		     filters.add(svclabf);
		     filters.add(custf);
		     filters.add(modf);
		     filters.add(serialf);
		     filters.add(ecnf);
		     filters.add(subcustf);
		     compoundRowFilter = RowFilter.andFilter(filters); // you may also choose the OR filter
		 } catch (java.util.regex.PatternSyntaxException e) {
		     return;
		 }
		 sorter.setRowFilter(compoundRowFilter); 		 
	 }  


Now when I enter anything in any one of the fields, I receieve:


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at PCQ.SearchTest.newFilter(SearchTest.java:600)
at PCQ.SearchTest.access$0(SearchTest.java:576)
at PCQ.SearchTest$3.insertUpdate(SearchTest.java:209)

full class:

//SEARCH TEST BACKUP - WITH HEAP SPACE ISSUE
package PCQ;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;



 
public class SearchTest implements ListSelectionListener, TableModelListener
{
//Main Table Object	
    JTable table;
    DefaultTableModel model;
    
    int selRows;
    int row;
    int row2;
	 RowFilter<TableModel, Object> svclabf = null;
	 RowFilter<TableModel, Object> custf = null;
	 RowFilter<TableModel, Object> modf = null;
	 RowFilter<TableModel, Object> serialf = null;
	 RowFilter<TableModel, Object> ecnf = null;
	 RowFilter<TableModel, Object> subcustf = null;
    
public TableRowSorter<TableModel> sorter ;  
    
//Search Field - Basic (Test)
    JTextField textField;
    
//Test Sorter Field
    
    JTextField svclabt;
    JTextField custt;
    JTextField modt;
    JTextField serialt;
    JTextField ecnt;
    JTextField subcustt;
    
    TransparentButton mcb = new TransparentButton("Get Meter Card(s)"); 
    TransparentButton metcb = new TransparentButton("Get MetCal Form(s)");

    
    
//Search Function - Complete
    
    JButton bs;
    JCheckBox cECN; 
    JCheckBox cCust;
    JCheckBox cMod;
    JCheckBox cSer;
    JCheckBox cNom;
    JCheckBox cSubCust;
    JTextField tECN;
    JTextField tCust;
    JTextField tMod;
    JTextField tSer;
    JTextField tNom;
    JTextField tSubCust;
    
//Text Fields for Detail Tab: Key Fields   
    JTextField dtECN;
    JTextField dtCust;
    JTextField dtMod;
    JTextField dtSer;
    JTextField dtNom;

//Text Fields for Detail Tab: Auxiliary Fields
    
    JTextField dtMFR;
    JTextField dtPARTOF;
    JTextField dtSUBCUST;
    JTextField dtSCHEDLAB;
    JTextField dtSCAT;
    JTextField dtNSN;
    JTextField dtPLANTACCT;
    JTextField dtAPPRPROC;
    JTextField dtSVCLAB;
    JTextField dtMETCYCLE;
    JTextField dtPHASE;
    JTextField dtDTCOMPL;
    JTextField dtDTLASTSER;
    JTextField dtSERVLBL;
    JTextField dtDTNEXTDUE;
    JTextField dtSTATUS;
    JTextField dtONSITE;
    JTextField dtSHOP;
    JTextField dtWLNHRS;
    JTextField dtCLASSSTD;
    JTextField dtCALSTD;
    
    

 
    public SearchTest() throws IOException 
    {
    	
    	
        table = getTable();
        table.setOpaque(false);
        
     //Search Function - Complete
        //Color bg = new Color(210, 222, 242);
        Color bg = new Color(224, 242, 252);
        bs = new JButton("  Search  ");
        mcb.setToolTipText("Get Meter Card(s) for Current PRINT Checkbox Selection");
        metcb.setToolTipText("Get MetCal Form(s) for Current PRINT Selection");
        svclabt = new JTextField(10); svclabt.setBackground(bg); svclabt.setToolTipText("Filter by Servicing Lab");
        custt = new JTextField(10); custt.setBackground(bg); custt.setToolTipText("Filter by Customer Code");
        modt= new JTextField(10); modt.setBackground(bg); modt.setToolTipText("Filter by Model Number");
        serialt = new JTextField(10); serialt.setBackground(bg); serialt.setToolTipText("Filter by Serial Number");
        ecnt = new JTextField(10); ecnt.setBackground(bg); ecnt.setToolTipText("Filter by Equipment Control Number");
        subcustt = new JTextField(10); subcustt.setBackground(bg); subcustt.setToolTipText("Filter by Sub Custodian");
        
        cECN = new JCheckBox("ECN:");
        cCust = new JCheckBox("CUSTOMER:");
        cMod = new JCheckBox("MODEL:");
        cSer = new JCheckBox("SERIAL:");
        cNom = new JCheckBox("NOMENCLATURE:");
        cSubCust = new JCheckBox("SUB CUSTODIAN:");
        tECN = new JTextField(10);
        tCust = new JTextField(10);
        tMod = new JTextField(10);
        tSer = new JTextField(10);
        tNom = new JTextField(10);
        tSubCust = new JTextField(10);
        
        
        textField = new JTextField();
        textField.setBackground(bg); 
        
//Detail Tab - Key Field Text Boxes   
                
        dtECN = new JTextField(15);	dtECN.setEditable(false);	dtECN.setBackground(bg); 
        dtCust = new JTextField(15);	dtCust.setEditable(false);	dtCust.setBackground(bg);
        dtMod = new JTextField(15);	dtMod.setEditable(false);	dtMod.setBackground(bg);
        dtSer = new JTextField(15);	dtSer.setEditable(false);	dtSer.setBackground(bg);
        dtNom = new JTextField(15);	dtNom.setEditable(false);	dtNom.setBackground(bg);

        
//Detail Tab - Auxiliary Field Text Boxes  
        dtMFR = new JTextField(15);    dtMFR.setEditable(false);    dtMFR.setBackground(bg);
        dtPARTOF = new JTextField(15);    dtPARTOF.setEditable(false);    dtPARTOF.setBackground(bg);
        dtSUBCUST = new JTextField(15);    dtSUBCUST.setEditable(false);    dtSUBCUST.setBackground(bg);
        dtSCHEDLAB = new JTextField(15);    dtSCHEDLAB.setEditable(false);    dtSCHEDLAB.setBackground(bg);
        dtSCAT = new JTextField(15);    dtSCAT.setEditable(false);    dtSCAT.setBackground(bg);
        dtNSN = new JTextField(15);    dtNSN.setEditable(false);    dtNSN.setBackground(bg);
        dtPLANTACCT = new JTextField(15);    dtPLANTACCT.setEditable(false);    dtPLANTACCT.setBackground(bg);
        dtAPPRPROC = new JTextField(15);    dtAPPRPROC.setEditable(false);    dtAPPRPROC.setBackground(bg);
        dtSVCLAB = new JTextField(15);    dtSVCLAB.setEditable(false);    dtSVCLAB.setBackground(bg);
        dtMETCYCLE = new JTextField(15);    dtMETCYCLE.setEditable(false);    dtMETCYCLE.setBackground(bg);
        dtPHASE = new JTextField(15);    dtPHASE.setEditable(false);    dtPHASE.setBackground(bg);
        dtDTCOMPL = new JTextField(15);    dtDTCOMPL.setEditable(false);    dtDTCOMPL.setBackground(bg);
        dtDTLASTSER = new JTextField(15);    dtDTLASTSER.setEditable(false);    dtDTLASTSER.setBackground(bg);
        dtSERVLBL = new JTextField(15);    dtSERVLBL.setEditable(false);    dtSERVLBL.setBackground(bg);
        dtDTNEXTDUE = new JTextField(15);    dtDTNEXTDUE.setEditable(false);    dtDTNEXTDUE.setBackground(bg);
        dtSTATUS = new JTextField(15);    dtSTATUS.setEditable(false);    dtSTATUS.setBackground(bg);
        dtONSITE = new JTextField(15);    dtONSITE.setEditable(false);    dtONSITE.setBackground(bg);
        dtSHOP = new JTextField(15);    dtSHOP.setEditable(false);    dtSHOP.setBackground(bg);
        dtWLNHRS = new JTextField(15);    dtWLNHRS.setEditable(false);    dtWLNHRS.setBackground(bg);
        dtCLASSSTD = new JTextField(15);    dtCLASSSTD.setEditable(false);    dtCLASSSTD.setBackground(bg);
        dtCALSTD = new JTextField(15);    dtCALSTD.setEditable(false);    dtCALSTD.setBackground(bg);
        

        textField.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                search();
            }
        });
        
        bs.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
            	table.repaint();
            	search2();
            }
        });
        
        svclabt.getDocument().addDocumentListener
        (  
        		   new DocumentListener()  
        		   {
        			           			   
        		      public void changedUpdate(DocumentEvent e)  
        		      {   	       		    	 
        		    	  newFilter();  
        		      }  
        		      public void insertUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void removeUpdate(DocumentEvent e)  
        		      {  
        		         newFilter();  
        		      }  
        		   }  
        		);  
        custt.getDocument().addDocumentListener
        (  
        		   new DocumentListener()  
        		   {  
        		      public void changedUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void insertUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void removeUpdate(DocumentEvent e)  
        		      {  
        		         newFilter();  
        		      }  
        		   }  
        		); 
        modt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        serialt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        ecnt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        subcustt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		);     
    mcb.addActionListener(new ActionListener()
        {
        public void actionPerformed(ActionEvent e)
        {
                 returnReportData();
               }
        });
     
    metcb.addActionListener(new ActionListener()
        {
        public void actionPerformed(ActionEvent e)
        {
                 returnReportData();
               }
        });
        
        
        
    }
 
//Get the JTable and return it    
	JTable getTable() throws IOException    { 

		File f = new File("C:\\PCQ\\A_R4.csv");
		Scanner s = new Scanner(f);

		String[] colNames = { 
				"PRINT",
				"SERVICED_LAB",
				"CUSTOMER_ID",
				"MODEL_NO",
				"SERIAL_NO",
				"ECN",
				"NOMENCLATURE",
				"SUB_CUSTODIAN",
				"METRL_CYCLE",
				"MFR_CD",
				"UIC",
				"SCHED_LAB",
				"PROCEDURE_USED",
				"VALUE_FIXED",
				"NSN",
				"PART_OF",
				"ON_SITE_SERVICE",
				"CAL_STD",
				"SERVICE_LABEL_CD",
				"PLANT_ACCT",
				"SCAT_CD",
				"PHASE_ID",
				"APPROVED_PROCEDURE",
				"INV_SHOP_NO",
				"CLASS_STD",
				"TYPE_STD",
				"WIP_STATUS",
				"EQPMT_TYPE_CD",
				"ICN",
				"PRINT_METERCARD_FLG",
				"EQPMT_STATUS_CD",
				"DELAY_REASON_CD",
				"EQPMT_STATUS_CD",
				"SPCL_INSTR_CD",
				"WORKLOAD_NORM_HRS",
				"METRL_CYCLE",
				"DT_SYS",
				"DT_RCVD",
				"DT_INDUCT",
				"DT_DELAY",
				"DT_REPTD",
				"DT_LSTCAL",
				"DT_NXT_DUE",
				"DT_RECALL",
				"DT_CMPL",
				"DT_CREATE",
				"COST",
				"CAT_CUS",
				"CAT_LAB",
				"LAB_TYPE",
				"ACC_CODE",
				"FLAG_OFFLN"//,
				//"DT_REIND"



		};  

		LineNumberReader  lnr = new LineNumberReader(new FileReader(f)); 
		lnr.skip(Long.MAX_VALUE); 
		int ln = lnr.getLineNumber();
		
		//Import CSV File into 2d array   	  
		ArrayList<String> al = new ArrayList<String>(ln);
		int c = 0;
		while (c < ln ) {         
			al.add(s.nextLine()); 
			c++;
		}     

		MyModel model = new MyModel(colNames, al);
		final JTable table =  new JTable(model){   		
    		public boolean isCellEditable(int rowIndex, int mColIndex) {
    			if(mColIndex > 0){
    			return false;
    			} 
    			else return true;
    		}
    	public Class getColumnClass(int col) {
    	Object o = getValueAt(0, col);     
    	if(o == null){                 
    		return Object.class;   
    		}
    	else     {         
    		return o.getClass();   
    			}
    		} 
    	final Color alphaZero = new Color(0, true);
		public Component prepareRenderer(TableCellRenderer renderer,
				int rowIndex, int vColIndex) {
			setOpaque(false);
			Component c = super.prepareRenderer(renderer, rowIndex,
				vColIndex);
				if (isCellSelected(rowIndex, vColIndex)) {
					if (rowIndex % 2 == 0) {
						//c.setBackground(Color.LIGHT_GRAY );
						
						c.setBackground(alphaZero);
						
					} else {
						//c.setBackground(getSelectionBackground());
						c.setBackground(alphaZero);
					}
				} else {
				if (rowIndex % 2 == 0) {
					//c.setBackground(new Color(224, 242, 252));
					c.setBackground(alphaZero);
					} else {
						//c.setBackground(getBackground());
						c.setBackground(alphaZero);
						}
					};

				return c;
				}
    	};
    	
    	table.getModel().addTableModelListener(new TableModelListener() {
			public void tableChanged(TableModelEvent e) {
		        int row2 = e.getFirstRow();
		        int column = e.getColumn();        
		        int columns = e.ALL_COLUMNS;
		        TableModel model = (TableModel)e.getSource();
		        String columnName = model.getColumnName(column);
		        Object data = model.getValueAt(row2, column);		      
		        Boolean val = getCBValueAt(row2, column);
				
				System.out.println(row2);
				System.out.println(column);
				System.out.println(val);
		    }

			private Boolean getCBValueAt(int row, int column) {
		    	  return (Boolean) table.getModel().getValueAt(row, column);
			} } 
	);
    	
		table.setOpaque(false);
		table.convertRowIndexToView(row);
		table.setModel(model);
		table.getTableHeader().setBackground(new Color(174, 201, 230));
		table.getTableHeader().setFont(new Font("SansSerif", Font.BOLD, 12));
		table.setRowSorter(sorter);  
		table.setAutoCreateRowSorter(true);
    	//table.setDefaultRenderer(String.class, new CustomRenderer());
    	table.setRowSelectionAllowed(true);       
    	table.setColumnSelectionAllowed(true);     
    	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	    ListSelectionModel listMod =  table.getSelectionModel();
	    listMod.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	    listMod.addListSelectionListener(this);
	    
	    
    	return table;
	}
	
// my tableModel as an inner class
	class MyModel extends AbstractTableModel {
		String[] colName;
		ArrayList<String> al;
		ArrayList<Boolean> first;

		MyModel(String[] colName, ArrayList<String> al) {
			this.colName = colName;
			this.al = al;
			first = new ArrayList<Boolean>(al.size());
			for(int i = 0; i < al.size(); ++i)
				first.add(Boolean.valueOf(false));
		}

		@Override
		public int getColumnCount() {
			return colName.length;
		}
		public String getColumnName(int col) {
			return colName[col];
		}

		@Override
		public int getRowCount() {
			return al.size();
		}

		@Override
		public Object getValueAt(int row, int col) {
			if(col == 0)
				return first.get(row);
			String line = al.get(row).replace("\"", "");
			String[] token = line.split(",");
			return token[col-1];
		}
		
		public void setValueAt(Object o, int row, int col) {
			// first col is the boolean
			if(col == 0) {
				first.set(row, (Boolean) o);
				return;
			}
			// other col
			String line = al.get(row);
			String[] token = line.split(",");
			token[row-1] = (String) o;         			// replace with new one												
			StringBuilder sb = new StringBuilder(); 	// rebuild the String
			for(int i = 0; i < token.length - 1; ++i)
				sb.append(token[i]).append(',');   		// with the comma
			sb.append(token[token.length-1]);     		// but for the last one
			al.set(row, sb.toString());           		// replace in ArrayList
		}
		
		
		
		
	}
    
    
    
//Search method
	 void search()
	    {
		 
	        String target = textField.getText();
	        for(int row = 1; row < table.getRowCount(); row++)
	            for(int col = 1; col < table.getColumnCount() -1 ; col++)
	            {
	                String next = (String)table.getValueAt(row, col);
	                if(next.equals(target))
	                {
	                    showSearchResults(row, col);
	                    return;
	                }
	            }
	 
// reset table display after failed search> target null/not found <
	        CustomRenderer renderer =
	                (CustomRenderer)table.getDefaultRenderer(String.class);
	        renderer.setTargetCell(-1, -1);
	        table.repaint();
	    }
	 
	 private void newFilter()  
	 {  
   	  //row = table.convertRowIndexToView(row);

		 List<RowFilter<TableModel,Object>> filters = new ArrayList<RowFilter<TableModel,Object>>();
		 RowFilter<TableModel, Object> compoundRowFilter = null;
		 try {
		     svclabf = RowFilter.regexFilter("^" + svclabt.getText(), 1);
		     custf = RowFilter.regexFilter("^" +custt.getText(), 2);
		     modf = RowFilter.regexFilter("^" +modt.getText(), 3);
		     serialf = RowFilter.regexFilter("^" +serialt.getText(), 4);
		     ecnf = RowFilter.regexFilter("^" +ecnt.getText(), 5);
		     subcustf = RowFilter.regexFilter("^" +subcustt.getText(), 7);
		     
		     filters.add(svclabf);
		     filters.add(custf);
		     filters.add(modf);
		     filters.add(serialf);
		     filters.add(ecnf);
		     filters.add(subcustf);
		     compoundRowFilter = RowFilter.andFilter(filters); // you may also choose the OR filter
		 } catch (java.util.regex.PatternSyntaxException e) {
		     return;
		 }
		 sorter.setRowFilter(compoundRowFilter); 		 
	 }  
 
	 void search2(){
		 
// reset table display after failed search		   
	      CustomRenderer renderer = (CustomRenderer)table.getDefaultRenderer(String.class);
	      renderer.setTargetCell(-1, -1);
	      table.repaint();
		
		 String [] searchlist = new String[6];
		 Boolean match; //use as toggle for search decision tree?
		 String sECN = null; Boolean Ec = true;
		 String sCust = null; Boolean Cc = true;
		 String sMod = null; Boolean Mc = true;
		 String sSer = null; Boolean  Sc = true;
		 String sNom = null; Boolean Nc = true;
		 String sSubCust = null; Boolean Scc = true;		 
		 
//Only get Text Field value if Check box is checked		 
		 if (cECN.isSelected()){
			 sECN = tECN.getText();
		 } else if(!cECN.isSelected()) {sECN = null;}; //if needed, catch null exception so "" won't be passed to search list? -- causes null pointer exception
		 if (cCust.isSelected()){
			 sCust = tCust.getText();
		 } 
		 if (cMod.isSelected()){
			 sMod = tMod.getText();
		 }
		 if (cSer.isSelected()){
			 sSer = tSer.getText();
		 }
		 if (cNom.isSelected()){
			 sNom = tNom.getText();
		 }
		 if (cSubCust.isSelected()){
			 sSubCust = tSubCust.getText();
		 }
//After assigning String values from text fields based on check box confirmation, fill an array list with values
		searchlist[0] = sECN;
		searchlist[1] = sCust;
		searchlist[2] = sMod;
		searchlist[3] = sSer;
		searchlist[4] = sNom;
		searchlist[5] = sSubCust;		

//Need: array to hold table row values
  Object[] tbrowdata = new Object[8];
  TableModel tb = table.getModel();
  Object val;
  int selectedRow;
  
  for(int r = 0; r < table.getRowCount(); r++){ 
	  selectedRow = r;
	  
  for (int i= 1; i < 8 ; i++) {
	  val = tb.getValueAt(r, i);
	  tbrowdata [i-1] = val;
   
  		}
  if(
	 ((tbrowdata[4].equals(searchlist[0])) || searchlist[0] == null) &&
	 ((tbrowdata[1].equals(searchlist[1])) || searchlist[1] == null) &&
	 ((tbrowdata[2].equals(searchlist[2])) || searchlist[2] == null) &&
	 ((tbrowdata[3].equals(searchlist[3])) || searchlist[3] == null) &&
	 ((tbrowdata[5].equals(searchlist[4])) || searchlist[4] == null) &&
	 ((tbrowdata[6].equals(searchlist[5])) || searchlist[5] == null) 
	  
	){
	  showSearchResults(r, 5);
  	}

  }
  
//test print values from GUI Text Fields when respective Check box is checked
		 /*
  		 System.out.println(searchlist[0]);
		 System.out.println(searchlist[1]);
		 System.out.println(sMod);
		 System.out.println(sSer);
		 System.out.println(sNom);
		 System.out.println(sSubCust);
	 	*/
	 }
	 
//returnReportData 	 
	 public Object[][] returnReportData(){
		 
		 TableModel tm2 = table.getModel();
//Get count of rows with Print Box checked (counter = z) to initialize the reportData Object[][] 
		 int z = 0; 		 
		 for(int x = 0; x < tm2.getRowCount(); x++){
			 if(((Boolean)tm2.getValueAt(x, 0)) == true){
				  z++;				  				  
			 }
		 }
//Initialize Object[][]	reportData and store dimensions as tRow and tCol	 		 			 
		 int nRow = tm2.getRowCount(), nCol = tm2.getColumnCount();
		 Object[][] reportData = new Object[z][54];  
		 int tRow = reportData.length, tCol = reportData[0].length;

//Populate reportData with table model data where Checkbox = Boolean.TRUE				 
		 int index = 0;
		 for (int i = 0 ; i < nRow ; i++){
		     if(((Boolean)tm2.getValueAt(i, 0)) == true){
		         for (int j = 1 ; j < nCol ; j++){   
		              reportData[index][j] = tm2.getValueAt(i,j);  
		         }
		         ++index;
		     }
		 }
		 
//Test print reportData in rectangular form
		 int ROWS = reportData.length;
		 int COLS = reportData[0].length;
		 for (int L = 0; L < ROWS; L++) {
			 for (int M = 0; M < COLS; M++) {
				System.out.print(" " + reportData[L][M]);
		 }
		 System.out.println("");
		 }
		return reportData;		 	 
	}		 
 
//Show the search results using Custom Renderer 
		private void showSearchResults(int row, int col)
		    {
				//table.repaint();
		        CustomRenderer renderer = (CustomRenderer)table.getCellRenderer(row, col);
		        renderer.setTargetCell(row, col);
		        Rectangle r = table.getCellRect(row, col, false);
		        table.scrollRectToVisible(r);
				table.repaint();

		    }

//Main method for test purposes		
		public void main(String[] args) throws IOException
		    {
		        SearchTest test = new SearchTest();
		        JFrame f = new JFrame("-JQuery V_0.1 Beta-");
		        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
				Container cP = f.getContentPane(); 
		
				f.getContentPane().add(new JTabbedPane());
		        f.getContentPane().add(new JScrollPane(test.table));
		        f.getContentPane().add(test.textField, "North");
		        f.setSize(600,400);
		        f.setLocationRelativeTo(null);
		        f.setVisible(true);
		        test.textField.requestFocusInWindow();
		
		    }

		

		
//Mouse Event Listener for Row Selection into Detail Tab		
	Object o;
	Object[] dtlist = new Object[52];
	public void valueChanged(ListSelectionEvent e) {
		   Object value;
		   if (!e.getValueIsAdjusting()) {       	
		     selRows = table.getSelectedRow();
		     row = selRows;		     
		     
// get Table data
		     TableModel tm = table.getModel();
		     if (row > -1) {
		    	 row = table.convertRowIndexToModel(row);
		        for (int i= 1; i < 52 ; i++) {
		          value = tm.getValueAt(row,i);
		          dtlist[i-1]  = value;

		          }
//get test value in array dtlist
		        o = Array.get(dtlist, 1);
		        //System.out.println(selRows);
		        //System.out.println(row);
		        //Key Fields
		        dtECN.setText((String) Array.get(dtlist, 4));
		        dtCust.setText((String) Array.get(dtlist, 1));
		        dtMod.setText((String) Array.get(dtlist, 2));
		        dtSer.setText((String) Array.get(dtlist, 3));
		        dtNom.setText((String) Array.get(dtlist, 5));
		        
		        //Auxiliary Fields
		        dtMFR.setText((String) Array.get(dtlist, 8));
		        dtPARTOF.setText((String) Array.get(dtlist, 14));
		        dtSUBCUST.setText((String) Array.get(dtlist, 6));
		        dtSCHEDLAB.setText((String) Array.get(dtlist, 10));
		        dtSCAT.setText((String) Array.get(dtlist, 19));
		        dtNSN.setText((String) Array.get(dtlist, 13));
		        dtPLANTACCT.setText((String) Array.get(dtlist, 18));
		        dtAPPRPROC.setText((String) Array.get(dtlist, 21));
		        dtSVCLAB.setText((String) Array.get(dtlist, 0));
		        dtMETCYCLE.setText((String) Array.get(dtlist, 7));
		        dtPHASE.setText((String) Array.get(dtlist, 20));
		        dtDTCOMPL.setText((String) Array.get(dtlist, 43));
		        dtDTLASTSER.setText((String) Array.get(dtlist, 40));
		        dtSERVLBL.setText((String) Array.get(dtlist, 17));
		        dtDTNEXTDUE.setText((String) Array.get(dtlist, 41));
		        dtSTATUS.setText((String) Array.get(dtlist, 8));
		        dtONSITE.setText((String) Array.get(dtlist, 15));
		        dtSHOP.setText((String) Array.get(dtlist, 22));
		        dtWLNHRS.setText((String) Array.get(dtlist, 33));
		        dtCLASSSTD.setText((String) Array.get(dtlist, 23));
		        dtCALSTD.setText((String) Array.get(dtlist, 16));
	        
		        }
		     } 
		    }

	@Override
	public void tableChanged(TableModelEvent e) {
		if (!((ListSelectionModel) e).getValueIsAdjusting()) {
		int index = e.getFirstRow();
		model.setValueAt(Boolean.TRUE, index, 0);
		}
	} 

} //end SearchTest



class TransparentButton extends JButton {
	public TransparentButton(String text) { 
	    super(text);
	    final Color alphaZero = new Color(0, true);
	    setBackground(alphaZero);
	    setForeground(Color.black);
	    setOpaque(false); 
	    //setBorder(null);  
	    //setBorderPainted(false);    
	    setContentAreaFilled(true);     
	} 
	    
	public void paint(Graphics g) { 
	    Graphics2D g2 = (Graphics2D) g.create(); 
	    //g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); 
	    super.paint(g2); 
	    setForeground(Color.black);
	    g2.dispose(); 
	} 
}

	class CustomRenderer implements TableCellRenderer{
	    JLabel label;
	    int targetRow, targetCol;
	    final Color alphaZero = new Color(0, true);
	 
	    public CustomRenderer()
	    {
	        label = new JLabel();
	        label.setHorizontalAlignment(JLabel.CENTER);
	        label.setOpaque(true);
	        targetRow = -1;
	        targetCol = -1;
	    }

 
public Component getTableCellRendererComponent(JTable table,
                                                   Object value,
                                                   boolean isSelected,
                                                   boolean hasFocus,
                                                   int row, int column)
    {
        if(isSelected)
        {
            label.setBackground(alphaZero);
            label.setForeground(alphaZero);
        }
        else
        {
            label.setBackground(alphaZero);
            label.setForeground(alphaZero);
        }
        if(row == targetRow && column == targetCol)
        {
            label.setBorder(BorderFactory.createLineBorder(Color.red));
            label.setFont(table.getFont().deriveFont(Font.BOLD));
        }
        else
        {
            label.setBorder(null);
            label.setFont(table.getFont());
        }
        label.setText((String)value);
        return label;
    }

	public void setTargetRow(int row){
		targetRow = row;
	}
 
    public void setTargetCell(int row, int col)
    {
        targetRow = row;
        targetCol = col;
    }


    
}
	
	




Is this due to changing the table model from defalut to AbstractTableModel? This is the last hurdle!

This post has been edited by Examiner12: 04 May 2012 - 04:39 PM

Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 04 May 2012 - 07:11 PM

View PostExaminer12, on 04 May 2012 - 07:00 PM, said:

Is this due to changing the table model from defalut to AbstractTableModel? This is the last hurdle!

I doubt, and you probably didn't post your code correctly. Line 600 is

void search2(){

you can''t have a nullPointerException there
Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 05 May 2012 - 10:47 AM

Performance improvment :)

Just thinking of it. When the GUI will refresh the JTable while scolling it will call the getValueAt() of each displayed row and column. There is no need to perform the split(",") more than once for the same line. So a good idea will be to cache the last splitted line :^:

	class MyModel extends AbstractTableModel {
		String[] colName;
		ArrayList<String> al;
		ArrayList<Boolean> first;
		int lastAccessed ;           // <--- remember last one accessed
		String[] token;              // the last split

		MyModel(String[] colName, ArrayList<String> al) {
			this.colName = colName;
			this.al = al;
			first = new ArrayList<Boolean>(al.size());
			for(int i = 0; i < al.size(); ++i)
				first.add(Boolean.valueOf(false));
			lastAccessed = -1;                     // set to impossible value
		}

		@Override
		public Object getValueAt(int row, int col) {
			if(col == 0)
				return first.get(row);
			// split only if required
			if(row != lastAccessed) {
			   String line = al.get(row);
			   token = line.split(",");
			   lastAccessed = row;
			}
			return token[col-1];
		}
		public void setValueAt(Object o, int row, int col) {
			// first col is the boolean
			if(col == 0) {
				first.set(row, (Boolean) o);
				return;
			}
			// other col
			if(row != lastAccessed) {
			   String line = al.get(row);
			   token = line.split(",");
			   lastAccessed = row;
			}
			token[row-1] = (String) o;         // replace with new one
			// rebuid the String
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < token.length - 1; ++i)
				sb.append(token[i]).append(',');   // with the coma
			sb.append(token[token.length-1]);     // but for the last one
			al.set(row, sb.toString());           // replace in ArrayList
		}



Have fun
Was This Post Helpful? 0
  • +
  • -

#11 Examiner12  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 89
  • Joined: 02-February 12

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 05 May 2012 - 12:01 PM

Many thanks pbl. I don't have access to my work machine this weekend, but your suggestions have clarified lots. I'll report back on monday! As always, you're a lifesaver!
Was This Post Helpful? 0
  • +
  • -

#12 Examiner12  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 89
  • Joined: 02-February 12

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 07 May 2012 - 11:12 AM

Ok, it's Monday and I'm back at it!

Regarding the rowfilter, I did post my code wrong. The error is with "sorter.setRowFilter(compoundRowFilter); "

I'm trying to grasp why it's encountering a NULL Pointer Exception. This filter worked perfect before implementing the Abstract Table Model.


//SEARCH TEST BACKUP - WITH HEAP SPACE ISSUE
package PCQ;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;



 
public class SearchTest implements ListSelectionListener, TableModelListener
{
//Main Table Object	
    JTable table;
    DefaultTableModel model;
    
    int selRows;
    int row;
    int row2;
	 RowFilter<TableModel, Object> svclabf = null;
	 RowFilter<TableModel, Object> custf = null;
	 RowFilter<TableModel, Object> modf = null;
	 RowFilter<TableModel, Object> serialf = null;
	 RowFilter<TableModel, Object> ecnf = null;
	 RowFilter<TableModel, Object> subcustf = null;
    
public TableRowSorter<TableModel> sorter ;  
    
//Search Field - Basic (Test)
    JTextField textField;
    
//Test Sorter Field
    
    JTextField svclabt;
    JTextField custt;
    JTextField modt;
    JTextField serialt;
    JTextField ecnt;
    JTextField subcustt;
    
    TransparentButton mcb = new TransparentButton("Get Meter Card(s)"); 
    TransparentButton metcb = new TransparentButton("Get MetCal Form(s)");

    
    
//Search Function - Complete
    
    JButton bs;
    JCheckBox cECN; 
    JCheckBox cCust;
    JCheckBox cMod;
    JCheckBox cSer;
    JCheckBox cNom;
    JCheckBox cSubCust;
    JTextField tECN;
    JTextField tCust;
    JTextField tMod;
    JTextField tSer;
    JTextField tNom;
    JTextField tSubCust;
    
//Text Fields for Detail Tab: Key Fields   
    JTextField dtECN;
    JTextField dtCust;
    JTextField dtMod;
    JTextField dtSer;
    JTextField dtNom;

//Text Fields for Detail Tab: Auxiliary Fields
    
    JTextField dtMFR;
    JTextField dtPARTOF;
    JTextField dtSUBCUST;
    JTextField dtSCHEDLAB;
    JTextField dtSCAT;
    JTextField dtNSN;
    JTextField dtPLANTACCT;
    JTextField dtAPPRPROC;
    JTextField dtSVCLAB;
    JTextField dtMETCYCLE;
    JTextField dtPHASE;
    JTextField dtDTCOMPL;
    JTextField dtDTLASTSER;
    JTextField dtSERVLBL;
    JTextField dtDTNEXTDUE;
    JTextField dtSTATUS;
    JTextField dtONSITE;
    JTextField dtSHOP;
    JTextField dtWLNHRS;
    JTextField dtCLASSSTD;
    JTextField dtCALSTD;
    
    

 
    public SearchTest() throws IOException 
    {
    	
    	
        table = getTable();
        table.setOpaque(false);
        
     //Search Function - Complete
        //Color bg = new Color(210, 222, 242);
        Color bg = new Color(224, 242, 252);
        bs = new JButton("  Search  ");
        mcb.setToolTipText("Get Meter Card(s) for Current PRINT Checkbox Selection");
        metcb.setToolTipText("Get MetCal Form(s) for Current PRINT Selection");
        svclabt = new JTextField(10); svclabt.setBackground(bg); svclabt.setToolTipText("Filter by Servicing Lab");
        custt = new JTextField(10); custt.setBackground(bg); custt.setToolTipText("Filter by Customer Code");
        modt= new JTextField(10); modt.setBackground(bg); modt.setToolTipText("Filter by Model Number");
        serialt = new JTextField(10); serialt.setBackground(bg); serialt.setToolTipText("Filter by Serial Number");
        ecnt = new JTextField(10); ecnt.setBackground(bg); ecnt.setToolTipText("Filter by Equipment Control Number");
        subcustt = new JTextField(10); subcustt.setBackground(bg); subcustt.setToolTipText("Filter by Sub Custodian");
        
        cECN = new JCheckBox("ECN:");
        cCust = new JCheckBox("CUSTOMER:");
        cMod = new JCheckBox("MODEL:");
        cSer = new JCheckBox("SERIAL:");
        cNom = new JCheckBox("NOMENCLATURE:");
        cSubCust = new JCheckBox("SUB CUSTODIAN:");
        tECN = new JTextField(10);
        tCust = new JTextField(10);
        tMod = new JTextField(10);
        tSer = new JTextField(10);
        tNom = new JTextField(10);
        tSubCust = new JTextField(10);
        
        
        textField = new JTextField();
        textField.setBackground(bg); 
        
//Detail Tab - Key Field Text Boxes   
                
        dtECN = new JTextField(15);	dtECN.setEditable(false);	dtECN.setBackground(bg); 
        dtCust = new JTextField(15);	dtCust.setEditable(false);	dtCust.setBackground(bg);
        dtMod = new JTextField(15);	dtMod.setEditable(false);	dtMod.setBackground(bg);
        dtSer = new JTextField(15);	dtSer.setEditable(false);	dtSer.setBackground(bg);
        dtNom = new JTextField(15);	dtNom.setEditable(false);	dtNom.setBackground(bg);

        
//Detail Tab - Auxiliary Field Text Boxes  
        dtMFR = new JTextField(15);    dtMFR.setEditable(false);    dtMFR.setBackground(bg);
        dtPARTOF = new JTextField(15);    dtPARTOF.setEditable(false);    dtPARTOF.setBackground(bg);
        dtSUBCUST = new JTextField(15);    dtSUBCUST.setEditable(false);    dtSUBCUST.setBackground(bg);
        dtSCHEDLAB = new JTextField(15);    dtSCHEDLAB.setEditable(false);    dtSCHEDLAB.setBackground(bg);
        dtSCAT = new JTextField(15);    dtSCAT.setEditable(false);    dtSCAT.setBackground(bg);
        dtNSN = new JTextField(15);    dtNSN.setEditable(false);    dtNSN.setBackground(bg);
        dtPLANTACCT = new JTextField(15);    dtPLANTACCT.setEditable(false);    dtPLANTACCT.setBackground(bg);
        dtAPPRPROC = new JTextField(15);    dtAPPRPROC.setEditable(false);    dtAPPRPROC.setBackground(bg);
        dtSVCLAB = new JTextField(15);    dtSVCLAB.setEditable(false);    dtSVCLAB.setBackground(bg);
        dtMETCYCLE = new JTextField(15);    dtMETCYCLE.setEditable(false);    dtMETCYCLE.setBackground(bg);
        dtPHASE = new JTextField(15);    dtPHASE.setEditable(false);    dtPHASE.setBackground(bg);
        dtDTCOMPL = new JTextField(15);    dtDTCOMPL.setEditable(false);    dtDTCOMPL.setBackground(bg);
        dtDTLASTSER = new JTextField(15);    dtDTLASTSER.setEditable(false);    dtDTLASTSER.setBackground(bg);
        dtSERVLBL = new JTextField(15);    dtSERVLBL.setEditable(false);    dtSERVLBL.setBackground(bg);
        dtDTNEXTDUE = new JTextField(15);    dtDTNEXTDUE.setEditable(false);    dtDTNEXTDUE.setBackground(bg);
        dtSTATUS = new JTextField(15);    dtSTATUS.setEditable(false);    dtSTATUS.setBackground(bg);
        dtONSITE = new JTextField(15);    dtONSITE.setEditable(false);    dtONSITE.setBackground(bg);
        dtSHOP = new JTextField(15);    dtSHOP.setEditable(false);    dtSHOP.setBackground(bg);
        dtWLNHRS = new JTextField(15);    dtWLNHRS.setEditable(false);    dtWLNHRS.setBackground(bg);
        dtCLASSSTD = new JTextField(15);    dtCLASSSTD.setEditable(false);    dtCLASSSTD.setBackground(bg);
        dtCALSTD = new JTextField(15);    dtCALSTD.setEditable(false);    dtCALSTD.setBackground(bg);
        

        textField.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                search();
            }
        });
        
        bs.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
            	table.repaint();
            	search2();
            }
        });
        
        svclabt.getDocument().addDocumentListener
        (  
        		   new DocumentListener()  
        		   {
        			           			   
        		      public void changedUpdate(DocumentEvent e)  
        		      {   	       		    	 
        		    	  newFilter();  
        		      }  
        		      public void insertUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void removeUpdate(DocumentEvent e)  
        		      {  
        		         newFilter();  
        		      }  
        		   }  
        		);  
        custt.getDocument().addDocumentListener
        (  
        		   new DocumentListener()  
        		   {  
        		      public void changedUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void insertUpdate(DocumentEvent e)  
        		      {  
        		          newFilter();  
        		      }  
        		      public void removeUpdate(DocumentEvent e)  
        		      {  
        		         newFilter();  
        		      }  
        		   }  
        		); 
        modt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        serialt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        ecnt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		); 
        subcustt.getDocument().addDocumentListener
        (  
     		   new DocumentListener()  
     		   {  
     		      public void changedUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void insertUpdate(DocumentEvent e)  
     		      {  
     		          newFilter();  
     		      }  
     		      public void removeUpdate(DocumentEvent e)  
     		      {  
     		         newFilter();  
     		      }  
     		   }  
     		);     
    mcb.addActionListener(new ActionListener()
        {
        public void actionPerformed(ActionEvent e)
        {
                 returnReportData();
               }
        });
     
    metcb.addActionListener(new ActionListener()
        {
        public void actionPerformed(ActionEvent e)
        {
                 returnReportData();
               }
        });
        
        
        
    }
 
//Get the JTable and return it    
	JTable getTable() throws IOException    { 

		File f = new File("C:\\PCQ\\A_R4.csv");
		Scanner s = new Scanner(f);

		String[] colNames = { 
				"PRINT",
				"SERVICED_LAB",
				"CUSTOMER_ID",
				"MODEL_NO",
				"SERIAL_NO",
				"ECN",
				"NOMENCLATURE",
				"SUB_CUSTODIAN",
				"METRL_CYCLE",
				"MFR_CD",
				"UIC",
				"SCHED_LAB",
				"PROCEDURE_USED",
				"VALUE_FIXED",
				"NSN",
				"PART_OF",
				"ON_SITE_SERVICE",
				"CAL_STD",
				"SERVICE_LABEL_CD",
				"PLANT_ACCT",
				"SCAT_CD",
				"PHASE_ID",
				"APPROVED_PROCEDURE",
				"INV_SHOP_NO",
				"CLASS_STD",
				"TYPE_STD",
				"WIP_STATUS",
				"EQPMT_TYPE_CD",
				"ICN",
				"PRINT_METERCARD_FLG",
				"EQPMT_STATUS_CD",
				"DELAY_REASON_CD",
				"EQPMT_STATUS_CD",
				"SPCL_INSTR_CD",
				"WORKLOAD_NORM_HRS",
				"METRL_CYCLE",
				"DT_SYS",
				"DT_RCVD",
				"DT_INDUCT",
				"DT_DELAY",
				"DT_REPTD",
				"DT_LSTCAL",
				"DT_NXT_DUE",
				"DT_RECALL",
				"DT_CMPL",
				"DT_CREATE",
				"COST",
				"CAT_CUS",
				"CAT_LAB",
				"LAB_TYPE",
				"ACC_CODE",
				"FLAG_OFFLN"//,
				//"DT_REIND"



		};  

		LineNumberReader  lnr = new LineNumberReader(new FileReader(f)); 
		lnr.skip(Long.MAX_VALUE); 
		int ln = lnr.getLineNumber();
		
		//Import CSV File into 2d array   	  
		ArrayList<String> al = new ArrayList<String>(ln);
		int c = 0;
		while (c < ln ) {         
			al.add(s.nextLine()); 
			c++;
		}     

		MyModel model = new MyModel(colNames, al);
		final JTable table =  new JTable(model){   		
    		public boolean isCellEditable(int rowIndex, int mColIndex) {
    			if(mColIndex > 0){
    			return false;
    			} 
    			else return true;
    		}
    	public Class getColumnClass(int col) {
    	Object o = getValueAt(0, col);     
    	if(o == null){                 
    		return Object.class;   
    		}
    	else     {         
    		return o.getClass();   
    			}
    		} 
    	final Color alphaZero = new Color(0, true);
		public Component prepareRenderer(TableCellRenderer renderer,
				int rowIndex, int vColIndex) {
			setOpaque(false);
			Component c = super.prepareRenderer(renderer, rowIndex,
				vColIndex);
				if (isCellSelected(rowIndex, vColIndex)) {
					if (rowIndex % 2 == 0) {
						//c.setBackground(Color.LIGHT_GRAY );
						
						c.setBackground(alphaZero);
						
					} else {
						//c.setBackground(getSelectionBackground());
						c.setBackground(alphaZero);
					}
				} else {
				if (rowIndex % 2 == 0) {
					//c.setBackground(new Color(224, 242, 252));
					c.setBackground(alphaZero);
					} else {
						//c.setBackground(getBackground());
						c.setBackground(alphaZero);
						}
					};

				return c;
				}
    	};
    	
    	table.getModel().addTableModelListener(new TableModelListener() {
			public void tableChanged(TableModelEvent e) {
		        int row2 = e.getFirstRow();
		        int column = e.getColumn();        
		        int columns = e.ALL_COLUMNS;
		        TableModel model = (TableModel)e.getSource();
		        String columnName = model.getColumnName(column);
		        Object data = model.getValueAt(row2, column);		      
		        Boolean val = getCBValueAt(row2, column);
				
				System.out.println(row2);
				System.out.println(column);
				System.out.println(val);
		    }

			private Boolean getCBValueAt(int row, int column) {
		    	  return (Boolean) table.getModel().getValueAt(row, column);
			} } 
	);
    	
		table.setOpaque(false);
		table.convertRowIndexToView(row);
		table.setModel(model);
		table.getTableHeader().setBackground(new Color(174, 201, 230));
		table.getTableHeader().setFont(new Font("SansSerif", Font.BOLD, 12));
		table.setRowSorter(sorter);  
		table.setAutoCreateRowSorter(true);
    	//table.setDefaultRenderer(String.class, new CustomRenderer());
    	table.setRowSelectionAllowed(true);       
    	table.setColumnSelectionAllowed(true);     
    	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	    ListSelectionModel listMod =  table.getSelectionModel();
	    listMod.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	    listMod.addListSelectionListener(this);
	    
	    
    	return table;
	}
	
// my tableModel as an inner class
	class MyModel extends AbstractTableModel {
		String[] colName;
		ArrayList<String> al;
		ArrayList<Boolean> first;

		MyModel(String[] colName, ArrayList<String> al) {
			this.colName = colName;
			this.al = al;
			first = new ArrayList<Boolean>(al.size());
			for(int i = 0; i < al.size(); ++i)
				first.add(Boolean.valueOf(false));
		}

		@Override
		public int getColumnCount() {
			return colName.length;
		}
		public String getColumnName(int col) {
			return colName[col];
		}

		@Override
		public int getRowCount() {
			return al.size();
		}

		@Override
		public Object getValueAt(int row, int col) {
			if(col == 0)
				return first.get(row);
			String line = al.get(row).replace("\"", "");
			String[] token = line.split(",");
			return token[col-1];
		}
		
		public void setValueAt(Object o, int row, int col) {
			// first col is the boolean
			if(col == 0) {
				first.set(row, (Boolean) o);
				return;
			}
			// other col
			String line = al.get(row);
			String[] token = line.split(",");
			token[row-1] = (String) o;         			// replace with new one												
			StringBuilder sb = new StringBuilder(); 	// rebuild the String
			for(int i = 0; i < token.length - 1; ++i)
				sb.append(token[i]).append(',');   		// with the comma
			sb.append(token[token.length-1]);     		// but for the last one
			al.set(row, sb.toString());           		// replace in ArrayList
		}
		
		
		
		
	}
    
    
    
//Search method
	 void search()
	    {
		 
	        String target = textField.getText();
	        for(int row = 1; row < table.getRowCount(); row++)
	            for(int col = 1; col < table.getColumnCount() -1 ; col++)
	            {
	                String next = (String)table.getValueAt(row, col);
	                if(next.equals(target))
	                {
	                    showSearchResults(row, col);
	                    return;
	                }
	            }
	 
// reset table display after failed search> target null/not found <
	        CustomRenderer renderer =
	                (CustomRenderer)table.getDefaultRenderer(String.class);
	        renderer.setTargetCell(-1, -1);
	        table.repaint();
	    }
	 
	 private void newFilter()  
	 {  
   	  //row = table.convertRowIndexToView(row);

		 List<RowFilter<TableModel,Object>> filters = new ArrayList<RowFilter<TableModel,Object>>();
		 RowFilter<TableModel, Object> compoundRowFilter = null;
		 try {
		     svclabf = RowFilter.regexFilter("^" + svclabt.getText(), 1);
		     custf = RowFilter.regexFilter("^" +custt.getText(), 2);
		     modf = RowFilter.regexFilter("^" +modt.getText(), 3);
		     serialf = RowFilter.regexFilter("^" +serialt.getText(), 4);
		     ecnf = RowFilter.regexFilter("^" +ecnt.getText(), 5);
		     subcustf = RowFilter.regexFilter("^" +subcustt.getText(), 7);
		     
		     filters.add(svclabf);
		     filters.add(custf);
		     filters.add(modf);
		     filters.add(serialf);
		     filters.add(ecnf);
		     filters.add(subcustf);
		     compoundRowFilter = RowFilter.andFilter(filters); // you may also choose the OR filter
		 } catch (java.util.regex.PatternSyntaxException e) {
		     return;
		 }
		 sorter.setRowFilter(compoundRowFilter); 		 
	 }  
 
	 void search2(){
		 
// reset table display after failed search		   
	      CustomRenderer renderer = (CustomRenderer)table.getDefaultRenderer(String.class);
	      renderer.setTargetCell(-1, -1);
	      table.repaint();
		
		 String [] searchlist = new String[6];
		 Boolean match; //use as toggle for search decision tree?
		 String sECN = null; Boolean Ec = true;
		 String sCust = null; Boolean Cc = true;
		 String sMod = null; Boolean Mc = true;
		 String sSer = null; Boolean  Sc = true;
		 String sNom = null; Boolean Nc = true;
		 String sSubCust = null; Boolean Scc = true;		 
		 
//Only get Text Field value if Check box is checked		 
		 if (cECN.isSelected()){
			 sECN = tECN.getText();
		 } else if(!cECN.isSelected()) {sECN = null;}; //if needed, catch null exception so "" won't be passed to search list? -- causes null pointer exception
		 if (cCust.isSelected()){
			 sCust = tCust.getText();
		 } 
		 if (cMod.isSelected()){
			 sMod = tMod.getText();
		 }
		 if (cSer.isSelected()){
			 sSer = tSer.getText();
		 }
		 if (cNom.isSelected()){
			 sNom = tNom.getText();
		 }
		 if (cSubCust.isSelected()){
			 sSubCust = tSubCust.getText();
		 }
//After assigning String values from text fields based on check box confirmation, fill an array list with values
		searchlist[0] = sECN;
		searchlist[1] = sCust;
		searchlist[2] = sMod;
		searchlist[3] = sSer;
		searchlist[4] = sNom;
		searchlist[5] = sSubCust;		

//Need: array to hold table row values
  Object[] tbrowdata = new Object[8];
  TableModel tb = table.getModel();
  Object val;
  int selectedRow;
  
  for(int r = 0; r < table.getRowCount(); r++){ 
	  selectedRow = r;
	  
  for (int i= 1; i < 8 ; i++) {
	  val = tb.getValueAt(r, i);
	  tbrowdata [i-1] = val;
   
  		}
  if(
	 ((tbrowdata[4].equals(searchlist[0])) || searchlist[0] == null) &&
	 ((tbrowdata[1].equals(searchlist[1])) || searchlist[1] == null) &&
	 ((tbrowdata[2].equals(searchlist[2])) || searchlist[2] == null) &&
	 ((tbrowdata[3].equals(searchlist[3])) || searchlist[3] == null) &&
	 ((tbrowdata[5].equals(searchlist[4])) || searchlist[4] == null) &&
	 ((tbrowdata[6].equals(searchlist[5])) || searchlist[5] == null) 
	  
	){
	  showSearchResults(r, 5);
  	}

  }
  
//test print values from GUI Text Fields when respective Check box is checked
		 /*
  		 System.out.println(searchlist[0]);
		 System.out.println(searchlist[1]);
		 System.out.println(sMod);
		 System.out.println(sSer);
		 System.out.println(sNom);
		 System.out.println(sSubCust);
	 	*/
	 }
	 
//returnReportData 	 
	 public Object[][] returnReportData(){
		 
		 TableModel tm2 = table.getModel();
//Get count of rows with Print Box checked (counter = z) to initialize the reportData Object[][] 
		 int z = 0; 		 
		 for(int x = 0; x < tm2.getRowCount(); x++){
			 if(((Boolean)tm2.getValueAt(x, 0)) == true){
				  z++;				  				  
			 }
		 }
//Initialize Object[][]	reportData and store dimensions as tRow and tCol	 		 			 
		 int nRow = tm2.getRowCount(), nCol = tm2.getColumnCount();
		 Object[][] reportData = new Object[z][54];  
		 int tRow = reportData.length, tCol = reportData[0].length;

//Populate reportData with table model data where Checkbox = Boolean.TRUE				 
		 int index = 0;
		 for (int i = 0 ; i < nRow ; i++){
		     if(((Boolean)tm2.getValueAt(i, 0)) == true){
		         for (int j = 1 ; j < nCol ; j++){   
		              reportData[index][j] = tm2.getValueAt(i,j);  
		         }
		         ++index;
		     }
		 }
		 
//Test print reportData in rectangular form
		 int ROWS = reportData.length;
		 int COLS = reportData[0].length;
		 for (int L = 0; L < ROWS; L++) {
			 for (int M = 0; M < COLS; M++) {
				System.out.print(" " + reportData[L][M]);
		 }
		 System.out.println("");
		 }
		return reportData;		 	 
	}		 
 
//Show the search results using Custom Renderer 
		private void showSearchResults(int row, int col)
		    {
				//table.repaint();
		        CustomRenderer renderer = (CustomRenderer)table.getCellRenderer(row, col);
		        renderer.setTargetCell(row, col);
		        Rectangle r = table.getCellRect(row, col, false);
		        table.scrollRectToVisible(r);
				table.repaint();

		    }

//Main method for test purposes		
		public void main(String[] args) throws IOException
		    {
		        SearchTest test = new SearchTest();
		        JFrame f = new JFrame("-JQuery V_0.1 Beta-");
		        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
				Container cP = f.getContentPane(); 
		
				f.getContentPane().add(new JTabbedPane());
		        f.getContentPane().add(new JScrollPane(test.table));
		        f.getContentPane().add(test.textField, "North");
		        f.setSize(600,400);
		        f.setLocationRelativeTo(null);
		        f.setVisible(true);
		        test.textField.requestFocusInWindow();
		
		    }

		

		
//Mouse Event Listener for Row Selection into Detail Tab		
	Object o;
	Object[] dtlist = new Object[52];
	public void valueChanged(ListSelectionEvent e) {
		   Object value;
		   if (!e.getValueIsAdjusting()) {       	
		     selRows = table.getSelectedRow();
		     row = selRows;		     
		     
// get Table data
		     TableModel tm = table.getModel();
		     if (row > -1) {
		    	 row = table.convertRowIndexToModel(row);
		        for (int i= 1; i < 52 ; i++) {
		          value = tm.getValueAt(row,i);
		          dtlist[i-1]  = value;

		          }
//get test value in array dtlist
		        o = Array.get(dtlist, 1);
		        //System.out.println(selRows);
		        //System.out.println(row);
		        //Key Fields
		        dtECN.setText((String) Array.get(dtlist, 4));
		        dtCust.setText((String) Array.get(dtlist, 1));
		        dtMod.setText((String) Array.get(dtlist, 2));
		        dtSer.setText((String) Array.get(dtlist, 3));
		        dtNom.setText((String) Array.get(dtlist, 5));
		        
		        //Auxiliary Fields
		        dtMFR.setText((String) Array.get(dtlist, 8));
		        dtPARTOF.setText((String) Array.get(dtlist, 14));
		        dtSUBCUST.setText((String) Array.get(dtlist, 6));
		        dtSCHEDLAB.setText((String) Array.get(dtlist, 10));
		        dtSCAT.setText((String) Array.get(dtlist, 19));
		        dtNSN.setText((String) Array.get(dtlist, 13));
		        dtPLANTACCT.setText((String) Array.get(dtlist, 18));
		        dtAPPRPROC.setText((String) Array.get(dtlist, 21));
		        dtSVCLAB.setText((String) Array.get(dtlist, 0));
		        dtMETCYCLE.setText((String) Array.get(dtlist, 7));
		        dtPHASE.setText((String) Array.get(dtlist, 20));
		        dtDTCOMPL.setText((String) Array.get(dtlist, 43));
		        dtDTLASTSER.setText((String) Array.get(dtlist, 40));
		        dtSERVLBL.setText((String) Array.get(dtlist, 17));
		        dtDTNEXTDUE.setText((String) Array.get(dtlist, 41));
		        dtSTATUS.setText((String) Array.get(dtlist, 8));
		        dtONSITE.setText((String) Array.get(dtlist, 15));
		        dtSHOP.setText((String) Array.get(dtlist, 22));
		        dtWLNHRS.setText((String) Array.get(dtlist, 33));
		        dtCLASSSTD.setText((String) Array.get(dtlist, 23));
		        dtCALSTD.setText((String) Array.get(dtlist, 16));
	        
		        }
		     } 
		    }

	@Override
	public void tableChanged(TableModelEvent e) {
		if (!((ListSelectionModel) e).getValueIsAdjusting()) {
		int index = e.getFirstRow();
		model.setValueAt(Boolean.TRUE, index, 0);
		}
	} 

} //end SearchTest



class TransparentButton extends JButton {
	public TransparentButton(String text) { 
	    super(text);
	    final Color alphaZero = new Color(0, true);
	    setBackground(alphaZero);
	    setForeground(Color.black);
	    setOpaque(false); 
	    //setBorder(null);  
	    //setBorderPainted(false);    
	    setContentAreaFilled(true);     
	} 
	    
	public void paint(Graphics g) { 
	    Graphics2D g2 = (Graphics2D) g.create(); 
	    //g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); 
	    super.paint(g2); 
	    setForeground(Color.black);
	    g2.dispose(); 
	} 
}

	class CustomRenderer implements TableCellRenderer{
	    JLabel label;
	    int targetRow, targetCol;
	    final Color alphaZero = new Color(0, true);
	 
	    public CustomRenderer()
	    {
	        label = new JLabel();
	        label.setHorizontalAlignment(JLabel.CENTER);
	        label.setOpaque(true);
	        targetRow = -1;
	        targetCol = -1;
	    }

 
public Component getTableCellRendererComponent(JTable table,
                                                   Object value,
                                                   boolean isSelected,
                                                   boolean hasFocus,
                                                   int row, int column)
    {
        if(isSelected)
        {
            label.setBackground(alphaZero);
            label.setForeground(alphaZero);
        }
        else
        {
            label.setBackground(alphaZero);
            label.setForeground(alphaZero);
        }
        if(row == targetRow && column == targetCol)
        {
            label.setBorder(BorderFactory.createLineBorder(Color.red));
            label.setFont(table.getFont().deriveFont(Font.BOLD));
        }
        else
        {
            label.setBorder(null);
            label.setFont(table.getFont());
        }
        label.setText((String)value);
        return label;
    }

	public void setTargetRow(int row){
		targetRow = row;
	}
 
    public void setTargetCell(int row, int col)
    {
        targetRow = row;
        targetCol = col;
    }


    
}
	
	




*Edited: duplicated text/code removed. (It happens)

This post has been edited by pbl: 07 May 2012 - 11:16 AM

Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 07 May 2012 - 11:25 AM

Post the stack trace

And how do you know it worked before ? Didn't you had a stackoverflow ?
Was This Post Helpful? 0
  • +
  • -

#14 Examiner12  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 89
  • Joined: 02-February 12

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 07 May 2012 - 11:30 AM

Stack Trace:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at PCQ.SearchTest.newFilter(SearchTest.java:597)
at PCQ.SearchTest.access$0(SearchTest.java:573)
at PCQ.SearchTest$3.insertUpdate(SearchTest.java:209)
at javax.swing.text.Abstractdocument.fireInsertUpdate(Unknown Source)
at javax.swing.text.Abstractdocument.handleInsertString(Unknown Source)
at javax.swing.text.Abstractdocument.insertString(Unknown Source)
at javax.swing.text.Plaindocument.insertString(Unknown Source)
at javax.swing.text.Abstractdocument.replace(Unknown Source)
at javax.swing.text.JTextComponent.replaceSelection(Unknown Source)
at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(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.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(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)

This post has been edited by Examiner12: 07 May 2012 - 11:47 AM

Was This Post Helpful? 0
  • +
  • -

#15 Examiner12  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 89
  • Joined: 02-February 12

Re: JTable - eliminate java.lang.OutOfMemoryError: Java heap space ?

Posted 07 May 2012 - 11:52 AM

It worked using a smaller version of the dataset.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3