Example usage for javax.swing.table DefaultTableModel setColumnCount

List of usage examples for javax.swing.table DefaultTableModel setColumnCount

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableModel setColumnCount.

Prototype

public void setColumnCount(int columnCount) 

Source Link

Document

Sets the number of columns in the model.

Usage

From source file:hw.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

    //        ResultSet rs1;
    //         /*from w  ww .j ava  2s  .  c o m*/
    //        try {
    MongoCollection<Document> coll = db.getCollection("business");
    //MongoCollection<Document> catcollection = db.getCollection("catout");
    MongoCollection<Document> rcoll = db.getCollection("review");
    //final DBCollection collection = db.getCollection("review");
    MongoCollection<Document> ccoll = db.getCollection("checkin");
    String from_dropdown = jComboBox3.getSelectedItem().toString();
    String to_dropdown = jComboBox6.getSelectedItem().toString();

    String from_value = jTextField9.getText();
    String to_value = jTextField10.getText();
    String check_count_value = jTextField11.getText();

    String check_count_dropdown = jComboBox8.getSelectedItem().toString();
    String fromdate_value = jTextField1.getText();
    String todate_value = jTextField3.getText();
    String stars_value = jTextField12.getText();
    String votes_value = jTextField13.getText();
    String stars_dropdown = jComboBox4.getSelectedItem().toString();
    String votes_dropdown = jComboBox12.getSelectedItem().toString();
    String select = jComboBox1.getSelectedItem().toString();
    List<String> category_value = jList2.getSelectedValuesList();
    String poi = jComboBox5.getSelectedItem().toString();
    String proximity = jComboBox2.getSelectedItem().toString();
    BasicDBObject qryBusiness = new BasicDBObject();
    BasicDBObject qryReview = new BasicDBObject();
    BasicDBList BusinessList = new BasicDBList();
    BasicDBList ReviewList = new BasicDBList();
    FindIterable<Document> cursor;
    FindIterable<Document> cursor1;
    List<String> catout = new ArrayList<String>();
    List<String> proout = new ArrayList<String>();
    List<String> checkinout = new ArrayList<String>();
    List<String> reviewout = new ArrayList<String>();
    List<String> finalout = new ArrayList<String>();

    if (category_value.isEmpty())//&& poi == null && proximity == null && from_value == null && fromdate_value == null)
    {
        BasicDBObject nu = new BasicDBObject();
        FindIterable<Document> fi;
        fi = coll.find(nu);
        jTextField8.setText("db.business.find()");
        String Columnames[] = { "business_id", "state", "city", "stars" };
        DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
        dtm.setColumnCount(0);
        dtm.setRowCount(0);
        int numberOfColumns = Columnames.length;

        for (int i = 0; i < numberOfColumns; i++) {
            String name = Columnames[i];
            dtm.addColumn(name);

        }

        fi.forEach(new Block<Document>() {
            @Override
            public void apply(final Document document) {

                Object rowData[] = new Object[numberOfColumns];

                rowData[0] = document.get("business_id");
                rowData[1] = document.get("state");
                rowData[2] = document.get("city");
                rowData[3] = document.get("stars");

                dtm.addRow(rowData);
                rowData = null;
            }
        });

        jTable1.setRowSelectionAllowed(true);
        jTable1.setModel(dtm);

        jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        dtm.fireTableDataChanged();

    } else {

        Object[] l = jList2.getSelectedValues();
        //BasicDBList subcat = new BasicDBList();
        BasicDBList clist = new BasicDBList();
        BasicDBObject qrycategory;
        if (l.length > 0) {
            for (int i = 0; i < l.length; i++) {
                BasicDBObject buinessop = new BasicDBObject("categories", l[i]);
                clist.add(buinessop);
            }
        }
        qrycategory = new BasicDBObject("$or", clist);
        //               subcatquery = new BasicDBObject("$out","subcat");
        //               subcat.add(qrycategory);
        //               subcat.add(subcatquery);
        //               System.out.println(subcat);
        cursor = coll.find(qrycategory);

        System.out.println(qrycategory);
        //BasicDBObject category = new BasicDBObject();
        cursor.forEach(new Block<Document>() {
            @Override
            public void apply(final Document document) {

                System.out.println(document.get("business_id"));
                //category.put((String)document.get("business_id"), db);

                catout.add((String) document.get("business_id"));
                //                                System.out.println(document.get("state"));
                //                                System.out.println(document.get("city"));
                //                                System.out.println(document.get("stars"));
                //                               

            }
        });

        MongoCollection<Document> collecttest = db.getCollection("test");
        String[] addresses5 = { "", "4840 E Indian School Rd\\nSte 101\\nPhoenix, AZ 85018",
                "631 S Main St\\nDe Forest, WI 53532", "5813 Main St\\nMc Farland, WI 53558",
                "2039 Allen Blvd\\nMiddleton, WI 53562", "6230 University Ave\\nMiddleton, WI 53562" };
        String[][] latLong = { { "33.499313000000001", "-111.98375799999999" },
                { "43.2408748", "-89.343721700000003" }, { "43.014164000000001", "-89.288567" },
                { "43.090642000000003", "-89.485168999999999" }, { "43.0910607", "-89.487486700000005" } };

        BasicDBObject queryBusiness = new BasicDBObject();
        BasicDBList businessinputlist = new BasicDBList();

        String selectedAddress = jComboBox5.getSelectedItem().toString();
        String selectedProximity = jComboBox2.getSelectedItem().toString();
        Double pro = Double.parseDouble(selectedProximity) / 3963.2;
        int index = Arrays.asList(addresses5).indexOf(selectedAddress);
        Double Latitude = Double.parseDouble(latLong[index][0]);
        Double Longitude = Double.parseDouble(latLong[index][1]);
        System.out.println("lat" + Latitude);
        System.out.println("longi" + Longitude);
        //BasicDBObject lat = new BasicDBObject(Latitude.toString(),Longitude);
        BasicDBList c1 = new BasicDBList();
        BasicDBList cs = new BasicDBList();
        cs.add(Latitude);
        cs.add(Longitude);
        c1.add(cs);
        c1.add(pro);
        BasicDBObject c = new BasicDBObject("$centerSphere", c1);
        BasicDBObject bq = new BasicDBObject("loc", new BasicDBObject("$geoWithin", c));
        FindIterable<Document> fi;
        fi = collecttest.find(bq);
        System.out.println(bq);
        jTextField8.setText("db.test.find(" + bq + ")");
        fi.forEach(new Block<Document>() {
            @Override
            public void apply(final Document document) {

                System.out.println(document.get("business_id"));

                proout.add((String) document.get("business_id"));

                //System.out.println(document.get("loc"));
            }
        });
        int checkinempty = 0;
        if (from_value == null || to_value == null || check_count_value.equals("0")) {
            checkinempty = 1;
            List<String> pr = new ArrayList<String>(catout);
            System.out.println(pr.size());
            pr.retainAll(proout);
            System.out.println(pr.size());
            String Columnames[] = { "Business_id", "state", "city", "stars" };
            DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
            dtm.setColumnCount(0);
            dtm.setRowCount(0);
            int numberOfColumns = Columnames.length;
            Object rowData[] = new Object[numberOfColumns];

            for (int i = 0; i < numberOfColumns; i++) {
                String name = Columnames[i];
                dtm.addColumn(name);

            }
            for (int i = 0; i < pr.size(); i++) {

                rowData[0] = pr.get(i);
                BasicDBObject c11 = new BasicDBObject("business_id", pr.get(i));
                FindIterable<Document> f1;
                f1 = coll.find(c11);
                f1.forEach(new Block<Document>() {
                    @Override
                    public void apply(final Document document) {

                        Object rowData[] = new Object[numberOfColumns];
                        rowData[0] = document.get("business_id");
                        rowData[1] = document.get("state");
                        rowData[2] = document.get("city");
                        rowData[3] = document.get("stars");
                        dtm.addRow(rowData);
                        rowData = null;

                    }
                });

                //                                
                //                                
                //                              

            }

            jTable1.setRowSelectionAllowed(true);
            jTable1.setModel(dtm);

            jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            dtm.fireTableDataChanged();

        }
        if (checkinempty != 1) {

            BasicDBList checkinputlist = new BasicDBList();
            //               
            ArrayList<String> list1;
            list1 = new ArrayList<String>();
            list1.add("0");
            list1.add("1");
            list1.add("2");
            list1.add("3");
            list1.add("4");
            list1.add("5");
            list1.add("6");

            int from = list1.indexOf(from_dropdown);
            int to = list1.indexOf(to_dropdown);
            int count = to - from;
            int hoursfrom1 = Integer.parseInt(from_value);
            int hoursto1 = Integer.parseInt(to_value);
            int count1 = hoursto1 - hoursfrom1;

            FindIterable<Document> iterable = ccoll.find();

            iterable.forEach(new Block<Document>() {
                @Override
                public void apply(final Document document) {
                    //System.out.println(document.get("checkin_info"));

                    String s = document.toJson();
                    s.replace("Document", "");
                    // System.out.println(s);
                    JSONParser parser = new JSONParser();
                    try {
                        Object obj = parser.parse(s);
                        JSONObject doc = (JSONObject) obj;

                        //System.out.println(doc.get("checkin_info"));
                        JSONObject cinfo = (JSONObject) doc.get("checkin_info");
                        if (count >= 0) {
                            long num_checkin = 0;
                            for (int i = from; i <= to; i++) {
                                if (count1 >= 0) {
                                    for (int j = hoursfrom1; j <= hoursto1; j++) {
                                        //System.out.println(cinfo.get(j+"-"+i));
                                        if (cinfo.containsKey(j + "-" + i)) {
                                            num_checkin = num_checkin + (long) cinfo.get(j + "-" + i);
                                            //                              System.out.println(document.get("checkin_info."+j+"-"+i));

                                        }

                                    }
                                }
                            }
                            if (num_checkin != 0) {
                                if (jComboBox8.getSelectedItem().equals(">")
                                        && num_checkin > Long.parseLong(check_count_value)) {
                                    System.out
                                            .println(num_checkin + " checkins into " + doc.get("business_id"));
                                    checkinout.add((String) document.get("business_id"));

                                }
                                if (jComboBox8.getSelectedItem().equals("<")
                                        && num_checkin < Long.parseLong(check_count_value)) {
                                    System.out
                                            .println(num_checkin + " checkins into  " + doc.get("business_id"));
                                    checkinout.add((String) document.get("business_id"));

                                }
                                if (jComboBox8.getSelectedItem().equals("=")
                                        && num_checkin == Long.parseLong(check_count_value)) {
                                    System.out
                                            .println(num_checkin + " checkins into  " + doc.get("business_id"));
                                    checkinout.add((String) document.get("business_id"));

                                }
                            }

                            num_checkin = 0;

                        }
                    } catch (Exception e) {
                        System.out.println(e);
                    }
                }
            });

            if (fromdate_value != null && todate_value != null) {
                BasicDBObject fdv = new BasicDBObject("date", new BasicDBObject("$gte", fromdate_value));
                ReviewList.add(fdv);
                BasicDBObject tdv = new BasicDBObject("date", new BasicDBObject("$lte", todate_value));
                ReviewList.add(tdv);
            }
            if (stars_value != null) {
                if (stars_dropdown == ">") {
                    BasicDBObject sv = new BasicDBObject("stars",
                            new BasicDBObject("$gt", Integer.parseInt(stars_value)));
                    ReviewList.add(sv);
                }
                if (stars_dropdown == "<") {
                    BasicDBObject sv = new BasicDBObject("stars",
                            new BasicDBObject("$lt", Integer.parseInt(stars_value)));
                    ReviewList.add(sv);
                }
                if (stars_dropdown == "=") {
                    BasicDBObject sv = new BasicDBObject("stars", Integer.parseInt(stars_value));
                    ReviewList.add(sv);
                }
            }

            if (votes_value != null) {
                if (votes_dropdown == ">") {
                    BasicDBObject vv = new BasicDBObject("votes",
                            new BasicDBObject("$gt", Integer.parseInt(votes_value)));
                    //ReviewList.add(vv);
                }
                if (votes_dropdown == "<") {
                    BasicDBObject vv = new BasicDBObject("votes",
                            new BasicDBObject("$lt", Integer.parseInt(votes_value)));
                    //ReviewList.add(vv);
                }
                if (votes_dropdown == "=") {
                    BasicDBObject vv = new BasicDBObject("votes", Integer.parseInt(votes_value));
                    //ReviewList.add(vv);
                }
            }
            qryReview = new BasicDBObject("$and", ReviewList);
            if (qryReview == null) {
                //jTextField8.setText("db.review.find()");
                cursor1 = rcoll.find();

            } else {

                //jTextField8.setText("db.review.find("+qryReview.toString()+")");
                cursor1 = rcoll.find(qryReview);
            }

            cursor1.forEach(new Block<Document>() {
                @Override
                public void apply(final Document document) {
                    System.out.println(document.get("business_id"));
                    reviewout.add((String) document.get("business_id"));

                }
            });
            if ("AND".equals(jComboBox1.getSelectedItem().toString())) {
                //jTextField8.setText("db.checkin.find("+"{}"+","+"{business_id"+":1}"+")");
                List<String> fin = new ArrayList<String>(catout);
                System.out.println(fin.size());
                fin.retainAll(proout);
                System.out.println(fin.size());

                fin.retainAll(checkinout);

                System.out.println(fin.size());

                fin.retainAll(reviewout);

                //
                System.out.println(fin.size());
                String Columnames[] = { "Business_id", "state", "city", "stars" };
                DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
                dtm.setColumnCount(0);
                dtm.setRowCount(0);
                int numberOfColumns = Columnames.length;
                Object rowData[] = new Object[numberOfColumns];

                for (int i = 0; i < numberOfColumns; i++) {
                    String name = Columnames[i];
                    dtm.addColumn(name);

                }
                for (int i = 0; i < fin.size(); i++) {

                    rowData[0] = fin.get(i);
                    BasicDBObject c11 = new BasicDBObject("business_id", fin.get(i));
                    FindIterable<Document> f1;
                    f1 = coll.find(c11);
                    f1.forEach(new Block<Document>() {
                        @Override
                        public void apply(final Document document) {

                            Object rowData[] = new Object[numberOfColumns];
                            rowData[0] = document.get("business_id");
                            rowData[1] = document.get("state");
                            rowData[2] = document.get("city");
                            rowData[3] = document.get("stars");
                            dtm.addRow(rowData);
                            rowData = null;

                        }
                    });

                    //                                
                    //                                
                    //                              

                }

                jTable1.setRowSelectionAllowed(true);
                jTable1.setModel(dtm);

                jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                dtm.fireTableDataChanged();

            }
            if ("OR".equals(jComboBox1.getSelectedItem().toString())) {
                //MongoCollection<Document> = db.getCollection("business");
                //jTextField8.setText("db.checkin.find("+"{}"+","+"{business_id"+":1}"+")");
                List<String> fin = new ArrayList<String>(catout); //create a Set with all the elements in a
                fin.addAll(proout);
                System.out.println(fin.size());
                fin.addAll(checkinout);
                System.out.println(fin.size());
                fin.addAll(reviewout);
                System.out.println(fin.size());

                String Columnames[] = { "Business_id", "state", "city", "stars" };
                DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
                dtm.setColumnCount(0);
                dtm.setRowCount(0);
                int numberOfColumns = Columnames.length;
                //Object rowData[] = new Object[numberOfColumns];
                //Object rd1,rd2,rd3; 

                for (int i = 0; i < numberOfColumns; i++) {
                    String name = Columnames[i];
                    dtm.addColumn(name);

                }
                for (int i = 0; i < fin.size(); i++) {

                    Object rowData[] = new Object[numberOfColumns];

                    rowData[0] = fin.get(i);

                    BasicDBObject c11 = new BasicDBObject("business_id", fin.get(i));
                    FindIterable<Document> f1;
                    f1 = coll.find(c11);
                    f1.forEach(new Block<Document>() {
                        @Override
                        public void apply(final Document document) {

                            Object rowData[] = new Object[numberOfColumns];
                            rowData[0] = document.get("business_id");
                            rowData[1] = document.get("state");
                            rowData[2] = document.get("city");
                            rowData[3] = document.get("stars");
                            dtm.addRow(rowData);
                            rowData = null;
                        }
                    });

                }
                //                       });

                //Object rowData[] = new Object[numberOfColumns];

                //                                
                //                                
                //                              

                jTable1.setRowSelectionAllowed(true);
                jTable1.setModel(dtm);

                jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                dtm.fireTableDataChanged();

            }
            if (qryBusiness == null) {
                //jTextField8.setText("db.business.find()");
                cursor = coll.find();

            } else {

                //jTextField8.setText("db.business.find("+qryBusiness.toString()+")");
                cursor = coll.find(qryBusiness);
            }

            //         } catch (SQLException ex) {
            //             Logger.getLogger(hw.class.getName()).log(Level.SEVERE, null, ex);
            //         }
            //             
            //             
            //         
            //     

        }

    }
}

