Example usage for javax.swing.table TableModel getRowCount

List of usage examples for javax.swing.table TableModel getRowCount

Introduction

In this page you can find the example usage for javax.swing.table TableModel getRowCount.

Prototype

public int getRowCount();

Source Link

Document

Returns the number of rows in the model.

Usage

From source file:org.apache.metamodel.elasticsearch.rest.ElasticSearchRestDataContextIT.java

@Test
public void testMaxRows() throws Exception {
    Table table = dataContext.getDefaultSchema().getTableByName(peopleIndexType);
    Query query = new Query().from(table).select(table.getColumns()).setMaxRows(5);
    DataSet dataSet = dataContext.executeQuery(query);

    TableModel tableModel = new DataSetTableModel(dataSet);
    assertEquals(5, tableModel.getRowCount());
}

From source file:at.tuwien.ifs.feature.evaluation.SimilarityRetrievalGUI.java

private void initButtonSaveResults() {
    btnSaveResults = new JButton("Save as ...");
    btnSaveResults.setEnabled(false); // can't save right away, need a first search
    btnSaveResults.addActionListener(new ActionListener() {
        @Override/* ww w.  ja v  a2s.c o m*/
        public void actionPerformed(ActionEvent e) {
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            if (fileChooser.getSelectedFile() != null) { // reusing the dialog
                fileChooser.setSelectedFile(null);
            }

            int returnVal = fileChooser.showDialog(SimilarityRetrievalGUI.this, "Save results to file ...");
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                try {
                    PrintWriter w = FileUtils.openFileForWriting("Results file",
                            fileChooser.getSelectedFile().getAbsolutePath());
                    TableModel model = resultsTable.getModel();

                    // column headers
                    for (int col = 0; col < model.getColumnCount(); col++) {
                        w.print(model.getColumnName(col) + "\t");
                    }
                    w.println();

                    // write each data row
                    for (int row = 0; row < model.getRowCount(); row++) {
                        for (int col = 0; col < model.getColumnCount(); col++) {
                            w.print(model.getValueAt(row, col) + "\t");
                        }
                        w.println();
                    }
                    w.flush();
                    w.close();
                    JOptionPane.showMessageDialog(SimilarityRetrievalGUI.this,
                            "Successfully wrote to file " + fileChooser.getSelectedFile().getAbsolutePath(),
                            "Results stored", JOptionPane.INFORMATION_MESSAGE);

                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    });
}

From source file:uk.ac.lkl.cram.ui.report.Report.java

private void addSummary() {
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    mdp.addStyledParagraphOfText("Heading1", "Summary");
    Tbl table = factory.createTbl();/* w  ww .ja  v  a 2  s  . c  om*/
    Tr tableHead = factory.createTr();
    TableModel tableModel = new SummaryReportModel(module);
    int columnCount = tableModel.getColumnCount();
    for (int col = 0; col < columnCount; col++) {
        addTableCell(tableHead, tableModel.getColumnName(col), JcEnumeration.CENTER, true);
    }
    table.getContent().add(tableHead);
    for (int row = 0; row < tableModel.getRowCount(); row++) {
        boolean lastRow = row == tableModel.getRowCount() - 1;
        Tr tableRow = factory.createTr();
        if (lastRow) {
            addTableCell(tableRow, tableModel.getValueAt(row, 0).toString(), JcEnumeration.LEFT, true);
        } else {
            addSimpleTableCell(tableRow, tableModel.getValueAt(row, 0).toString());
        }
        for (int col = 1; col < columnCount; col++) {
            if (row > 4) {
                addTableCell(tableRow, CURRENCY_FORMATTER.format(tableModel.getValueAt(row, col)),
                        JcEnumeration.RIGHT, lastRow);
            } else {
                addTableCell(tableRow, INTEGER_FORMATTER.format(tableModel.getValueAt(row, col)),
                        JcEnumeration.RIGHT, lastRow);
            }
        }
        table.getContent().add(tableRow);
    }
    addBorders(table);
    mdp.addObject(table);
}

From source file:com.qspin.qtaste.ui.xmleditor.TestRequirementEditor.java

private void computeColumnWidths() {
    // horizontal spacing
    int hspace = 6;
    TableModel model = m_TestRequirementTable.getModel();

    // rows no// w w  w. j  av a  2s. c om
    int cols = model.getColumnCount();

    // columns no
    int rows = model.getRowCount();

    // width vector
    int w[] = new int[model.getColumnCount()];

    // computes headers widths
    for (int i = 0; i < cols; i++) {
        w[i] = (int) m_TestRequirementTable
                .getDefaultRenderer(String.class).getTableCellRendererComponent(m_TestRequirementTable,
                        m_TestRequirementModel.getColumnName(i), false, false, -1, i)
                .getPreferredSize().getWidth() + hspace;
        TableColumn hcol = m_TestRequirementTable.getColumn(m_TestRequirementModel.getColumnName(i));
        hcol.setHeaderRenderer(new MyTableHeaderRenderer());

    }

    // check if cell values fit in their cells and if not
    // keep in w[i] the necessary with
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            Object o = model.getValueAt(i, j);
            int width = 0;
            if (o != null) {
                width = (int) m_TestRequirementTable.getCellRenderer(i, j)
                        .getTableCellRendererComponent(m_TestRequirementTable, o, false, false, i, j)
                        .getPreferredSize().getWidth() + hspace;
            }
            if (w[j] < width) {
                w[j] = width;
            }
        }
    }

    TableColumnModel colModel = m_TestRequirementTable.getColumnModel();

    // and finally setting the column widths
    for (int i = 0; i < cols; i++) {
        colModel.getColumn(i).setPreferredWidth(w[i]);
    }
}

