Example usage for javax.swing.table DefaultTableModel getRowCount

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

Introduction

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

Prototype

public int getRowCount() 

Source Link

Document

Returns the number of rows in this data table.

Usage

From source file:StoreAdmin.ManageStoreJPanel.java

private void btntopfiveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btntopfiveActionPerformed
    DefaultTableModel dtm = (DefaultTableModel) tblsearchedproduct.getModel();
    dtm.getRowCount();

    System.out.println(dtm.getRowCount());

    if (dtm.getRowCount() < 4) {
        JOptionPane.showMessageDialog(null, "Inventory must have more than 4 products to plot the graph");

    } else {//  w w  w . j a  va  2s.  c om

        JFreeChart plotGraphInventory = ChartFactory.createBarChart("Top 5 products in Store", "Products",
                "Profit", plotGrapghInventory(), PlotOrientation.VERTICAL, true, true, false);

        ChartPanel chartPanel = new ChartPanel(plotGraphInventory);
        chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
        ChartFrame frame = new ChartFrame("Market Report", plotGraphInventory);
        frame.setVisible(true);
        frame.setSize(500, 270);
    } //GEN-LAST:event_btntopfiveActionPerformed
}

From source file:com.stanley.captioner.MainFrame.java

private void addButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addButtonActionPerformed
{//GEN-HEADEREND:event_addButtonActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setMultiSelectionEnabled(true);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("MP4 VIDEOS", "mp4", "mpeg");
    fileChooser.setFileFilter(filter);//from  w  w  w . ja  v  a2s.  c om
    if (lastAddDirectory != null) {
        fileChooser.setCurrentDirectory(lastAddDirectory);
    }
    int returnValue = fileChooser.showOpenDialog(this);

    if (returnValue == JFileChooser.APPROVE_OPTION) {
        lastAddDirectory = fileChooser.getCurrentDirectory();

        DefaultTableModel model = (DefaultTableModel) videoTable.getModel();
        File files[] = fileChooser.getSelectedFiles();
        for (File file : files) {
            boolean alreadyExists = false;
            for (int i = model.getRowCount() - 1; i >= 0; i--) {
                String path = (String) model.getValueAt(i, 0);
                if (file.getAbsolutePath().equals(path)) {
                    alreadyExists = true;
                }
            }

            if (!alreadyExists) {
                model.addRow(getVideoInfo(file));
            }
        }
    }
}

From source file:com.mirth.connect.client.ui.attachments.RegexAttachmentDialog.java

private void closeButtonActionPerformed(ActionEvent evt) {
    if (regexTable.isEditing()) {
        regexTable.getCellEditor().stopCellEditing();
    }/*w  w w  .  j  a va 2s  .  co m*/
    if (inboundReplacementTable.isEditing()) {
        inboundReplacementTable.getCellEditor().stopCellEditing();
    }
    if (outboundReplacementTable.isEditing()) {
        outboundReplacementTable.getCellEditor().stopCellEditing();
    }

    attachmentHandlerProperties.getProperties().clear();

    for (int row = 0; row < regexTable.getModel().getRowCount(); row++) {
        String regex = (String) regexTable.getModel().getValueAt(row, 0);
        String mimeType = (String) regexTable.getModel().getValueAt(row, 1);

        attachmentHandlerProperties.getProperties().put("regex.pattern" + row, regex);
        attachmentHandlerProperties.getProperties().put("regex.mimetype" + row, mimeType);
    }

    DefaultTableModel inboundTableModel = (DefaultTableModel) inboundReplacementTable.getModel();
    for (int row = 0; row < inboundTableModel.getRowCount(); row++) {
        String replaceKey = (String) inboundTableModel.getValueAt(row, 0);
        String replaceValue = (String) inboundTableModel.getValueAt(row, 1);

        attachmentHandlerProperties.getProperties().put("regex.replaceKey" + row, replaceKey);
        attachmentHandlerProperties.getProperties().put("regex.replaceValue" + row, replaceValue);
    }

    DefaultTableModel outboundTableModel = (DefaultTableModel) outboundReplacementTable.getModel();
    for (int row = 0; row < outboundTableModel.getRowCount(); row++) {
        String replaceKey = (String) outboundTableModel.getValueAt(row, 0);
        String replaceValue = (String) outboundTableModel.getValueAt(row, 1);

        attachmentHandlerProperties.getProperties().put("outbound.regex.replaceKey" + row, replaceKey);
        attachmentHandlerProperties.getProperties().put("outbound.regex.replaceValue" + row, replaceValue);
    }

    attachmentHandlerProperties = null;
    parent.setSaveEnabled(true);
    this.dispose();
}

