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:edu.ku.brc.specify.config.FixAttachments.java

/**
 * @param tableList//  ww w.ja v a 2 s. co m
 * @param tableIdList
 * @param resultsHashMap
 * @param tblTypeHash
 * @param tableHash
 * @param totalFiles
 */
private void displayBadAttachments(final ArrayList<JTable> tableList, final ArrayList<Integer> tableIdList,
        final HashMap<Integer, Vector<Object[]>> resultsHashMap, final HashMap<Integer, String> tblTypeHash,
        final HashMap<Integer, AttchTableModel> tableHash, final int totalFiles) {
    CellConstraints cc = new CellConstraints();

    int maxWidth = 200;
    int y = 1;
    String rowDef = tableList.size() == 1 ? "f:p:g"
            : UIHelper.createDuplicateJGoodiesDef("p", "10px", tableList.size());
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", rowDef));
    if (tableList.size() > 1) {
        int i = 0;
        for (JTable table : tableList) {
            Integer tblId = tableIdList.get(i++);
            int numRows = table.getModel().getRowCount();

            PanelBuilder pb2 = new PanelBuilder(new FormLayout("f:p:g", "p,2px,f:p:g"));
            if (resultsHashMap.size() > 1) {
                UIHelper.calcColumnWidths(table, numRows < 15 ? numRows + 1 : 15, maxWidth);
            } else {
                UIHelper.calcColumnWidths(table, 15, maxWidth);
            }
            pb2.addSeparator(tblTypeHash.get(tblId), cc.xy(1, 1));
            pb2.add(UIHelper.createScrollPane(table), cc.xy(1, 3));
            pb.add(pb2.getPanel(), cc.xy(1, y));
            y += 2;
        }
    } else {
        UIHelper.calcColumnWidths(tableList.get(0), 15, maxWidth);
        pb.add(UIHelper.createScrollPane(tableList.get(0)), cc.xy(1, 1));
    }
    tableList.clear();

    pb.setDefaultDialogBorder();

    JScrollPane panelSB = UIHelper.createScrollPane(pb.getPanel());
    panelSB.setBorder(BorderFactory.createEmptyBorder());
    Dimension dim = panelSB.getPreferredSize();
    panelSB.setPreferredSize(new Dimension(dim.width + 10, 600));

    final int totFiles = totalFiles;
    String title = String.format("Attachment Information - %d files to recover.", totalFiles);
    CustomDialog dlg = new CustomDialog((Dialog) null, title, true, CustomDialog.OKCANCELAPPLYHELP, panelSB) {
        @Override
        protected void helpButtonPressed() {
            File file = produceSummaryReport(resultsHashMap, tableHash, totFiles);
            try {
                AttachmentUtils.openURI(file.toURI());
            } catch (Exception e) {
            }
        }

        @Override
        protected void applyButtonPressed() {
            boolean isOK = UIRegistry.displayConfirm("Clean up",
                    "Are you sure you want to remove all references to the missing attachments?", "Remove",
                    "Cancel", JOptionPane.WARNING_MESSAGE);
            if (isOK) {
                super.applyButtonPressed();
            }
        }
    };

    dlg.setCloseOnApplyClk(true);
    dlg.setCancelLabel("Skip");
    dlg.setOkLabel("Recover Files");
    dlg.setHelpLabel("Show Summary");
    dlg.setApplyLabel("Delete References");
    dlg.createUI();
    dlg.pack();

    dlg.setVisible(true);

    if (dlg.getBtnPressed() == CustomDialog.OK_BTN) {
        reattachFiles(resultsHashMap, tableHash, totalFiles);

    } else if (dlg.getBtnPressed() == CustomDialog.APPLY_BTN) {
        doAttachmentRefCleanup(resultsHashMap, tableHash, totFiles);
    }

}

From source file:Software_Jframes.chart.java