From source file:bio.gcat.gui.BDATool.java

private void enableBinaryDichotomicAlgorithmMenus() {
    JTable table = bdaPanel.table;
    javax.swing.table.TableModel bdas = table.getModel();
    int size = bdas.getRowCount(), index = table.getSelectedRow();
    boolean filled = size != 0, selected = filled && index != -1;
    getMenuItem(menubar, ACTION_BDA_EDIT).setEnabled(selected && index < size); //BinaryDichotomicAlgorithm bda = bdas.get(index); !isPredefined(bda);
    getMenuItem(menubar, ACTION_BDA_MOVE_UP).setEnabled(index > 0);
    getMenuItem(menubar, ACTION_BDA_MOVE_DOWN).setEnabled(selected && index < size - 1);
    getMenuItem(menubar, ACTION_BDA_REMOVE).setEnabled(selected);
    getMenuItem(menubar, ACTION_BDAS_CLEAR).setEnabled(filled);
}

From source file:uk.ac.lkl.cram.ui.report.Report.java

private void addTutorPreparationCost() {
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    mdp.addStyledParagraphOfText("Heading2", "Cost of Preparation");
    Tbl table = factory.createTbl();/*from ww  w . j  av a2s .c  om*/
    Tr tableHead = factory.createTr();
    TableModel tableModel = new TutorCostTableModel(module);
    addTableCell(tableHead, tableModel.getColumnName(0), JcEnumeration.CENTER, true);
    for (int col = 1; col < 4; col++) {
        addTableCell(tableHead, tableModel.getColumnName(col), JcEnumeration.CENTER, true);
    }
    table.getContent().add(tableHead);
    for (int row = 0; row < tableModel.getRowCount(); row++) {
        boolean lastRow = row == tableModel.getRowCount() - 1;
        Tr tableRow = factory.createTr();
        if (lastRow) {
            addTableCell(tableRow, tableModel.getValueAt(row, 0).toString(), JcEnumeration.LEFT, true);
        } else {
            addSimpleTableCell(tableRow, tableModel.getValueAt(row, 0).toString());
        }
        for (int col = 1; col < 4; col++) {
            addTableCell(tableRow, CURRENCY_FORMATTER.format(tableModel.getValueAt(row, col)),
                    JcEnumeration.RIGHT, lastRow);
        }
        table.getContent().add(tableRow);
    }
    addBorders(table);
    mdp.addObject(table);
}

From source file:uk.ac.lkl.cram.ui.report.Report.java

