create TableModel and populate jTable dynamically

Posted by Julia on Stack Overflow See other posts from Stack Overflow or by Julia
Published on 2010-05-30T08:42:30Z Indexed on 2010/05/30 8:52 UTC
Read the original article Hit count: 409

Hi all!

I want to store the results of reading lucene index into jTable, so that I can make it sortable by different columns. From index I am reading terms with different measures of their frequencies.

Table columns are these : [string term][int absFrequency][int docFrequency][double invFrequency]

So i in AbstractTableModel I can define column names, but i dont know how to get the Object[][]data with results from the following method:

public static void FrequencyMap(Directory indexDir) throws Exception
{        
        List<Object>redoviLista = new ArrayList<Object>();


        //final Map<String,TermRow> map = new TreeMap<String,TermRow>(); 
        List<String>termList = new ArrayList<String>();

        IndexReader iReader = IndexReader.open(indexDir);
        FilterIndexReader fReader = new FilterIndexReader(iReader);

        int numOfDocs = fReader.numDocs();
        TermEnum terms = fReader.terms(); 

        while (terms.next()){
            Term term = terms.term(); 
            String termText = term.text();
            termList.add(termText);

//Calculating the frequencies   
            int df = iReader.docFreq(term);
            double idf = 0.0F;
            idf = Math.log10((double) numOfDocs / df);
            double tfidf = (df*idf);

    //Here comes important part     
            Object oneTableRow[] = {termText, df, idf, tfidf};
            redoviLista.add(jedanRed); // So i thaught to store them into list, and then later to copy into table, but didnt manage


        }
        iReader.close();
  // So I need something like this, and i Neeed this array to be stored out of this method

                  Object[][]data = new Object[redoviLista.size()][];
        for (int i = 0; i < data.length; i++) {
            data[i][0] = redoviLista.get(i);
        }

So I am kindda stuck here to proceed to implement AbstractTableModel and populate and display this table .... :/

Please help!

© Stack Overflow or respective owner

Related posts about java

Related posts about swing