Results 1 to 5 of 5
  1. #1
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Question How to solve this JTable problem?? [REPOST]

    hi,

    I am trying to build a small program that can search java ‘class’ files and ‘method’s from a repository where millions of java files are stored. In addition it has an algorithm(LONGEST COMMON SUBSEQUENT) to compare the results to find the similarity percentage and user can make precision by putting threshold value before start searching.

    I already done for java ‘class’ files and it can show results correctly in TextArea of GUI. But actually I want to show these results in JTable instead of textArea where result will create rows automatically in Table.

    I am trying like this, has no error but no output..

    Would anybody please check and help me......

    Java Code:
    public void actionPerformed(ActionEvent e) {
    if(e.getSource()==searchButton){
    
    FileReader reader;			String result=""; 				
    String word= new String(); 
    String target = "class";
    Map<String, File> names = new HashMap<String, File>();
     
    try{  
    
    File directory = new File("C:/Java/Repository");// setting the repository path
    
    File filelist[]= directory.listFiles();
    for (File f: filelist) {
    	
    reader = new FileReader (f);		
    Scanner scan = new Scanner(reader); 
    
    while(scan.hasNext()){ scan.next();
    result = scan.findWithinHorizon(target,0); 
    
    if(result!=null) {
    word = (scan.next() + scan.findWithinHorizon("", 0));
    names.put(word,f); 
    
    for (String found: names.keySet()){ } 
    
    }
    }
    
    }
    String SearchClass=txtField.getText();
    				  
    for (String found: names.keySet()) {
    	DecimalFormat myformat=new DecimalFormat("###.##");
    	double compare = MyGui.LCS(found, SearchClass);
    	double getThreshold = Double.parseDouble(threshold.getText());
    		
    if (compare >= getThreshold) {
    	File file = names.get(found);
    //previously show resutls in textArea correctly
    //txtArea.append(found+"\t\t\t\t"+myformat.format(compare) +" \t\t\t "+ file.getName()+"\n");  
    			
    //now i want to make column and row to show that same results  	
    try {	 
    DefaultTableModel model= new DefaultTableModel();
    Vector<String> vCol = new Vector<String>();
     vCol.addElement("NAMES"); 	vCol.addElement("SIMILAIRY");  	vCol.addElement("FILE PATH"); 
    
     Vector<String> row;
     Vector<Vector> vRow=new Vector<Vector>();			
    			
    row= new Vector<String>();
    row.addElement(found); row.addElement(myformat.format(compare)); row.addElement(file.getName());
    //row.addElement(" "+found); row.addElement(" "+myformat.format(compare)); row.addElement(" "+file.getName());
    					
    vRow.addElement(row);
      model.addRow(vRow);
      model = new DefaultTableModel(vRow, vCol); 
    JTable table = new JTable(model);
    		
    JScrollPane	scrollpane = new JScrollPane(table);
    resultSet.add(scrollpane);
    		  }
     catch(Exception exc)
                      {System.out.println("Error!" + exc); }
    Last edited by doha786; 02-05-2010 at 04:47 AM.

  2. #2
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Default

    oppss..same problem happened.

    why the code tags is not working here ? is it because of the code is too big ??

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

    Default

    why the code tags is not working here ? is it because of the code is too big ?

    Try using spaces to indent rather than tabs. Spaces act more predictably when displayed as part of a web page. You might also want to avoid very long lines - code is easier to read in any context when it consists of moderate length lines.

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

    Default

    What's resultSet?

    Post a small example that shows how you are trying to display the data. Something that actually compiles. It does not have to include the searching/formatting/tolerance stuff as this has nothing to do with your problem.

  5. #5
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Default

    resultSet is a Panel where i want to set this JTable.
    JTable has three columns - "NAMES" "SIMILARITY" AND "FILE PATH"

    so found search results will come under this and make rows which has value of "class name", "similarity percentage like..40%,50% " and "show location of that file"

    if 20 result found..20 rows will create in JTable..

    thats all... thanks

Similar Threads

  1. How to solve this JTable problem??
    By doha786 in forum New To Java
    Replies: 5
    Last Post: 02-05-2010, 03:45 AM
  2. Could someone help me to solve this problem...
    By Vinny in forum Java Software
    Replies: 1
    Last Post: 07-08-2009, 07:59 PM
  3. Help me to solve problem
    By mansoorhacker in forum Forum Guides
    Replies: 8
    Last Post: 01-24-2009, 07:29 PM
  4. Help me to solve problem
    By mansoorhacker in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 09:15 AM
  5. Replies: 2
    Last Post: 05-15-2008, 11:15 AM

Posting Permissions

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