Hi All,

I've created a gui Panel with 6 JTextFields and a 'Search' JButton. Each field has a corresponding Checkbox. The objective is to provide the user the ability to search using varying combinations of search criteria based on what boxes are checked. The logic for the search method (called by the 'Search' button action listener) is where I'm having difficulty as there is no 'where' clause in java from what I can see (more on this in a minute). So far, I'm checking if the box is checked, assigning the textfield value to a string, then loading the strings into an array list. Next, I begin looping through the table model (my data is contained in a JTable), assigning row values into a second array list, and compare to check for matches, calling my show search results method when I find a match. To be more clear about my problem: If a box isnt checked, the loop still compares the empty arraylist element to a real field. I need to only compare elements where the user checked the box and can't seem to get my head around an if else or other logic to accomplish this. I know this explanation is a little wonky, but I'd really appreciate any constructive feedback here. I'll gladly provide more clarity as needed. So far I have:

Java Code:


	 void search2(){
		 table.repaint();
		 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;
		 String [] searchlist = new String[6];
		 
//Only get Text Field value if Check box is checked		 
		 if (cECN.isSelected()){
			 sECN = tECN.getText();
		 } 
		 //else{sECN = null;}; //if needed, catch null exception so "" won't be passed to search list?
		 if (cCust.isSelected()){
			 sCust = tCust.getText();
		 }
		 //else{cCust = null;};
		 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])) /*&&
	 (tbrowdata[1].equals(searchlist[1])) &&
	 (tbrowdata[1].equals(searchlist[2])) &&
	 (tbrowdata[3].equals(searchlist[3])) &&
	 (tbrowdata[5].equals(searchlist[4])) &&
	 (tbrowdata[7].equals(searchlist[5])) 
	  */
	){
	  showSearchResults(r, 5);
      //return;
  	//table.repaint();
	  
  	}
  
  }	
 
//test print values from GUI Text Fields when respective Check box is checked
		 System.out.println(searchlist[0]);
		 System.out.println(sCust);
		 System.out.println(sMod);
		 System.out.println(sSer);
		 System.out.println(sNom);
		 System.out.println(sSubCust);

		 
	 }