void print_pdf_report(JTable jTable5) {
    Access ac = new Access();
    try {/*from  w ww  .  j a v  a  2s .c o m*/
        String filename = ac.chooseFile();

        com.itextpdf.text.Document document = new com.itextpdf.text.Document();
        PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf"));

        document.open();
        document.add(new Paragraph(""));

        Image image1 = Image.getInstance("src/images/ROPA_Logo_without_claim.jpg");
        document.add(new Paragraph(""));
        image1.scaleAbsolute(80, 50);
        image1.setAbsolutePosition(50, 800);

        document.add(image1);
        PdfPTable table = new PdfPTable(3); // 3 columns.

        DefaultTableModel dtm = (DefaultTableModel) jTable5.getModel();
        Vector v = new Vector();
        int count_row = dtm.getRowCount();
        int count_col = dtm.getColumnCount();

        for (int i = 0; i < count_row; i++) {
            for (int j = 0; j < count_col; j++) {

                table.addCell(new PdfPCell(new Paragraph(dtm.getValueAt(i, j) + "")));

            }
        }
        table.setWidthPercentage(100);
        float[] columnWidths = { 2f, 1f, 1f };

        table.setWidths(columnWidths);

        document.add(table);
        document.close();
        JOptionPane.showMessageDialog(null, "Successfully Created.");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

private void addRow() {
    try {/*from   w ww .j  av a  2  s .  c  o  m*/
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        model.addRow(new String[] { "Name" + String.valueOf(model.getRowCount()), "Value" });
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

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:com.smanempat.controller.ControllerEvaluation.java

public void showTahunAjaran(JTable tableTahunModel, JTable tableTahunTesting) {
    modelEvaluation = new ModelEvaluation();
    try {//from  w  ww .ja v  a  2 s . c o m
        tableModel1 = (DefaultTableModel) tableTahunModel.getModel();
        tableModel2 = (DefaultTableModel) tableTahunTesting.getModel();
        modelEvaluation.selectTahunAjaran();
        for (int i = 0; i < modelEvaluation.getTahunAjaran().size(); i++) {
            tableModel1.addRow(new Object[] { modelEvaluation.getTahunAjaran().get(i), false });
            tableModel2.addRow(new Object[] { modelEvaluation.getTahunAjaran().get(i), false });
        }
        tableTahunModel.setModel(tableModel1);
        tableTahunTesting.setModel(tableModel2);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:de.codesourcery.eve.skills.ui.components.impl.RefiningComponent.java

private Collection<Object> getSelectedRows(JTable table) {
    final Collection<Object> result = new ArrayList<Object>();

    final int[] rows = table.getSelectedRows();
    final TableModel tableModel = table.getModel();
    for (int viewRow : rows) {

        final int modelRow = table.convertRowIndexToModel(viewRow);

        if (tableModel == refinedItemsModel) {
            result.add(refinedItemsModel.getRow(modelRow));
        } else if (tableModel == this.refiningResultsModel) {
            result.add(refiningResultsModel.getRow(modelRow));
        } else {//from  www . j  ava 2  s.  c  o  m
            throw new IllegalArgumentException("Internal error - table has unsupported model");
        }
    }
    return result;
}

From source file:maltcms.ui.fileHandles.csv.CSVTableView.java

private HashMap<String, Integer> getLabelToIndex(JTable jt, int labelColumn) {
    HashSet<String> hm = new LinkedHashSet<>();
    for (int i = 0; i < jt.getRowCount(); i++) {
        hm.add(String.valueOf(jt.getModel().getValueAt(i, labelColumn)));
    }//w  w w.j a v  a  2 s . c om
    HashMap<String, Integer> placeMap = new LinkedHashMap<>();
    int cnt = 0;
    for (String s : hm) {
        Logger.getLogger(getClass().getName()).log(Level.INFO, "Label: {0}", s);
        placeMap.put(s, cnt++);
    }
    return placeMap;
}

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

private void copy(boolean cut) {
    try {/* w  w w.  j  ava2s. 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 {//from w  ww.  ja  va2  s  .  co  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.smanempat.controller.ControllerEvaluation.java

public void showDataSetModel(JTable tableDataSetModel, JTable tableTahunModel, JLabel totalDataModel)
        throws SQLException {
    int row;/*from   w ww.ja v a 2  s.  c om*/
    int transMinat;
    tableModelDataSet1 = (DefaultTableModel) tableDataSetModel.getModel();
    row = tableModelDataSet1.getRowCount();
    for (int i = 0; i < row; i++) {
        tableModelDataSet1.removeRow(0);
    }
    row = tableTahunModel.getRowCount();
    boolean checkList;
    for (int i = 0; i < row; i++) {
        checkList = Boolean.valueOf("" + tableTahunModel.getValueAt(i, 1));
        if (checkList == true) {
            dbConnection = new DbConnection();
            connect = dbConnection.connect();
            query = "SELECT * FROM siswa WHERE tahun_ajaran = ?";
            pstmt = connect.prepareStatement(query);
            pstmt.setString(1, tableTahunModel.getValueAt(i, 0).toString());
            rs = pstmt.executeQuery();
            while (rs.next()) {
                String nis = rs.getString("nis");
                String nama = rs.getString("nama");
                String jenisKelamin = rs.getString("jenis_kelamin");
                String nilaiUN = rs.getString("nilai_un");
                double meanUN = Double.parseDouble(nilaiUN) / 4;
                String ptBindo = rs.getString("pt_bhs_indonesia");
                String ptMtk = rs.getString("pt_matematika");
                String ptBing = rs.getString("pt_bhs_inggris");
                String ptIpa = rs.getString("pt_ipa");
                double meanPt = (Double.parseDouble(ptBindo) + Double.parseDouble(ptMtk)
                        + Double.parseDouble(ptBing) + Double.parseDouble(ptIpa)) / 4;
                String minat = rs.getString("minat");
                if (minat.equals("IPA")) {
                    transMinat = 1;
                } else {
                    transMinat = 0;
                }
                String jurusan = rs.getString("jurusan");
                Object tableContent[] = { nis, nilaiUN, meanUN, ptBindo, ptMtk, ptBing, ptIpa, meanPt, minat,
                        transMinat, jurusan };
                tableModelDataSet1.addRow(tableContent);
            }
        }
        tableDataSetModel.setModel(tableModelDataSet1);
        totalDataModel.setText(tableDataSetModel.getRowCount() + " Data");
    }
}