private void addTutorSupportCost() {
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    mdp.addStyledParagraphOfText("Heading2", "Cost of Support");
    Tbl table = factory.createTbl();/*from   w ww .j a  v a2s . c om*/
    Tr tableHead = factory.createTr();
    TableModel tableModel = new TutorCostTableModel(module);
    addTableCell(tableHead, tableModel.getColumnName(0), JcEnumeration.CENTER, true);
    for (int col = 4; col < 7; col++) {
        addTableCell(tableHead, tableModel.getColumnName(col), JcEnumeration.CENTER, true);
    }
    table.getContent().add(tableHead);
    for (int row = 0; row < tableModel.getRowCount(); row++) {
        boolean lastRow = row == tableModel.getRowCount() - 1;
        Tr tableRow = factory.createTr();
        if (lastRow) {
            addTableCell(tableRow, tableModel.getValueAt(row, 0).toString(), JcEnumeration.LEFT, true);
        } else {
            addSimpleTableCell(tableRow, tableModel.getValueAt(row, 0).toString());
        }
        for (int col = 4; col < 7; col++) {
            addTableCell(tableRow, CURRENCY_FORMATTER.format(tableModel.getValueAt(row, col)),
                    JcEnumeration.RIGHT, lastRow);
        }
        table.getContent().add(tableRow);
    }
    addBorders(table);
    mdp.addObject(table);
}

From source file:com.view.TradeWindow.java

private void TraderBlockOrdersActionPerformed(java.awt.event.ActionEvent evt) {
    TableModel dtm = (TableModel) TraderIncomingRequestsTable.getModel();
    int nRow = dtm.getRowCount();
    int nCol = dtm.getColumnCount();
    Object[][] tableData = new Object[nRow][nCol];
    ArrayList<SingleOrder> parsedOrders = new ArrayList();
    ControllerBlockOrders control = new ControllerBlockOrders();

    for (int i = 0; i < nRow; i++) {
        for (int j = 0; j < nCol; j++) {
            tableData[i][j] = dtm.getValueAt(i, j);
        }//w ww  .  j  a v a  2  s . com
        SingleOrder o = new SingleOrder();
        o.SingleOrderMakeBlocks(tableData[i]);
        parsedOrders.add(o);
    }
    singleOrderLists = control.MakeBlock(parsedOrders);
    showMessageDialog(null, "Blocks have been successfully completed.");
    //dtm.setRowCount(0);
    TraderPlatformBlockedRequests.setLayout(new BorderLayout());
    int count = 1;
    ArrayList<JScrollPane> paneList = new ArrayList<JScrollPane>();
    for (ArrayList<SingleOrder> b : singleOrderLists) {
        JTable jTable = new JTable();
        jTable.setModel(CTraderBlockOrder.getTableModel(b));
        Dimension d = jTable.getPreferredSize();
        // System.out.println(d);
        int rows = jTable.getRowCount();
        // System.out.println(rows);
        JScrollPane jPane = new JScrollPane();
        jPane.setPreferredSize(new Dimension(d.width, jTable.getRowHeight() * rows + 50));
        jPane.add(jTable);
        jPane.setViewportView(jTable);
        paneList.add(jPane);
        count++;
    }

    test.add(blockOptions);
    int i = 0;
    for (final JScrollPane j : paneList) {
        //   JButton btn = new JButton();
        //  btn.setText("Split Block");
        //     btn.setName(""+i);

        JPanel cPanel = new JPanel();
        /*  btn.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            JViewport viewport = j.getViewport(); 
            final JTable mytable = (JTable)viewport.getView();
            final ArrayList<Integer> index = new ArrayList<Integer>();
            for(int row = 0;row<mytable.getRowCount();row++){
                  if((boolean)mytable.getValueAt(row, 11)){
                     index.add(row);
                  }
            }
             SplitBlockActionPerformed(evt,index,cPanel,test);
         }
          });*/
        JCheckBox check = new JCheckBox();
        JLabel label = new JLabel();
        label.setText("Select Block");
        check.setName("" + i);
        check.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SelectBlockActionPerformed(evt);
            }
        });
        JPanel splitOptions = new JPanel();
        splitOptions.add(label);
        splitOptions.add(check);
        splitOptions.setName("splitOpt");
        //  splitOptions.add(btn);
        cPanel.setName("cPanel" + i);
        cPanel.add(splitOptions);
        cPanel.add(j);
        cPanel.setLayout(new BoxLayout(cPanel, BoxLayout.Y_AXIS));
        test.add(cPanel);
        cPanelList.add(cPanel);
        i++;
    }

    test.setLayout(new BoxLayout(test, BoxLayout.Y_AXIS));
    JScrollPane p = new JScrollPane(test);
    p.setName("ParentP");
    TraderPlatformBlockedRequests.add(p);
    TraderPlatformBlockedRequests.validate();
    TraderPlatformTabbedPane.setSelectedIndex(TraderPlatformTabbedPane.getSelectedIndex() + 1);

}

