Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By pbrockway2

Thread: Need advice on potential memory leaks in this class

  1. #1
    Redefine12 is offline Member
    Join Date
    Feb 2012
    Posts
    66
    Rep Power
    0

    Default Need advice on potential memory leaks in this class

    Hi all,

    I have a class that establishes the main business objects for an application, central to which is a jtable and custom hash filter, implementing an abstract table model. I've attempted to use -Xprof, Eclipse MAT, to diagnose memory leaks, but am getting nowhere fast. Could some more experienced forum folks weigh in on adjustments I could make to optimize/performance tune this class? I know this isn't an SSCCE, but I strongly suggest there is a memory leak here and if there's something glaring that jumps out, please post a suggestion.

    Java Code:
    //SEARCH TEST BACKUP - HEAP SOLVED
    package pcInvpkg;
    
    import java.awt.*;
    import java.awt.event.*;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.LineNumberReader;
    import java.lang.reflect.Array;
    import java.util.ArrayList;
    import java.util.Scanner;
    import java.util.regex.Pattern;
    import javax.swing.*;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.*;
    import javax.swing.text.AbstractDocument;
    import javax.swing.text.AttributeSet;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.DocumentFilter;
    
    public class SearchTest implements ListSelectionListener, TableModelListener// ,
    																			// ActionListener
    {
    	// Main Table Object
    	final JTable table;
    	MyModel model;
    	final TextFieldPanel tfPanel;
    	//ArrayList<String> filtered;
    	// int [] filteredRows;
    	ArrayList<String> toUse;
    	readMeclData mc = new readMeclData();
    	Object[][] aMeclTwoD = mc.returnMecl();
    	launchCSVreport launchXLS = new launchCSVreport();
    	final Color alphaZero = new Color(0, true);
    	int selRows;
    	int row;
    
    	/*
    	 * 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;
    	 */
    
    	JLabel jlbPicture;
    	String reportType = "Metcal_Form";
    	String pmcColors = "MeterCard_Form-";
    	RadioListener myListener = 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("Print Menu");
    	TransparentButton print = new TransparentButton("PRINT");
    	// TransparentButton metcb = new TransparentButton("Get MetCal Form(s)");
    	TransparentButton clearmc = new TransparentButton("Clear Print Selection");
    	TransparentButton filter = new TransparentButton("Filter");
    	JButton refresh = new JButton("Refresh Filter");
    	TransparentButton all = new TransparentButton("Select All");
    
    	// 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 {
    		
    		tfPanel = new TextFieldPanel();
    		table = getTable();
    		table.setOpaque(false);	
    		refresh.setBackground(alphaZero);
    		refresh.setOpaque(false);
    		refresh.setContentAreaFilled(true);
    		Color bg = new Color(224, 242, 252);
    		
    		/*
    		 * //Search Function - Complete
    		 * 
    		 * bs = new JButton("  Search  ");
    		 * refresh.setToolTipText("Filter Table View for Current Selection");
    		 * mcb
    		 * .setToolTipText("Enter Print Menu for Current PRINT Checkbox Selection"
    		 * );
    		 * metcb.setToolTipText("Get MetCal Form(s) for Current PRINT Selection"
    		 * ); clearmc.setToolTipText("Clear the Current PRINT Selection");
    		 * filter.setToolTipText("Filter Data");
    		 * all.setToolTipText("Print Entire Current Filtered 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(); } });
    		 */
    		print.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				/*
    				 * try {
    				 */// System.out.println("Do I get here at all? " + pmcColors);
    				if (reportType.contains("Metcal_Form")) {
    					print.setEnabled(false);
    					// app.printMetcalForm();
    				}
    				if (reportType.contains("MeterCard_Form")) {
    					print.setEnabled(false);
    					// app.printMeterCardForm();
    				}
    				if (reportType.contains("Asset_List")) {
    					launchXLS.launchNewReport();
    				}
    				/*
    				 * } catch (IOException e1) { // TODO Auto-generated catch block
    				 * e1.printStackTrace(); }
    				 */}
    		});
    
    		mcb.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				try {
    					returnReportData();
    				} catch (IOException e1) {
    					// TODO Auto-generated catch block
    					e1.printStackTrace();
    				}
    				printMenu();
    			}
    		});
    		/*
    		 * metcb.addActionListener(new ActionListener() { public void
    		 * actionPerformed(ActionEvent e) { try { returnReportData(); } catch
    		 * (IOException e1) { // TODO Auto-generated catch block
    		 * e1.printStackTrace(); } } });
    		 */
    		clearmc.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				clearPrint();
    			}
    		});
    		/*
    		 * filter.addActionListener(new ActionListener() { public void
    		 * actionPerformed(ActionEvent e) { newFilter(); } });
    		 */
    		refresh.addActionListener(new ActionListener() {
    
    			public void actionPerformed(ActionEvent e) {
    				// get the hash value from the JTextField
    				String[] hash = tfPanel.getHash();
    				// update the model
    				// System.out.println(hash[0]+hash[1]+hash[2]+hash[3]+hash[4]+hash[5]+hash[6]);
    				// System.out.println(model);
    				// System.out.println(table);
    
    				int nb = model.use(hash);
    				// update the label for number of match
    				tfPanel.label.setText(nb + " matches found");
    				// redraw the JTable
    				table.tableChanged(new TableModelEvent(model));
    				// System.out.print(filtered);
    				// System.out.println(filtered.size());
    				clearPrint(); // ?
    				
    			}
    		});
    
    		all.addActionListener(new ActionListener() {
    
    			public void actionPerformed(ActionEvent e) {
    				filtPrint();
    
    			}
    
    		});
    
    	}
    
    	// Get the JTable and return it
    	JTable getTable() throws IOException {
    
    		File f = new File("C:\\PCQ\\A_R06.csv");
    		// File f = new File("C:\\PCQ\\SQUIGGLE.csv");
    		Scanner s = new Scanner(f);
    
    		String[] colNames = { "PRINT", "SERVICING_LAB", "CUSTOMER_ID",
    				"MODEL_NO", "SERIAL_NO", "ECN", "NOMENCLATURE",
    				"SUB_CUSTODIAN", "SCHED_LAB", "METRL_CYCLE", "MFR_CD", "UIC",
    				"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",
    				"CONDITION_RECEIVED", "SPCL_INSTR_CD", "WORKLOAD_NORM_HRS",
    				"BIN_LOCATION", "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() - 1; // subtract 1 to account for the skipped row
    		lnr = null;									
    
    		// Import CSV File into table model
    		ArrayList<String> al = new ArrayList<String>(ln);
    		int c = 0;
    		s.nextLine(); // advance the scanner to skip the first row
    		while (c < ln) {
    			al.add(s.nextLine().replace("\"", ""));
    			c++;
    		}
    		s.close();
    		s = null;
    		f=null;
    		model = new MyModel(colNames, al);
    		al = null;
    		// sorter = new TableRowSorter<TableModel>(model);
    
    		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();
    				}
    			}
    			
    			public Component prepareRenderer(TableCellRenderer renderer,
    					int rowIndex, int vColIndex) {
    				setOpaque(false);
    				Component c = super.prepareRenderer(renderer, rowIndex,
    						vColIndex);
    				c.setBackground(alphaZero);
    				/*
    				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);
    					}
    				}
    				
    				//highlight WIP
    				if (Pattern.matches("[a-zA-Z]+",
    						(CharSequence) (model.getValueAt(rowIndex, 1)))) {
    					c.setBackground(new Color(174, 201, 230));
    				}
    */
    				// int[] wipcols = {1,26,28,31,37,38,39,40};
    
    				if (vColIndex == 1 || vColIndex == 26 || vColIndex == 28
    						|| vColIndex == 31 || vColIndex == 37
    						|| vColIndex == 38 || vColIndex == 39) {
    					c.setFont(new Font("SansSerif", Font.BOLD, 12));
    				}
    
    				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);
    		// int index=0; for(String s1 : al) System.out.println((index)+": "+s1);
    		return table;
    	}
    
    	// my tableModel as an inner class
    	class MyModel extends AbstractTableModel {
    		String[] colName;
    		ArrayList<String> al;
    		ArrayList<Boolean> first;
    		final String[][] hash; // the hashcode of each line
    		ArrayList<String> filtered;
    		// the selected rows
    		String[] token; // last row read
    		int cacheRow = -1; // not set
    
    		// the arrayList to use. If I have filters, it will point to filtered
    		// if I do not have filters it will point to al
    
    		// constructor
    		MyModel(String[] colName, ArrayList<String> al) {
    
    			long start = System.nanoTime();
    			this.colName = colName;
    			this.al = al;
    			filtered = new ArrayList<String>(); // init empty
    
    			// Start by pointing to the ArrayList containing all the data (no
    			// filter)
    			toUse = al;
    
    			// ArrayList<Boolean> first;
    			first = new ArrayList<Boolean>(al.size());
    			for (int i = 0, s = al.size(); i < s; ++i)
    				first.add(Boolean.valueOf(false));
    
    			// build the hash-code for each row based on the 8 first columns
    			hash = new String[al.size()][8];
    			for (int i = 0, s = hash.length; i < s; ++i) {
    				// split the data based on delimiter
    				token = al.get(i).split("\\|", 8);
    				for (int j = 0; j < 8; ++j) {
    					hash[i][j] = token[j];
    				}
    			}
    			//long now = System.nanoTime();
    			// System.out.println("TableModel constructed in: " + ((now-start) /
    			// 1000000L) + " milliseconds");
    
    		}
    
    		// Use a filter based on a hash-value coming from the JTextField
    		private int use(String[] hashValue) {
    			cacheRow = -1; // clear cache
    			filtered.clear(); // clear previous match data
    			// save the length in an array to avoid to call 200000 * 7 times
    			// .length()
    			
    			int[] len = new int[hashValue.length];
    			int total = 0;
    			for (int i = 0, s = hashValue.length; i < s; ++i) {
    				len[i] = hashValue[i].length();
    				total += len[i];
    			}
    			// if all text fields empty
    			if (total == 0) {
    				toUse = al;
    				return al.size();
    			}
    			// filteredRows = new int[/*filtered.size()*/40000];
    			// k we will have to test
    			for (int i = 0, s3 = hash.length; i < s3; ++i) {
    				int j;
    				int s4;
    				for (j = 0, s4 = hashValue.length; j < s4; ++j) {
    					// empty test
    					if (len[j] == 0)
    						continue;
    					// if does not start with break
    					if (!hash[i][j].startsWith(hashValue[j]))
    						break;
    				}
    				// if all matched
    				if (j == hashValue.length)
    					filtered.add(al.get(i));
    				int z = i;
    			}
    
    			toUse = filtered;
    			
    			// returns the number of match to be displayed in the JLabel
    			return toUse.size();
    		}
    
    		@Override
    		public int getColumnCount() {
    			return colName.length;
    		}
    
    		public String getColumnName(int col) {
    			return colName[col];
    		}
    
    		@Override
    		public int getRowCount() {
    			return toUse.size();
    		}
    
    		@Override
    		public Object getValueAt(int row, int col) {
    
    			if (col == 0)
    				return first.get(row);
    			// if we are using the gig array and the column is the first ones
    			// use the hash
    			if (toUse == al && col < 8)
    				return hash[row][col - 1];
    
    			if (row != cacheRow) {
    				String line = toUse.get(row);// .replace("\"", "");
    				token = line.split("\\|");
    				cacheRow = row;
    			}
    			return token[col - 1]; // -1
    		}
    
    		public void setValueAt(Object o, int row, int col) {
    			// first column is the boolean
    			if (col == 0) {
    				first.set(row, (Boolean) o);
    				return;
    			}
    			// other column
    			String line = al.get(row).replace("\"", "");
    			String[] token = line.split("\\|"); // DELIMITER - USE PIPE***
    			token[row - 1] = (String) o; // replace with new one
    			StringBuilder sb = new StringBuilder(); // rebuild the String
    			for (int i = 0, s5 = token.length; i < s5 - 1; ++i)
    				sb.append(token[i]).append("\\|"); // with the delimiter
    			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() { 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); }
    	 * 
    	 * }
    	 */
    	// clear Print Selection
    	public void clearPrint() {
    		TableModel tm2 = table.getModel();
    		for (int i = 0, s6 = tm2.getRowCount(); i < s6; i++) {
    			tm2.setValueAt(false, i, 0);	
    		}
    		table.repaint(); // outside loop
    		tm2 = null;
    	}
    
    	// need: Method to set Print = true on current filtered selection called by
    	// JButton
    	public void filtPrint() {
    
    		int rows = toUse.size();
    		String[] filtVals = new String[rows];
    		TableModel tm2 = table.getModel();
    
    		/*
    		 * Color a = new Color(104, 106, 132); Color b = new Color(210, 226,
    		 * 232); Color c = new Color(10, 77, 126);
    		 */
    		/*
    		 * if(rows > 3000){
    		 * 
    		 * //v.1 - SIMPLE JFrame frame2 = new JFrame();
    		 * frame2.getRootPane().setOpaque(false); frame2.setUndecorated(true);
    		 * Color cm = new Color(210, 226, 232); frame2.getContentPane
    		 * ().setBackground (cm); //Color cm = Color.cyan; UIManager um = new
    		 * UIManager(); um.put("OptionPane.background", cm);
    		 * UIManager.put("Panel.background", cm);
    		 * JOptionPane.showMessageDialog(frame2,
    		 * "Current Filter Selection is too large. Please refine filter criteria."
    		 * , "Refine Filter Selection", JOptionPane.WARNING_MESSAGE);
    		 * 
    		 * }
    		 */
    		// else{
    		for (int i = 0, s7 = toUse.size(); i < s7; i++) {
    			String n = toUse.get(i);
    			String[] filtrow = n.split("\\|");
    			for (int j = 0, s8 = filtrow.length; j < s8; j++) {
    				filtVals[i] = filtrow[4];
    			}
    			// System.out.println(filtVals[i]);
    		}
    
    		for (int i = 0, s9 = tm2.getRowCount(); i < s9; i++) {
    			for (int x = 0, s10 = filtVals.length; x < s10; x++) {
    				// System.out.println(tm2.getValueAt(i, 5)+ " " +filtVals[i]);
    				if (tm2.getValueAt(i, 5).equals(filtVals[x])) {
    					tm2.setValueAt(true, i, 0);		
    				}
    			}
    		}
    		table.repaint(); //outside loop
    		tm2 = null;
    		// }
    		// System.out.println(tm2.getValueAt(1, 5));
    		// System.out.println(filtVals[1][4]);
    		// System.out.println(filtered.size());
    		// System.out.println(toUse.size());
    		// System.out.println(Arrays.toString(filteredRows));
    
    	}
    
    	// returnReportData
    	public void returnReportData() throws IOException {
    		BufferedWriter out = null;
    		Object[][] reportData = null;
    
    		out = new BufferedWriter(new FileWriter("C:\\PCQ\\MCard.csv"));
    		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, s11 = tm2.getRowCount(); x < s11; x++) {
    			if (((Boolean) tm2.getValueAt(x, 0)) == true) {
    				z++;
    			}
    		}
    		// Initialize Object[][] reportData and store dimensions as tRow and
    		int nRow = tm2.getRowCount(), nCol = tm2.getColumnCount();
    		reportData = new Object[z][/* 50 *//* 76 */102];
    
    		// 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 = 0; j < nCol - 1; j++) {
    					reportData[index][j] = tm2.getValueAt(i, j + 1);
    				}
    				++index;
    			}
    		}
    		// AND append Customer MECL data
    		// System.out.println("First test spot, did I get here?");
    		for (int i = 0, s12 = reportData.length; i < s12; i++) {
    			// System.out.println("I'm here: " + aMeclTwoD.length);
    			for (int d = 0, s13 = aMeclTwoD.length; d < s13; d++) {
    				if (reportData[i][1].equals(aMeclTwoD[d][2])) {
    					// LOOP - CUSTOMER
    					for (int m = 0, s14=aMeclTwoD[0].length; m < s14; m++) {
    						reportData[i][m + 50] = aMeclTwoD[d][m];
    					}
    				}
    				if (reportData[i][7].equals(aMeclTwoD[d][2])) {
    					// LOOP - SCHED LAB
    					for (int m = 0, s15=aMeclTwoD[0].length; m < s15; m++) {
    						reportData[i][m + 76] = aMeclTwoD[d][m];
    					}
    				}
    			}
    			
    		}
    
    		// Headers////////////////////////////////////
    		final String[] colNames = { "SERVICED_LAB", "CUSTOMER_ID", "MODEL_NO",
    				"SERIAL_NO", "ECN", "NOMENCLATURE", "SUB_CUSTODIAN",
    				"SCHED_LAB", "METRL_CYCLE", "MFR_CD", "UIC", "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", "CONDITION_RECEIVED",
    				"SPCL_INSTR_CD", "WORKLOAD_NORM_HRS", "BIN_LOCATION", "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",
    				/* "DTC_REIND", */"SITEID", "RCD_STA", "RCD_TYPE", "CUSTOMER",
    				"UIC_1", "QUAL_CODE", "CAT_CD", "PROC_ONE", "PROC_TWO",
    				"MAIL_CODE", "COMD_LINE", "ADD_LINE1", "ADD_LINE2",
    				"ADD_LINE3", "ADD_LINE4", "ADD_LINE5", "ADD_LINE6",
    				"ACC_CODE_1", "M3_CODE", "CHG_CUST", "LAB_TYPE_CD", "ZIP_CODE",
    				"LAB_CORR", "LAB2", "LAB3", "LAB4", "SITEID_2", "RCD_STA_2",
    				"RCD_TYPE_2", "CUSTOMER_2", "UIC_2", "QUAL_CODE_2", "CAT_CD_2",
    				"PROC_ONE_2", "PROC_TWO_2", "MAIL_CODE_2", "COMD_LINE_2",
    				"ADD_LINE1_2", "ADD_LINE2_2", "ADD_LINE3_2", "ADD_LINE4_2",
    				"ADD_LINE5_2", "ADD_LINE6_2", "ACC_CODE_2", "M3_CODE_2",
    				"CHG_CUST_2", "LAB_TYPE_CD_2", "ZIP_CODE_2", "LAB_CORR_2",
    				"LAB2_2", "LAB3_2", "LAB4_2" };
    		// Write Report Data...
    		// System.out.println("SECOND TEST spot, did I get here?");
    		int ROWS = reportData.length;
    		int COLS = reportData[0].length;
    		for (int c = 0; c < 102; c++) {
    			out.write(colNames[c] + ","); // Column Headers Plus Pipe
    			// System.out.print(colNames[c]);
    		}
    		// System.out.print("\n");
    		out.newLine();
    		for (int L = 0; L < ROWS; L++) {
    			for (int M = 0; M < COLS; M++) {
    				out.write(" " + reportData[L][M] + ","); // Data Plus Pipe
    				// System.out.print(" " + reportData[L][M]); // Test Print
    			}
    			// System.out.print("\n");
    			out.newLine();
    		}
    		out.close();
    
    	}
    
    	public void printMenu() {
    
    		JFrame frame = new JFrame("PcInventoryQuery Print Menu");
    		print.setEnabled(false);
    		// frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    		frame.setLayout(new BorderLayout());
    		frame.setResizable(false);
    		JPanel p = new JPanel();
    		frame.setContentPane(p);
    		p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    
    		JPanel panel1 = new JPanel() {
    			protected void paintComponent(Graphics grphcs) {
    				this.setBackground(new Color(114, 167, 226));
    				Graphics2D g2d = (Graphics2D) grphcs;
    				int arc = 10;
    				g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    						RenderingHints.VALUE_ANTIALIAS_ON);
    				GradientPaint gp = new GradientPaint(0, 0, getBackground()
    						.darker(), 0, getHeight(), getBackground().brighter()
    						.brighter());
    				g2d.setStroke(new BasicStroke());
    				g2d.setPaint(gp);
    				g2d.fillRoundRect(0, 0, getWidth(), getHeight(), arc, arc);
    				super.paintComponent(grphcs);
    			}
    		};
    		panel1.setOpaque(false);
    
    		JPanel panel2 = new JPanel() {
    			protected void paintComponent(Graphics grphcs) {
    				this.setBackground(new Color(114, 167, 226));
    				Graphics2D g2d = (Graphics2D) grphcs;
    				int arc = 10;
    				g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    						RenderingHints.VALUE_ANTIALIAS_ON);
    				GradientPaint gp = new GradientPaint(0, 0, getBackground()
    						.darker(), 0, getHeight(), getBackground().brighter()
    						.brighter());
    				g2d.setStroke(new BasicStroke());
    				g2d.setPaint(gp);
    				g2d.fillRoundRect(0, 0, getWidth(), getHeight(), arc, arc);
    				super.paintComponent(grphcs);
    			}
    		};
    		panel2.setOpaque(false);
    		Color fg = new Color(7, 116, 165);
    		panel1.setForeground(fg);
    		Font lfont = new Font("SansSerif", Font.BOLD, 11);
    
    		JRadioButton metcalForm = new JRadioButton("Metcal Form");
    		JLabel l1 = new JLabel("Print a METCAL Form.");
    		l1.setFont(lfont);
    		metcalForm.setForeground(Color.WHITE);
    		// metcalForm.setMnemonic(KeyEvent.VK_A);
    		metcalForm.setActionCommand("Metcal_Form");
    		metcalForm.setSelected(true);
    		metcalForm.setOpaque(false);
    
    		JRadioButton paperMcard = new JRadioButton("Paper MeterCard");
    		JLabel l2 = new JLabel("Print a Paper MeterCard.");
    		l2.setFont(lfont);
    		paperMcard.setForeground(Color.WHITE);
    		// paperMcard.setMnemonic(KeyEvent.VK_B);
    		paperMcard.setActionCommand("Paper_MeterCard");
    		paperMcard.setOpaque(false);
    
    		JRadioButton mCard = new JRadioButton("MeterCard Form");
    		JLabel l3 = new JLabel("Print a MeterCard Form.");
    		l3.setFont(lfont);
    		mCard.setForeground(new Color(96, 96, 96));
    		// mCard.setMnemonic(KeyEvent.VK_C);
    		mCard.setActionCommand("MeterCard_Form");
    		mCard.setOpaque(false);
    
    		JRadioButton assetList = new JRadioButton("Asset List");
    		JLabel l4 = new JLabel("Print an Asset List.");
    		l4.setFont(lfont);
    		assetList.setForeground(Color.DARK_GRAY);
    		// mCard.setMnemonic(KeyEvent.VK_D);
    		assetList.setActionCommand("Asset_List");
    		assetList.setOpaque(false);
    
    		// Group the radio buttons.
    		ButtonGroup group = new ButtonGroup();
    		group.add(metcalForm);
    		group.add(paperMcard);
    		group.add(mCard);
    		group.add(assetList);
    
    		RadioListener myListener = new RadioListener();
    		metcalForm.addActionListener(myListener);
    		paperMcard.addActionListener(myListener);
    		mCard.addActionListener(myListener);
    		assetList.addActionListener(myListener);
    
    		panel1.setLayout(new GridLayout(5, 1));
    		panel2.setLayout(new BorderLayout());
    
    		panel1.add(metcalForm);
    		panel1.add(paperMcard);
    		panel1.add(mCard);
    		panel1.add(assetList);
    		panel2.add(print, BorderLayout.SOUTH);
    		jlbPicture = new JLabel((new ImageIcon("C:\\PCQ\\Metcal_Form.jpg"))); // Set
    																				// the
    																				// Default
    																				// Image
    		jlbPicture.setPreferredSize(new Dimension(250, 180));
    		panel2.add(jlbPicture, BorderLayout.CENTER);
    
    		p.add(panel1);
    		p.add(panel2);
    		frame.setSize(538, 259);
    		frame.setVisible(true);
    		frame.setLocationRelativeTo(null);
    	}
    
    	// 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, 10));
    				dtPARTOF.setText((String) Array.get(dtlist, 14));
    				dtSUBCUST.setText((String) Array.get(dtlist, 6));
    				dtSCHEDLAB.setText((String) Array.get(dtlist, 7));
    				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, 8));
    				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, 35));
    				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);
    		}
    	}
    
    	class TextFieldPanel extends JPanel {
    		JTextField[] tf = new JTextField[8];
    		JLabel label = new JLabel();
    		DocumentFilter filter = new UppercaseDocumentFilter();
    
    		// TextFieldPanel constructor. The 5 JTextField and the JLabel
    		TextFieldPanel() {
    			super(new GridBagLayout());
    			add(new JLabel("\n")); // a little gap at the top
    			GridBagConstraints t = new GridBagConstraints();
    
    			// ADD LABELS TO SEARCH FIELDS
    			String[] labels = new String[] { "SVC LAB", "CUSTOMER", "MODEL",
    					"SERIAL", "ECN", "NOMENCLATURE", "SUB CUSTODIAN",
    					"SCHED LAB" };
    			for (int i = 0, s16 = labels.length; i < s16; ++i) {
    				JLabel x = new JLabel(labels[i].toString());
    				// System.out.println(x);
    				t.gridx = i;
    				t.gridy = 0;
    				add(x, t);
    			}
    
    			// the 8 JTextFields in a row
    			String[] tips = new String[] { "Filter by Servicing Lab",
    					"Filter by Customer ID", "Filter by Model Number",
    					"Filter by Serial Number",
    					"Filter by Equipment Control Number",
    					"Filter by Nomenclature", "Filter by Sub Custodian",
    					"Filter by Scheduled Lab" };
    			for (int i = 0, s17=tf.length; i < s17; ++i) {
    				tf[i] = new JTextField(12);
    				Color bg = new Color(224, 242, 252);
    				tf[i].setBackground(bg);
    				((AbstractDocument) tf[i].getDocument())
    						.setDocumentFilter(filter);
    				tf[i].setToolTipText(tips[i]);
    
    				t.gridx = i;
    				t.gridy = 1;
    				add(tf[i], t);
    			}
    
    			// the status label
    			label.setOpaque(true);
    			label.setBackground(new Color(210, 226, 232));
    			label.setHorizontalAlignment(SwingConstants.CENTER);
    
    			t.gridx = 3;
    			t.gridy = 2;
    			add(label, t);
    			t.gridx = 8;
    			t.gridy = 1;
    			add(refresh, t);
    			setOpaque(false);
    		}
    
    		// return the String in the 8 JTextFields
    		String[] getHash() {
    			String[] token = new String[tf.length];
    			for (int i = 0,s19=token.length; i < s19; ++i)
    				token[i] = tf[i].getText().trim();
    			return token;
    		}
    	}
    
    	class RadioListener implements ActionListener {
    		public void actionPerformed(ActionEvent e) {
    
    			reportType = e.getActionCommand();
    			jlbPicture.setIcon(new ImageIcon("C:\\PCQ\\" + e.getActionCommand()
    					+ ".jpg"));
    
    			if (!(reportType.equals("Asset_List")) || reportType == null) {
    				print.setEnabled(false);
    			} else {
    				print.setEnabled(true);
    			}
    
    			/*
    			 * if(reportType.equals("MeterCard_Form")){ print.setEnabled(false);
    			 * pmcColors = "MeterCard_Form-"; JFrame pmcFrame = new
    			 * JFrame("MeterCard Form Selection Menu"); pmcFrame.setLayout(new
    			 * BorderLayout()); pmcFrame.setResizable(false); JPanel p1 = new
    			 * JPanel(); pmcFrame.setContentPane(p1); p1.setLayout(new
    			 * BoxLayout(p1, BoxLayout.Y_AXIS )); pmcFrame.setSize(412, 121);
    			 * pmcFrame.setVisible(true); pmcFrame.setLocationRelativeTo(null);
    			 * 
    			 * final JCheckBox white = new JCheckBox("WHITE", true);
    			 * white.setOpaque(false); final JCheckBox pink = new
    			 * JCheckBox("PINK", true); pink.setOpaque(false); final JCheckBox
    			 * buff = new JCheckBox("BUFF", true); buff.setOpaque(false); final
    			 * JCheckBox yellow = new JCheckBox("YELLOW", true);
    			 * yellow.setOpaque(false); final JCheckBox green = new
    			 * JCheckBox("GREEN", true); green.setOpaque(false); JLabel instr =
    			 * new JLabel("               "+
    			 * "*Please select desired MeterCard Form Copies");
    			 * instr.setOpaque(false); TransparentButton pmcPrint = new
    			 * TransparentButton("PRINT");
    			 * 
    			 * pmcPrint.addActionListener(new ActionListener(){
    			 * 
    			 * @Override public void actionPerformed(ActionEvent e) { pmcColors
    			 * = "MeterCard_Form-";
    			 * 
    			 * if(white.isSelected()){ pmcColors = pmcColors + "white"; }
    			 * if(pink.isSelected()){ pmcColors = pmcColors + "pink"; }
    			 * if(buff.isSelected()){ pmcColors = pmcColors + "buff"; }
    			 * if(yellow.isSelected()){ pmcColors = pmcColors + "yellow"; }
    			 * if(green.isSelected()){ pmcColors = pmcColors + "green"; }
    			 * 
    			 * //System.out.println(pmcColors); } } );
    			 * 
    			 * JPanel p2 = new JPanel(new GridBagLayout()){ protected void
    			 * paintComponent(Graphics grphcs) { this.setBackground(new
    			 * Color(114, 167, 226)); Graphics2D g2d = (Graphics2D) grphcs; int
    			 * arc = 10; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    			 * RenderingHints.VALUE_ANTIALIAS_ON); GradientPaint gp = new
    			 * GradientPaint(0, 0, getBackground().darker(), 0, getHeight(),
    			 * getBackground().brighter().brighter()); g2d.setStroke(new
    			 * BasicStroke()); g2d.setPaint(gp); g2d.fillRoundRect(0, 0,
    			 * getWidth(), getHeight(), arc, arc); super.paintComponent(grphcs);
    			 * } }; p2.setOpaque(false); GridBagConstraints c = new
    			 * GridBagConstraints();
    			 * 
    			 * c.gridx = 0; c.gridy = 0; p2.add(white, c); c.gridx = 1; c.gridy
    			 * = 0; p2.add(pink, c); c.gridx = 2; c.gridy = 0; p2.add(buff, c);
    			 * c.gridx = 3; c.gridy = 0; p2.add(yellow, c); c.gridx = 4; c.gridy
    			 * = 0; p2.add(green, c); c.gridx = 2; c.gridy = 1; p2.add(pmcPrint,
    			 * c);
    			 * 
    			 * JPanel p3 = new JPanel(new GridLayout(1, 0)); p3.add(instr);
    			 * p1.add(p2); p1.add(p3);
    			 * 
    			 * }
    			 * 
    			 * else print.setEnabled(true);
    			 */
    		}
    	}
    
    } // 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 UppercaseDocumentFilter extends DocumentFilter {
    	public void insertString(DocumentFilter.FilterBypass fb, int offset,
    			String text, AttributeSet attr) throws BadLocationException {
    
    		fb.insertString(offset, text.toUpperCase(), attr);
    	}
    
    	public void replace(DocumentFilter.FilterBypass fb, int offset, int length,
    			String text, AttributeSet attrs) throws BadLocationException {
    
    		fb.replace(offset, length, text.toUpperCase(), attrs);
    	}
    }
    /*
    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;
    	}
    
    }
    */
    Last edited by Redefine12; 06-27-2012 at 10:06 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Need advice on potential memory leaks in this class

    My experience at this forum suggests that you're not going to be able to find a volunteer at this forum that will have the time to devote towards reading, understanding, and then completely analyzing this holy flippin' humongous god-class. I hope I'm wrong, but in the mean time while we're waiting, consider refactoring this huge class, and then running tests on the smaller more reasonably sized portions of the code to try to isolate your error. Also consider trying a different profiler. Also consider telling us why you suspect that a memory leak is occurring. Best of luck.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Need advice on potential memory leaks in this class

    I know this isn't an SSCCE
    I suggest making it into one.

    You could begin by removing distracting commented out code. And any of the gui controls that you can while still reproducing the problem. The suggestion of refactoring into manageable pieces will also help mightily in "zeroing in" on the problem.

    A SSCCE will include all of the classes that are required to compile and run (or proxies for them: eg JButton for TransparentButton if that makes no difference). This is important as any such code may be contributing to the problem.

    A SSCCE will describe the actual problem: that is, the discrepancy between what happens when main() is invoked and what you expect or intend would happen. This might involve adding code to main() to make the discrepancy overt. This will address fubarable's question of why you suspect a memory leak.

    -----

    I realise all of this involves a lot of work. Life is a *lot* easier when someone wanders by and is able to tell me that I did something dumb on line 666. Who knows, that might happen, but I wouldn't sit around waiting. The refactoring suggestion is valuable in any case as smaller testable and tested pieces will contribute ongoing value in terms of manageability.
    Last edited by pbrockway2; 06-28-2012 at 03:10 AM.
    Fubarable likes this.

Similar Threads

  1. Java from c++ (JNI) memory leaks
    By Gigabitze in forum New To Java
    Replies: 12
    Last Post: 02-27-2011, 02:03 PM
  2. memory leaks in Java
    By Navatha in forum New To Java
    Replies: 8
    Last Post: 09-29-2010, 06:42 PM

Posting Permissions

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