Example usage for javax.swing JTable getModel

List of usage examples for javax.swing JTable getModel

Introduction

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

Prototype

public TableModel getModel() 

Source Link

Document

Returns the TableModel that provides the data displayed by this JTable .

Usage

From source file:au.org.ala.delta.editor.ui.ActionSetsDialog.java

@Action
public void addDirectiveFile() {

    String name = _messageHelper.promptForDirectiveFileName();
    if (name != null) {
        int fileCount = _model.getDirectiveFileCount();
        DirectiveFile file = _model.addDirectiveFile(fileCount, name, selectedDirectiveType());
        updateGUI();/*from w ww  . ja v  a  2 s.c o m*/

        JTable selectedTable = (JTable) ((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
                .getView();
        DirectiveFileTableModel tm = (DirectiveFileTableModel) selectedTable.getModel();
        int newFileIndex = tm.indexOf(file);
        selectedTable.getSelectionModel().setSelectionInterval(newFileIndex, newFileIndex);

        editDirectiveFile();
    }
}

From source file:org.drugis.addis.gui.builder.NetworkMetaAnalysisView.java

private MouseAdapter treatmentCategorizationListener(final NetworkRelativeEffectTableCellRenderer renderer) {
    return new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                JTable table = (JTable) e.getComponent();
                int row = table.convertRowIndexToModel(table.rowAtPoint(e.getPoint()));
                int col = table.convertColumnIndexToModel(table.columnAtPoint(e.getPoint()));
                if (col == row) {
                    Treatment treatment = renderer.getTreatment(table.getModel(), col);
                    TreatmentDefinition treatmentDefinition = d_pm.getTreatmentDefinition(treatment);
                    Category category = treatmentDefinition.getContents().first();
                    if (category != null && !category.isTrivial()) {
                        d_mainWindow.leftTreeFocus(category.getCategorization());
                    }//from   w w w .j a v a 2s .  c om
                }
            }
        }
    };
}

From source file:frames.MainGUI.java

public String getTableRow(JTable j, int row) {
    DefaultTableModel model = (DefaultTableModel) j.getModel();
    int count = model.getColumnCount();
    String s = "";
    for (int i = 0; i < count; i++) {
        s += model.getValueAt(row, i) + ",";
    }/*from   w w  w  .  ja va2s. c om*/
    s += "\n";
    return s;
}

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

private void addRow() {
    try {//from ww w. java 2 s  .  c  om
        JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent();
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        model.addRow(new String[] { null, "Name" + String.valueOf(model.getRowCount()), "Value" });
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Get the table model for a given subjective title. Mostly for testing.
 * // w ww. j av a2s .com
 * @return the table model or null if the specified title is not present
 */
public TableModel getTableModelForTitle(final String title) {
    final JTable table = getTableForTitle(title);
    if (null == table) {
        return null;
    } else {
        return table.getModel();
    }
}

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

public void showClassificationResult(JTable tableResult, JTable tablePreview, String[] knnValue,
        int rowCountData, JLabel labelSiswaIPA, JLabel labelSiswaIPS, JLabel labelKeterangan,
        JYearChooser jYearChooser1, JYearChooser jYearChooser2, int kValue) {
    DefaultTableModel tableModelResult = new DefaultTableModel();
    tableModelResult = (DefaultTableModel) tableResult.getModel();
    int jumlahSiswaIPA = 0;
    int jumlahSiswaIPS = 0;

    for (int i = 0; i < rowCountData; i++) {
        if (knnValue[i].equals("IPA")) {
            jumlahSiswaIPA = jumlahSiswaIPA + 1;
        } else if (knnValue[i].equalsIgnoreCase("IPS")) {
            jumlahSiswaIPS = jumlahSiswaIPS + 1;
        }//w  ww  .j a  va2 s . c  o  m

        String nis = tablePreview.getValueAt(i, 0).toString();
        String nama = tablePreview.getValueAt(i, 1).toString();
        String jenKel = tablePreview.getValueAt(i, 2).toString();
        String nilaiUN = tablePreview.getValueAt(i, 3).toString();
        String ptBindo = tablePreview.getValueAt(i, 4).toString();
        String ptMtk = tablePreview.getValueAt(i, 5).toString();
        String ptBing = tablePreview.getValueAt(i, 6).toString();
        String ptIpa = tablePreview.getValueAt(i, 7).toString();
        String minat = tablePreview.getValueAt(i, 8).toString();
        String jurusan = knnValue[i];
        Object[] resultData = { nis, nama, jenKel, nilaiUN, ptBindo, ptMtk, ptBing, ptIpa, minat, jurusan };
        tableModelResult.addRow(resultData);
    }
    tableResult.setModel(tableModelResult);
    labelSiswaIPA.setText(jumlahSiswaIPA + "");
    labelSiswaIPS.setText(jumlahSiswaIPS + "");
    labelKeterangan.setText("Hasil Klasifikasi Penjurusan Siswa Pada Tahun Ajaran " + jYearChooser1.getYear()
            + "/" + jYearChooser2.getYear() + ", dengan paramater K = " + kValue + " adalah sebagai berikut ");
}

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

private void pasteTable(Core[] ca) {
    try {//from  w w w  .  j a va 2 s.  c  om
        JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent();
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        int cnt = ca.length;
        if (cnt < 1)
            return;
        for (int i = 0; i < cnt; i++)
            model.addRow(new String[] { ca[i].type, ca[i].name, ca[i].value });
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

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

private void replaceTable(Core[] ca) {
    try {//from ww  w.  jav a  2  s .  com
        JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent();
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        while (model.getRowCount() > 0)
            model.removeRow(0);
        int cnt = ca.length;
        if (cnt < 1)
            return;
        for (int i = 0; i < cnt; i++)
            model.addRow(new String[] { ca[i].type, ca[i].name, ca[i].value });
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

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

private Core[] getContent(boolean selected) {
    try {/*from   w  w w. j  a va  2s.c  om*/
        JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent();
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        ListSelectionModel listModel = table.getSelectionModel();
        int cnt = model.getRowCount();
        if (cnt < 1)
            return null;
        ArrayList<Core> cl = new ArrayList<Core>();
        for (int i = 0; i < cnt; i++) {
            if (selected)
                if (!listModel.isSelectedIndex(i))
                    continue;
            cl.add(new Core((String) model.getValueAt(i, 0), (String) model.getValueAt(i, 1),
                    (String) model.getValueAt(i, 2)));
        }
        return cl.toArray(new Core[0]);
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
    return null;
}

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

private void deleteRows() {
    try {/*from   ww w  .jav a2  s  .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());
    }
}