From source file:uk.ac.lkl.cram.ui.report.Report.java

private void addTutorPreparationHours() {
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    mdp.addStyledParagraphOfText("Heading2", "Tutor Preparation Hours");
    Tbl table = factory.createTbl();/* w  w  w . j av  a  2s .co m*/
    Tr tableHead = factory.createTr();
    TableModel tableModel = new TutorHoursTableModel(module);
    addTableCell(tableHead, tableModel.getColumnName(0), JcEnumeration.CENTER, true);
    for (int col = 1; col < 4; col++) {
        addTableCell(tableHead, tableModel.getColumnName(col), JcEnumeration.CENTER, true);
    }
    table.getContent().add(tableHead);
    for (int row = 0; row < tableModel.getRowCount(); row++) {
        boolean lastRow = row == tableModel.getRowCount() - 1;
        Tr tableRow = factory.createTr();
        if (lastRow) {
            addTableCell(tableRow, tableModel.getValueAt(row, 0).toString(), JcEnumeration.LEFT, true);
        } else {
            addSimpleTableCell(tableRow, tableModel.getValueAt(row, 0).toString());
        }
        for (int col = 1; col < 4; col++) {
            addTableCell(tableRow, FLOAT_FORMATTER.format(tableModel.getValueAt(row, col)), JcEnumeration.RIGHT,
                    lastRow);
        }
        table.getContent().add(tableRow);
    }
    addBorders(table);
    mdp.addObject(table);
}

From source file:uk.ac.lkl.cram.ui.report.Report.java

private void addLearningActivities() {
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    mdp.addStyledParagraphOfText("Heading1", "Learning Activities");
    float online_hours = 0f;
    float f2f_hours = 0f;
    Tbl table = factory.createTbl();/*  w ww.  ja va2 s. co  m*/
    Tr tableHead = factory.createTr();
    TableModel tableModel = new ModuleReportModel(module);
    for (int col = 0; col < tableModel.getColumnCount(); col++) {
        addTableCell(tableHead, tableModel.getColumnName(col), JcEnumeration.CENTER, true);
    }
    table.getContent().add(tableHead);
    int columnCount = tableModel.getColumnCount();
    for (int row = 0; row < tableModel.getRowCount(); row++) {
        boolean lastRow = row == tableModel.getRowCount() - 1;
        Tr tableRow = factory.createTr();
        addTableCell(tableRow, tableModel.getValueAt(row, 0).toString(), JcEnumeration.LEFT, lastRow);
        for (int col = 1; col < columnCount; col++) {
            addTableCell(tableRow, FLOAT_FORMATTER.format(tableModel.getValueAt(row, col)), JcEnumeration.RIGHT,
                    lastRow);
        }
        table.getContent().add(tableRow);
    }
    addBorders(table);
    List<TLALineItem> lineItems = module.getTLALineItems();
    for (TLALineItem lineItem : lineItems) {
        TLActivity activity = lineItem.getActivity();
        float totalLearnerHourCount = lineItem.getTotalLearnerHourCount(module);
        StudentTeacherInteraction sti = activity.getStudentTeacherInteraction();
        if (sti.isOnline()) {
            online_hours += totalLearnerHourCount;
        }
        if (sti.isTutorSupported() && sti.isLocationSpecific()) {
            f2f_hours += totalLearnerHourCount;
        }
    }
    mdp.addStyledParagraphOfText("BodyText", "Number of learner hours online: " + (int) online_hours);
    mdp.addStyledParagraphOfText("BodyText", "Number of learner hours face-to-face: " + (int) f2f_hours);
    addBorders(table);
    mdp.addObject(table);
}