From source file:view.ResultsPanel.java

public void setTable(int nbMode, List<ElementaryMode> modes) {

    ElementaryMode mode = modes.get(nbMode);

    DefaultTableModel model = (DefaultTableModel) modeTable.getModel();

    while (model.getRowCount() > 0) {
        model.removeRow(0);/*from w  w w  . j  a  v a2  s  .  c  o m*/
    }

    Map<Reaction, Double> map = mode.getContent();
    for (Reaction key : map.keySet()) {

        model.addRow(new Object[] { map.get(key), key.getName(), key.getStringReaction() });

    }

    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(modeTable.getModel());
    modeTable.setRowSorter(sorter);
    modeTable.getTableHeader().setReorderingAllowed(false);

    searchField.getDocument().addDocumentListener(new MyDocumentListener(searchField, sorter, 1, 2));

    searchField.setText(searchField.getText());

}

From source file:ca.uviccscu.lp.server.main.MainFrame.java

public static void wipeGameTableRows() {
    DefaultTableModel md = (DefaultTableModel) jTable1.getModel();
    int lim = md.getRowCount();
    for (int i = 0; i < lim; i++) {
        md.removeRow(0);/*  w  w w .jav  a 2s.  c  om*/
    }
}

From source file:ca.uviccscu.lp.server.main.MainFrame.java

public static void wipeNetworkTableRows() {
    DefaultTableModel md = (DefaultTableModel) jTable2.getModel();
    int lim = md.getRowCount();
    for (int i = 0; i < lim; i++) {
        md.removeRow(0);/* w w  w  .  jav a  2s  .  c  o m*/
    }
}

From source file:Import.pnl_import_vcf.java

public Object[] getMapPair(DefaultTableModel model) {
    ArrayList<String> list1 = new ArrayList<>();
    ArrayList<String> list2 = new ArrayList<>();
    for (int i = 0; i < model.getRowCount(); i++) {
        list1.add(model.getValueAt(i, 0).toString());
        list2.add(model.getValueAt(i, 1).toString());
    }/*from   w  w  w. ja  v a  2 s .c o m*/
    String[] array1 = list1.toArray(new String[list1.size()]);
    String[] array2 = list2.toArray(new String[list2.size()]);
    Object[] o = { array1, array2 };
    return o;
}

From source file:gui.Grafico.java

/**
 *
 * @param expresion//from  w  ww . j a v  a 2  s .c o m
 * @param minX
 * @param maxX
 * <p/>
 * @throws CaracterIlegal
 */
public void graficar(String expresion, double minX, double maxX) throws CaracterIlegal {
    String nombreVariable = "";
    String[] rpn = Procesador.convertirRPN(expresion);

    for (String item : rpn) {
        if (Procesador.esVariable(item)) {
            if (nombreVariable.isEmpty()) {
                nombreVariable = item;
            } else if (!item.equals(nombreVariable)) {
                throw new CaracterIlegal(expresion, 0);
            }
        }
    }

    double[] valoresX = new double[1001];
    double[] valoresY = new double[1001];
    double iteradorDoubleX = minX;
    double pasoDouble = (maxX - minX) / 1000.0;

    for (int i = 0; i < valoresX.length; i++) {
        valoresX[i] = iteradorDoubleX;

        try {
            valoresY[i] = evaluarValor(Arrays.copyOf(rpn, rpn.length), nombreVariable, valoresX[i]);
        } catch (Exception e) {
            valoresY[i] = Double.NaN;
        }

        iteradorDoubleX += pasoDouble;
    }

    double pasoDoubleError = pasoDouble / 2;

    for (int i = 0; i < valoresY.length; i++) {
        if (valoresY[i] == Double.NaN) {
            double izquierdo = evaluarValor(Arrays.copyOf(rpn, rpn.length), nombreVariable,
                    valoresX[i] - pasoDoubleError);
            double derecho = evaluarValor(Arrays.copyOf(rpn, rpn.length), nombreVariable,
                    valoresX[i] + pasoDoubleError);
            valoresY[i] = (izquierdo - derecho) / 2;
        }
    }

    //        System.out.println(Arrays.toString(valoresX));
    //        System.out.println(Arrays.toString(valoresY));
    DefaultTableModel modeloTablaDefecto = (DefaultTableModel) jTable1.getModel();

    if (ultimoNombre.length() > 0) {
        set.removeSeries(nombres.get(ultimoNombre));
        modeloTablaDefecto.setValueAt(false, modeloTablaDefecto.getRowCount() - 1, 0);
    }

    double[][] valores = new double[][] { valoresX, valoresY };
    String funcion = generarNombre() + "(" + nombreVariable + ") = "
            + Procesador.evaluarRPN(Procesador.convertirRPN(expresion)).toString();

    set.addSeries(funcion, valores);
    nombres.put(ultimoNombre, funcion);
    funciones.put(funcion, valores);

    modeloTablaDefecto.addRow(new Object[] { true, funcion });
    jPanel2.repaint();

    setVisible(true);
}