From source file:search2go.UIFrame.java

public void identify(boolean fullProcess) {
    if ("Stop".equals(btnGTermIdent.getText())) {
        identButton.activate();//from   www. ja v  a2 s. c  o m
        try {
            if (os.isWindows()) {
                Runtime.getRuntime().exec("cmd /C TaskKill -IM blastx.exe -F");
                Runtime.getRuntime().exec("cmd /C TaskKill -IM blastn.exe -F");
                Runtime.getRuntime().exec("cmd /C TaskKill -IM blastp.exe -F");
            } else {
                Runtime.getRuntime().exec("killAll -KILL blastx");
                Runtime.getRuntime().exec("killAll -KILL blastn");
                Runtime.getRuntime().exec("killAll -KILL blastp");
            }
        } catch (IOException ex) {
            System.out.println("Error closing child processes");
        }
        prgIdentification.setIndeterminate(false);
    } else if (currentProj.checkStage(2)) {
        if (currentProj.isAvaialable()) {
            pnlChartHolder.removeAll();
            lstQueries.clearSelection();
            lstQueries.setModel(new DefaultListModel());
            txtTermInfo.setText("");

            tblGOFreq.clearSelection();
            DefaultTableModel d = new DefaultTableModel();
            d.setColumnCount(2);
            d.setColumnIdentifiers(new String[] { "GO ID", "Frequency" });
            tblGOFreq.setModel(d);

            identSequences = new ArrayList<>();

            resetIdentCount();
            for (int i = 0; i < 3; i++) {
                if (currentProj.getTargetDBString().contains(targetDBs[i])) {
                    JTextArea tempHolder = new JTextArea();
                    ProcessSequence identSequence = new ProcessSequence(currentProj,
                            new ProcessSequenceFiller(tempHolder, Integer.toString(i)) {
                                private final JTextArea sequenceOutput = tempHolder;

                                @Override
                                public void run() {
                                    new Thread(new Runnable() {
                                        @Override
                                        public void run() {
                                            for (String record : sequenceOutput.getText().split("\n")) {
                                                String name = record.split("\t")[0];
                                                GTerm nextGTerm = new GTerm(
                                                        name.substring(0, name.indexOf("[")),
                                                        name.substring(name.indexOf("[")));
                                                nextGTerm.setTopLevel(topLevels[Integer.parseInt(getNotes())]);
                                                nextGTerm.setFrequency(Integer.parseInt(record.split("\t")[1]));
                                                gTerms.addGTerm(nextGTerm);
                                            }
                                            incIdentCount();
                                        }
                                    }).start();
                                }
                            });
                    identSequences.add(identSequence);
                    Process checkFullIdent = new Process(tempHolder);
                    Path checkFullIdentPath = new Path("Processes");
                    checkFullIdentPath.append("gotFullGTerms.py");
                    checkFullIdent.setScriptCommand(checkFullIdentPath.toEscString());
                    checkFullIdent.addParameter("dir", currentProj.getPath().toEscString());
                    checkFullIdent.addParameter("db", targetDBs[i]);
                    identSequence.addProcess(checkFullIdent);
                    ProcessSequenceFiller doFullCheckOutputGetter = new ProcessSequenceFiller(tempHolder,
                            targetDBs[i]) {
                        @Override
                        public void run() {
                            if (this.getOutBox().getText().contains("false")) {
                                this.getOutBox().setText("");
                                Process mapSequenceGO = new Process(this.getOutBox());
                                Path mapSequenceGOPath = new Path("Processes");
                                mapSequenceGOPath.append("mapSequenceGO.py");
                                mapSequenceGO.setScriptCommand(mapSequenceGOPath.toEscString());
                                mapSequenceGO.addParameter("dir", currentProj.getPath().toEscString());
                                mapSequenceGO.addParameter("db", this.getNotes());
                                this.getParentSequence(0).addProcess(mapSequenceGO);

                                Process parseConverts = new Process(this.getOutBox());
                                Path parseConvertsPath = new Path("Processes");
                                parseConvertsPath.append("parseConvertedIDs.py");
                                parseConverts.setScriptCommand(parseConvertsPath.toEscString());
                                parseConverts.addParameter("dir", currentProj.getPath().toEscString());
                                parseConverts.addParameter("db", this.getNotes());
                                this.getParentSequence(0).addProcess(parseConverts);

                                identSequence.addProcess(new ProcessSequenceFiller(tempHolder) {
                                    @Override
                                    public void run() {
                                        tempHolder.setText("");
                                        try {
                                            this.finish();
                                        } catch (IOException ex) {
                                            System.out.println("Error finishing identification process filler");
                                        }
                                    }

                                });
                            }
                            this.getOutBox().setText("");
                            Process getMatchedQueryFreq = new Process(this.getOutBox());
                            Path getMatchedQueryFreqPath = new Path("Processes");
                            getMatchedQueryFreqPath.append("getMatchedQueryFreq.py");
                            getMatchedQueryFreq.setScriptCommand(getMatchedQueryFreqPath.toEscString());
                            getMatchedQueryFreq.addParameter("dir", currentProj.getPath().toEscString());
                            getMatchedQueryFreq.addParameter("db", this.getNotes());
                            this.getParentSequence(0).addProcess(getMatchedQueryFreq);
                            try {
                                this.finish();
                            } catch (IOException ex) {
                                System.out.println("Error finishing identification process filler");
                            }
                        }
                    };

                    identSequence.addProcess(doFullCheckOutputGetter);
                    try {
                        gTerms.getGTerms().clear();
                        identSequence.start();
                        identButton.setStopTargets(
                                identSequences.toArray(new ProcessSequence[identSequences.size()]));
                        if (currentProj.willDoCC())
                            currentProj.setStage(0, 2);
                        if (currentProj.willDoBP())
                            currentProj.setStage(1, 2);
                        if (currentProj.willDoBP())
                            currentProj.setStage(2, 2);
                        prgIdentification.setIndeterminate(true);
                    } catch (IOException ex) {
                        Logger.getLogger(UIFrame.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
            identButton.activate();
        } else
            javax.swing.JOptionPane.showMessageDialog(this,
                    "Another function is currently being performed on this project, please wait until completion or manually stop the process.");
    } else {
        System.out.println(currentProj.getStage());
        javax.swing.JOptionPane.showMessageDialog(this,
                "Mapping data unavailable. Please complete mapping step or switch to a project with completed mapping to continue.");
    }

}