Example usage for javax.swing JTable getRowCount

List of usage examples for javax.swing JTable getRowCount

Introduction

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

Prototype

@BeanProperty(bound = false)
public int getRowCount() 

Source Link

Document

Returns the number of rows that can be shown in the JTable, given unlimited space.

Usage

From source file:Visuals.RingChart.java

public JPanel addAVCharts() {
    JPanel thisPanel = new JPanel();
    thisPanel.setLayout(new BorderLayout());
    int tempCriticalCount = 0, tempUpdatedCount = 0;
    String[][] criticalList = new String[critical][4];
    String[][] updatedList = new String[low][4];
    for (int i = 0; i < riskCount; i++) {
        if (risks[i][2].equals("Critical")) {
            criticalList[tempCriticalCount][0] = risks[i][0];
            criticalList[tempCriticalCount][1] = risks[i][1];
            criticalList[tempCriticalCount][3] = risks[i][3];
            tempCriticalCount++;/*  w  w  w .  j av a  2s  .c  o m*/
        }
        if (risks[i][2].equals("Low")) {
            updatedList[tempUpdatedCount][0] = risks[i][0];
            updatedList[tempUpdatedCount][1] = risks[i][1];
            tempUpdatedCount++;
        }
    }

    JTable criticalTable = new JTable(criticalList, criticalColumns);
    JTable updatedTable = new JTable(updatedList, updatedColumns);
    TableColumn tcol = criticalTable.getColumnModel().getColumn(2);
    criticalTable.removeColumn(tcol);
    TableColumn tcol2 = updatedTable.getColumnModel().getColumn(2);
    updatedTable.removeColumn(tcol2);

    criticalTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    updatedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    criticalTable.setEnabled(false);
    updatedTable.setEnabled(false);

    int width = 0;
    for (int i = 0; i < 3; i++) {
        for (int row = 0; row < criticalTable.getRowCount(); row++) {
            TableCellRenderer renderer = criticalTable.getCellRenderer(row, i);
            Component comp = criticalTable.prepareRenderer(renderer, row, i);
            width = Math.max(comp.getPreferredSize().width, width);
        }
        criticalTable.getColumnModel().getColumn(i).setPreferredWidth(width);
        width = 0;
    }

    for (int i = 0; i < 2; i++) {
        for (int row = 0; row < updatedTable.getRowCount(); row++) {
            TableCellRenderer renderer = updatedTable.getCellRenderer(row, i);
            Component comp = updatedTable.prepareRenderer(renderer, row, i);
            width = Math.max(comp.getPreferredSize().width, width);
        }
        updatedTable.getColumnModel().getColumn(i).setPreferredWidth(width);
        width = 0;
    }

    criticalTable.setShowHorizontalLines(true);
    criticalTable.setRowHeight(40);
    updatedTable.setShowHorizontalLines(true);
    updatedTable.setRowHeight(40);

    JScrollPane criticalTableScrollPane = new JScrollPane(criticalTable,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    JScrollPane updatedTableScrollPane = new JScrollPane(updatedTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    Dimension d = criticalTable.getPreferredSize();
    criticalTableScrollPane.setPreferredSize(
            new Dimension((d.width - 400), (criticalTable.getRowHeight() + 1) * (tempCriticalCount + 1)));

    Dimension d2 = updatedTable.getPreferredSize();
    updatedTableScrollPane.setPreferredSize(
            new Dimension((d.width - 400), (updatedTable.getRowHeight() + 1) * (tempUpdatedCount + 1)));

    Font titleFonts = new Font("Calibri", Font.BOLD, 30);

    JLabel criticalLabel = new JLabel(" Critical    ");
    criticalLabel.setFont(titleFonts);
    criticalLabel.setForeground(new Color(230, 27, 27));
    JPanel leftPanel = new JPanel();
    leftPanel.setLayout(new BorderLayout());
    leftPanel.add(criticalLabel, BorderLayout.WEST);
    leftPanel.add(criticalTableScrollPane, BorderLayout.CENTER);

    JLabel updatedLabel = new JLabel(" Updated ");
    updatedLabel.setFont(titleFonts);
    updatedLabel.setForeground(new Color(47, 196, 6));
    JPanel rightPanel = new JPanel();
    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(updatedLabel, BorderLayout.WEST);
    rightPanel.add(updatedTableScrollPane, BorderLayout.CENTER);

    if (tempCriticalCount != 0)
        thisPanel.add(leftPanel, BorderLayout.NORTH);
    if (tempUpdatedCount != 0)
        thisPanel.add(rightPanel, BorderLayout.SOUTH);
    return thisPanel;
}

From source file:com.smanempat.controller.ControllerClassification.java

public String[] processMining(JTextField textNumberOfK, JTable tablePreview, JLabel labelPesanError,
        JTable tableResult, JLabel labelSiswaIPA, JLabel labelSiswaIPS, JLabel labelKeterangan,
        JYearChooser jYearChooser1, JYearChooser jYearChooser2, JTabbedPane jTabbedPane1) {

    String numberValidate = textNumberOfK.getText();
    ModelClassification modelClassification = new ModelClassification();
    int rowCountModel = modelClassification.getRowCount();
    int rowCountData = tablePreview.getRowCount();
    System.out.println("Row Count Data : " + rowCountData);
    System.out.println("Row Count Model : " + rowCountModel);
    String[] knnValue = null;/*  ww w  .  ja v  a  2  s. c o m*/

    /*Validasi Nilai Number of Nearest Neighbor*/
    if (Pattern.matches("[0-9]+", numberValidate) == false && numberValidate.length() > 0) {
        labelPesanError.setText("Number of Nearest Neighbor tidak valid");
        JOptionPane.showMessageDialog(null, "Number of Nearest Neighbor tidak valid!", "Error",
                JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/fail.png"));
        textNumberOfK.requestFocus();
    } else if (numberValidate.isEmpty()) {
        JOptionPane.showMessageDialog(null, "Number of Nearest Neighbor tidak boleh kosong!", "Error",
                JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/fail.png"));
        labelPesanError.setText("Number of Nearest Neighbor tidak boleh kosong");
        textNumberOfK.requestFocus();
    } else if (Integer.parseInt(numberValidate) >= rowCountModel) {
        labelPesanError.setText("Number of Nearest Neighbor tidak boleh lebih dari " + rowCountModel + "");
        JOptionPane.showMessageDialog(null,
                "Number of Nearest Neighbor tidak boleh lebih dari " + rowCountModel + " !", "Error",
                JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/fail.png"));
        textNumberOfK.requestFocus();
    } else {
        int confirm = 0;
        confirm = JOptionPane.showOptionDialog(null, "Yakin ingin memproses data?", "Proses Klasifikasi",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (confirm == JOptionPane.OK_OPTION) {
            int kValue = Integer.parseInt(textNumberOfK.getText());
            String[][] modelValue = getModelValue(rowCountModel);
            double[][] dataValue = getDataValue(rowCountData, tablePreview);
            knnValue = getKNNValue(rowCountData, rowCountModel, modelValue, dataValue, kValue);
            showClassificationResult(tableResult, tablePreview, knnValue, rowCountData, labelSiswaIPA,
                    labelSiswaIPS, labelKeterangan, jYearChooser1, jYearChooser2, kValue);
            jTabbedPane1.setSelectedIndex(1);
        }

    }
    return knnValue;
}

From source file:com.vgi.mafscaling.OpenLoop.java

private boolean sortRunData(TreeMap<Integer, ArrayList<Double>> result) {
    int closestVoltIdx;
    double rpm;/*w w w  .j ava2s  .  c o m*/
    double voltage;
    double error;
    ArrayList<Double> closestVolatageArray;
    for (int i = 0; i < runTables.length; ++i) {
        JTable table = runTables[i];
        String tableName = RunTableName + (i + 1);
        String rpmValue;
        String mafvValue;
        String afrValue;
        for (int j = 0; j < table.getRowCount(); ++j) {
            rpmValue = table.getValueAt(j, 0).toString();
            mafvValue = table.getValueAt(j, 1).toString();
            afrValue = table.getValueAt(j, 2).toString();
            if (rpmValue.isEmpty() || mafvValue.isEmpty() || afrValue.isEmpty())
                continue;
            if (!Utils.validateDouble(rpmValue, j, 0, tableName)
                    || !Utils.validateDouble(mafvValue, j, 1, tableName)
                    || !Utils.validateDouble(afrValue, j, 2, tableName))
                return false;
            rpm = Double.parseDouble(rpmValue);
            voltage = Double.parseDouble(mafvValue);
            error = Double.parseDouble(afrValue);
            rpmArray.add(rpm);
            mafvArray.add(voltage);
            afrArray.add(error);
            closestVoltIdx = Utils.closestValueIndex(voltage, voltArray);
            closestVolatageArray = result.get(closestVoltIdx);
            if (closestVolatageArray == null) {
                closestVolatageArray = new ArrayList<Double>();
                result.put(closestVoltIdx, closestVolatageArray);
            }
            closestVolatageArray.add(error);
        }
    }
    return true;
}

From source file:gdt.jgui.tool.JEntityEditor.java

private void deleteRows() {
    try {//from w  ww.j  a va  2s.  c  o m
        JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent();
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
        ListSelectionModel listModel = table.getSelectionModel();
        int rCnt = table.getRowCount();
        ArrayList<Integer> srl = new ArrayList<Integer>();
        for (int i = 0; i < rCnt; i++)
            if (listModel.isSelectedIndex(i)) {
                srl.add(new Integer(i));
            }
        Integer[] sra = srl.toArray(new Integer[0]);
        ArrayList<Core> ol = new ArrayList<Core>();
        Core row;
        boolean skip;
        for (int i = 0; i < rCnt; i++) {
            skip = false;
            for (int aSra : sra) {
                if (i == aSra) {
                    skip = true;
                    break;
                }
            }
            if (!skip) {
                row = new Core((String) tableModel.getValueAt(i, 0), (String) tableModel.getValueAt(i, 1),
                        (String) tableModel.getValueAt(i, 2));
                ol.add(row);
            }
        }
        Core[] ra = ol.toArray(new Core[0]);
        while (tableModel.getRowCount() > 0)
            tableModel.removeRow(0);
        for (Core aRa : ra) {
            tableModel.addRow(new String[] { aRa.type, aRa.name, aRa.value });
        }
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:com.smanempat.controller.ControllerClassification.java

public void saveResultFile(JYearChooser thnAjaran1, JYearChooser thnAjaran2, JTable tableResult)
        throws IOException {
    JFileChooser dirChooser = new JFileChooser();
    dirChooser.setDialogTitle("Save as Excel File");
    String thnAjaran = Integer.toString(thnAjaran1.getYear()) + "-" + Integer.toString(thnAjaran2.getYear());
    String generateFileName = "Data Hasil Penjurusan Siswa Tahun Ajaran " + thnAjaran + ".xlsx";
    dirChooser.setSelectedFile(new File(generateFileName));
    int userSelection = dirChooser.showSaveDialog(null);
    int rowCountData = tableResult.getRowCount();
    if (userSelection == dirChooser.APPROVE_OPTION) {
        File fileToSave = dirChooser.getSelectedFile();
        convertToExcel(tableResult, fileToSave);
        JOptionPane.showMessageDialog(null, "Hasil klasifikasi jurusan berhasil disimpan",
                "Penyimpanan Berhasil", JOptionPane.INFORMATION_MESSAGE,
                new ImageIcon("src/com/smanempat/image/success.png"));
    }/*from  w w w .jav  a 2  s .  c  o m*/
}

From source file:me.mayo.telnetkek.MainPanel.java

public final void setupTablePopup() {
    this.tblPlayers.addMouseListener(new MouseAdapter() {
        @Override/*from  w w w . j av  a  2s.  c  om*/
        public void mouseReleased(final MouseEvent mouseEvent) {
            final JTable table = MainPanel.this.tblPlayers;

            final int r = table.rowAtPoint(mouseEvent.getPoint());
            if (r >= 0 && r < table.getRowCount()) {
                table.setRowSelectionInterval(r, r);
            } else {
                table.clearSelection();
            }

            final int rowindex = table.getSelectedRow();
            if (rowindex < 0) {
                return;
            }

            if ((SwingUtilities.isRightMouseButton(mouseEvent) || mouseEvent.isControlDown())
                    && mouseEvent.getComponent() instanceof JTable) {
                final PlayerInfo player = getSelectedPlayer();
                if (player != null) {
                    final JPopupMenu popup = new JPopupMenu(player.getName());

                    final JMenuItem header = new JMenuItem("Apply action to " + player.getName() + ":");
                    header.setEnabled(false);
                    popup.add(header);

                    popup.addSeparator();

                    final ActionListener popupAction = (ActionEvent actionEvent) -> {
                        Object _source = actionEvent.getSource();
                        if (_source instanceof PlayerListPopupItem_Command) {
                            final PlayerListPopupItem_Command source = (PlayerListPopupItem_Command) _source;
                            final String output = source.getCommand().buildOutput(source.getPlayer(), true);
                            MainPanel.this.getConnectionManager().sendDelayedCommand(output, true, 100);
                        } else if (_source instanceof PlayerListPopupItem) {
                            final PlayerListPopupItem source = (PlayerListPopupItem) _source;

                            final PlayerInfo _player = source.getPlayer();

                            switch (actionEvent.getActionCommand()) {
                            case "Copy IP": {
                                copyToClipboard(_player.getIp());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied IP to clipboard: " + _player.getIp()));
                                break;
                            }
                            case "Copy Name": {
                                copyToClipboard(_player.getName());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied name to clipboard: " + _player.getName()));
                                break;
                            }
                            case "Copy UUID": {
                                copyToClipboard(_player.getUuid());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied UUID to clipboard: " + _player.getUuid()));
                                break;
                            }
                            }
                        }
                    };

                    TelnetKek.config.getCommands().stream().map(
                            (command) -> new PlayerListPopupItem_Command(command.getName(), player, command))
                            .map((item) -> {
                                item.addActionListener(popupAction);
                                return item;
                            }).forEach((item) -> {
                                popup.add(item);
                            });

                    popup.addSeparator();

                    JMenuItem item;

                    item = new PlayerListPopupItem("Copy Name", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

                    item = new PlayerListPopupItem("Copy IP", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

                    item = new PlayerListPopupItem("Copy UUID", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

                    popup.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
                }
            }
        }
    });
}

From source file:gdt.jgui.entity.fields.JFieldsEditor.java

private void copy(boolean cut) {
    try {//from  w w  w.  j  a  v a 2  s .c om
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        ListSelectionModel listModel = table.getSelectionModel();
        int rCnt = table.getRowCount();
        ArrayList<Integer> srl = new ArrayList<Integer>();
        for (int i = 0; i < rCnt; i++)
            if (listModel.isSelectedIndex(i)) {
                srl.add(new Integer(i));
            }
        Integer[] sra = srl.toArray(new Integer[0]);
        ArrayList<String> sl = new ArrayList<String>();
        Properties locator = new Properties();
        locator.setProperty(Locator.LOCATOR_TYPE, LOCATOR_TYPE_FIELD);
        if (cut)
            locator.setProperty(JRequester.REQUESTER_ACTION, ACTION_CUT_FIELDS);
        else
            locator.setProperty(JRequester.REQUESTER_ACTION, ACTION_COPY_FIELDS);
        locator.setProperty(Entigrator.ENTIHOME, entihome$);
        locator.setProperty(EntityHandler.ENTITY_KEY, entityKey$);
        String locator$;
        console.clipboard.clear();
        for (int i = 0; i < rCnt; i++) {
            for (int aSra : sra) {
                if (i == aSra) {
                    locator.setProperty(CELL_FIELD_NAME, (String) model.getValueAt(i, 0));
                    locator.setProperty(Locator.LOCATOR_TITLE, (String) model.getValueAt(i, 0));
                    locator.setProperty(CELL_FIELD_VALUE, (String) model.getValueAt(i, 1));
                    locator$ = Locator.toString(locator);
                    //                System.out.println("FieldsEditor:copy:locator="+locator$);
                    console.clipboard.putString(locator$);
                }
            }
        }
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:gdt.jgui.entity.fields.JFieldsEditor.java

private void deleteRows() {
    try {// w w  w.j  ava  2 s .  c  o m
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
        ListSelectionModel listModel = table.getSelectionModel();
        int rCnt = table.getRowCount();
        ArrayList<Integer> srl = new ArrayList<Integer>();
        for (int i = 0; i < rCnt; i++)
            if (listModel.isSelectedIndex(i)) {
                srl.add(new Integer(i));
            }
        Integer[] sra = srl.toArray(new Integer[0]);
        ArrayList<Core> ol = new ArrayList<Core>();
        Core row;
        boolean skip;
        for (int i = 0; i < rCnt; i++) {
            skip = false;
            for (int aSra : sra) {
                if (i == aSra) {
                    skip = true;
                    break;
                }
            }
            if (!skip) {
                row = new Core(null, (String) tableModel.getValueAt(i, 0),
                        (String) tableModel.getValueAt(i, 1));
                ol.add(row);
            }
        }
        Core[] ra = ol.toArray(new Core[0]);
        while (tableModel.getRowCount() > 0)
            tableModel.removeRow(0);
        for (Core aRa : ra) {
            tableModel.addRow(new String[] { aRa.name, aRa.value });
        }
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

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);
        }//from   www  .jav  a2  s.co m
        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:com.vgi.mafscaling.ClosedLoop.java

private void clearAfrDataTable(JTable table) {
    while (AfrTableRowCount < table.getRowCount())
        Utils.removeRow(AfrTableRowCount, table);
    while (AfrTableColumnCount < table.getColumnCount())
        Utils.removeColumn(AfrTableColumnCount, table);
    Utils.clearTable(table);/*from   ww w. j a v a 2 s.  c  om*/
}