From source file:Main.java

public Main() {
    DefaultTableModel model = new DefaultTableModel(0, 5) {
        @Override/*from w w  w . j a  v a2s.c  o  m*/
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    JTable table = new JTable(model);
    for (int i = 0; i < 20; i++) {
        model.addRow(new String[] { i + ".1", i + ".2", i + ".3", i + ".4", i + ".5", });
    }
    add(table, BorderLayout.CENTER);
    table.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            System.out.println("pressed");
            char key = e.getKeyChar();
            int selectedColumn = table.getSelectedColumn();
            for (int i = 0; i < model.getRowCount(); i++) {
                String value = (String) model.getValueAt(i, selectedColumn);
                model.setValueAt(value + key, i, selectedColumn);
            }
        }
    });
}

From source file:view.ResultsPanel.java

public void displayFrame(final List<ElementaryMode> modes, final List<Integer> indices) {

    this.removeAll();

    DefaultTableModel model = (DefaultTableModel) modeTable.getModel();

    while (model.getRowCount() > 0) {
        model.removeRow(0);//from   w w w.  ja va2  s  .  co  m
    }

    if (modes.size() > 0) {
        setTable(0, modes);
    }
    JLabel nbMod = new JLabel(modes.size() + " mode(s) found");

    toolbar = new JToolBar();
    // set elements in the toolbar
    toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.LINE_AXIS));
    toolbar.add(nbMod);
    toolbar.setFloatable(false);

    Object[] comboElements = new Object[modes.size()];

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

        comboElements[i] = "mode " + indices.get(i);
    }

    modesCombo = new JComboBox(comboElements);

    if (modesCombo.getActionListeners().length > 0) {
        modesCombo.removeActionListener(modesCombo.getActionListeners()[0]);
    }
    modesCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setTable(modesCombo.getSelectedIndex(), modes);
        }
    });

    if (modes.size() > 0) {
        toolbar.add(modesCombo);
    }
    modesCombo.setMaximumSize(new Dimension(100, 30));

    //we put the right size for le comboBox
    int sizeMax = String.valueOf(modes.size()).length();

    String stringMax = "mode ";
    for (int i = 0; i < sizeMax; i++) {
        stringMax += "X";
    }

    modesCombo.setPrototypeDisplayValue(stringMax);

    if (download.getActionListeners().length > 0) {
        download.removeActionListener(download.getActionListeners()[0]);
    }
    download.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            Thread thread = new DownloadContentThread(modes, controler, command, log.getText());
            thread.start();

        }
    });

    if (histoButton.getActionListeners().length > 0) {
        histoButton.removeActionListener(histoButton.getActionListeners()[0]);
    }
    histoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            showHistogram(modes);

        }

    });

    toolbar.add(histoButton);
    toolbar.add(filterButton);
    toolbar.add(download);
    toolbar.add(scriptButton);
    if (!isAttached) {
        toolbar.add(addToProject);
    } else {
        toolbar.add(removeFromProject);
    }

    toolbar.add(Box.createHorizontalGlue());
    toolbar.add(searchField);
    toolbar.add(new JLabel(Var.iconsearch));

    JPanel logPanel = new JPanel(new BorderLayout());

    logPanel.add(new JLabel("Generetad log", JLabel.CENTER), BorderLayout.PAGE_START);
    logPanel.add(new JScrollPane(log), BorderLayout.CENTER);

    this.setLayout(new BorderLayout());

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(modeTable), logPanel);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(500);

    add(toolbar, BorderLayout.PAGE_START);
    this.add(splitPane, BorderLayout.CENTER);

    this.revalidate();
    this.repaint();
}