List of usage examples for javax.swing JTable getModel
public TableModel getModel()
From source file:edu.ku.brc.specify.tasks.PluginsTask.java
/** * @param table//from ww w. j a v a 2 s.com */ protected void exportTable(final JTable table) { Hashtable<String, String> values = new Hashtable<String, String>(); ViewBasedDisplayDialog dlg = new ViewBasedDisplayDialog((Frame) UIRegistry.getTopWindow(), "SystemSetup", "ExcelExportInfo", null, getResourceString("EXCEL_EXPORT_INFO_TITLE"), getResourceString("Export"), null, // className, null, // idFieldName, true, // isEdit, 0); dlg.setData(values); dlg.setModal(true); dlg.setVisible(true); if (dlg.getBtnPressed() == ViewBasedDisplayIFace.OK_BTN) { dlg.getMultiView().getDataFromUI(); File file = new File(values.get("FilePath")); TableModel2Excel.convertToExcel(file, values.get("Title"), table.getModel()); } }
From source file:org.jas.gui.MainWindow.java
private void deleteALLRows(JTable descriptionTable) { DefaultTableModel model = (DefaultTableModel) descriptionTable.getModel(); for (int i = model.getRowCount() - 1; i >= 0; i--) { model.removeRow(i);/*from www .j a v a 2 s .com*/ } }
From source file:com.aw.swing.mvp.binding.component.BndSJTable.java
public void addTableModelListener(TableModelListener tableModelListener) { jTable.getModel().addTableModelListener(tableModelListener); JTable fixedTable = (JTable) jTable.getClientProperty(CP_FIXED_TABLE); if (fixedTable != null) { fixedTable.getModel().addTableModelListener(tableModelListener); }//from ww w . j av a 2 s . c om }
From source file:org.jas.gui.MainWindow.java
@EventMethod(Events.LOAD_METADATA) void onLoadMetadata(List<Metadata> metadatas) { JTable descriptionTable = getDescriptionTable(); DefaultTableModel model = (DefaultTableModel) descriptionTable.getModel(); for (Metadata metadata : metadatas) { int row = descriptionTable.getRowCount(); model.addRow(new Object[] { "", "", "", "", "", "", "", "" }); descriptionTable.setValueAt(metadata.getArtist(), row, ApplicationState.ARTIST_COLUMN); descriptionTable.setValueAt(metadata.getTitle(), row, ApplicationState.TITLE_COLUMN); descriptionTable.setValueAt(metadata.getAlbum(), row, ApplicationState.ALBUM_COLUMN); descriptionTable.setValueAt(metadata.getGenre(), row, ApplicationState.GENRE_COLUMN); descriptionTable.setValueAt(metadata.getYear(), row, ApplicationState.YEAR_COLUMN); descriptionTable.setValueAt(metadata.getTrackNumber(), row, ApplicationState.TRACK_NUMBER_COLUMN); descriptionTable.setValueAt(metadata.getTotalTracks(), row, ApplicationState.TOTAL_TRACKS_NUMBER_COLUMN); descriptionTable.setValueAt(metadata.getCdNumber(), row, ApplicationState.CD_NUMBER_COLUMN); descriptionTable.setValueAt(metadata.getTotalCds(), row, ApplicationState.TOTAL_CDS_NUMBER_COLUMN); if (metadata.isMetadataFromFile()) { descriptionTable.setValueAt(ApplicationState.NEW, row, ApplicationState.STATUS_COLUMN); metadataWithAlbum.add(metadata); getApplyButton().setEnabled(true); } else {//from w w w . jav a 2 s .c o m descriptionTable.setValueAt(ApplicationState.READY, row, ApplicationState.STATUS_COLUMN); } } }
From source file:com.smanempat.controller.ControllerEvaluation.java
private double[][] evaluationModel(JTable tableResult, JTable tableConfMatrix, JLabel totalAccuracy, JTable tableTahunTesting, JTable tableDataSetTesting, String[] knnValue, int nilaiK, JPanel panelChart) throws SQLException { int actIPA = 0; int actIPS = 0; int trueIPA = 0; int falseIPA = 0; int trueIPS = 0; int falseIPS = 0; int classIPA = 0; int classIPS = 0; double recIPA; double recIPS; double preIPA; double preIPS; double accuracy; DefaultTableModel tableModelConf = (DefaultTableModel) tableConfMatrix.getModel(); DefaultTableModel tableModelRes = (DefaultTableModel) tableResult.getModel(); String[] tempJurusan = getJurusanTest(tableTahunTesting, tableDataSetTesting); if (tableModelRes.getRowCount() != 0) { tableModelRes.setRowCount(0);/*ww w.j a v a 2 s.c o m*/ } for (int j = 0; j < tableDataSetTesting.getRowCount(); j++) { String nis = tableDataSetTesting.getValueAt(j, 0).toString(); String jurusan = tempJurusan[j]; String classified = knnValue[j]; Object[] tableContent = { nis, jurusan, classified }; tableModelRes.addRow(tableContent); tableResult.setModel(tableModelRes); } /*Hitung Jumlah Data Actual IPA dan IPS*/ for (int j = 0; j < tempJurusan.length; j++) { if (tempJurusan[j].equals("IPA")) { actIPA = actIPA + 1; } else if (tempJurusan[j].equals("IPS")) { actIPS = actIPS + 1; } } /*Hitung Jumlah Data Classified IPA dan IPS*/ for (int j = 0; j < knnValue.length; j++) { if (tableResult.getValueAt(j, 1).equals("IPA")) { if (tableResult.getValueAt(j, 1).equals(tableResult.getValueAt(j, 2))) { trueIPA = trueIPA + 1; } else { falseIPS = falseIPS + 1; } } else if (tableResult.getValueAt(j, 1).equals("IPS")) { if (tableResult.getValueAt(j, 1).equals(tableResult.getValueAt(j, 2))) { trueIPS = trueIPS + 1; } else { falseIPA = falseIPA + 1; } } } // System.out.println("trueIPA =" + trueIPA); // System.out.println("falseIPA =" + falseIPA); // System.out.println("falseIPS =" + falseIPS); // System.out.println("trueIPS =" + trueIPS); /*Hitung Nilai Recall, Precision, dan Accuracy*/ preIPA = (double) trueIPA / (trueIPA + falseIPA); preIPS = (double) trueIPS / (trueIPS + falseIPS); recIPA = (double) trueIPA / (trueIPA + falseIPS); recIPS = (double) trueIPS / (trueIPS + falseIPA); accuracy = (double) (trueIPA + trueIPS) / (trueIPA + trueIPS + falseIPA + falseIPS); /*Tampung Nilai Recall, Precision, dan Accuracy*/ double[][] tempEval = new double[3][1]; tempEval[0][0] = accuracy; tempEval[1][0] = recIPA; tempEval[2][0] = preIPA; /*Set Nilai TF, TN, FP, FN ke Tabel Confusion Matrix*/ tableModelConf.setValueAt("Actual IPA", 0, 0); tableModelConf.setValueAt("Actual IPS", 1, 0); tableModelConf.setValueAt("Class Precision", 2, 0); tableModelConf.setValueAt(trueIPA, 0, 1); tableModelConf.setValueAt(falseIPS, 0, 2); tableModelConf.setValueAt(falseIPA, 1, 1); tableModelConf.setValueAt(trueIPS, 1, 2); /*Set Nilai Recall, Precision, dan Accuracy ke Tabel Confusion Matrix*/ if (Double.isNaN(preIPA)) { tableModelConf.setValueAt("NaN" + " %", 2, 1); } else { tableModelConf.setValueAt(df.format(preIPA * 100) + " %", 2, 1); } if (Double.isNaN(preIPS)) { tableModelConf.setValueAt("NaN" + " %", 2, 2); } else { tableModelConf.setValueAt(df.format(preIPS * 100) + " %", 2, 2); } if (Double.isNaN(recIPA)) { tableModelConf.setValueAt("NaN" + " %", 0, 3); } else { tableModelConf.setValueAt(df.format(recIPA * 100) + " %", 0, 3); } if (Double.isNaN(recIPS)) { tableModelConf.setValueAt("NaN" + " %", 1, 3); } else { tableModelConf.setValueAt(df.format(recIPS * 100) + " %", 1, 3); } if (Double.isNaN(accuracy)) { totalAccuracy.setText("Overall Accuracy is " + "NaN" + " %"); } else { totalAccuracy.setText("Overall Accuracy is " + df.format(accuracy * 100) + " %"); } // System.out.println("Recall IPA = " + recIPA); // System.out.println("Recall IPA =" + recIPS); // System.out.println("Precision IPA = " + preIPA); // System.out.println("Precision IPS = " + preIPS); // System.out.println("Overall Accuracy = " + accuracy); return tempEval; }
From source file:lob.VisualisationGUI.java
public void clearTable(final JTable table) { DefaultTableModel dm = (DefaultTableModel) table.getModel(); for (int i = 0; i < dm.getRowCount(); i++) { for (int j = 0; j < dm.getColumnCount(); j++) { dm.setValueAt("", i, j); }/* w w w .j a v a 2 s.co m*/ } }
From source file:com.vgi.mafscaling.LogView.java
private void createLogViewPanel() { logViewPanel = new JPanel(); GridBagLayout gbl_logViewPanel = new GridBagLayout(); gbl_logViewPanel.columnWidths = new int[] { 0 }; gbl_logViewPanel.rowHeights = new int[] { 0, 0 }; gbl_logViewPanel.columnWeights = new double[] { 1.0 }; gbl_logViewPanel.rowWeights = new double[] { 1.0, 0.0 }; logViewPanel.setLayout(gbl_logViewPanel); try {//from www . j a v a 2s .c o m logDataTable = new DBTable(); logDataTable.copyColumnHeaderNames = true; logDataTable.defaultClickCountToStartEditor = 2; logDataTable.doNotUseDatabaseSort = true; logDataTable.listenKeyPressEventsWholeWindow = true; logDataTable.createControlPanel(DBTable.READ_NAVIGATION); logDataTable.enableExcelCopyPaste(); logDataTable.setSortEnabled(false); logDataTable.setSkin(new TableSkin()); logDataTable.refresh(new String[1][25]); logDataTable.setComparator(new DoubleComparator()); logDataTable.getTable().setCellSelectionEnabled(true); logDataTable.getTable().setColumnSelectionAllowed(true); logDataTable.getTable().setRowSelectionAllowed(true); logDataTable.getTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JTextField rowTextField = ((JTextField) logDataTable.getControlPanel().getComponent(3)); rowTextField.setPreferredSize(null); rowTextField.setColumns(5); GridBagConstraints gbc_logDataTable = new GridBagConstraints(); gbc_logDataTable.insets = insets0; gbc_logDataTable.anchor = GridBagConstraints.PAGE_START; gbc_logDataTable.fill = GridBagConstraints.BOTH; gbc_logDataTable.gridx = 0; gbc_logDataTable.gridy = 0; logViewPanel.add(logDataTable, gbc_logDataTable); listModel = new DefaultListModel<JLabel>(); selectionCombo.removeAllItems(); String name; JTableHeader tableHeader = logDataTable.getTableHeader(); for (int i = 0; i < logDataTable.getColumnCount(); ++i) { Column col = logDataTable.getColumn(i); col.setNullable(true); col.setHeaderRenderer(new CheckboxHeaderRenderer(i + 1, tableHeader)); name = col.getHeaderValue().toString(); selectionCombo.addItem(name); listModel.addElement(new JLabel(name, new CheckBoxIcon(), JLabel.LEFT)); } JList<JLabel> menuList = new JList<JLabel>(listModel); menuList.setOpaque(false); menuList.setCellRenderer(new ImageListCellRenderer()); menuList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); menuList.setLayoutOrientation(JList.VERTICAL); menuList.setFixedCellHeight(25); menuList.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { if (e.getClickCount() == 1 && colors.size() > 0) { JList<?> list = (JList<?>) e.getSource(); int index = list.locationToIndex(e.getPoint()); if (index >= 0) { int colIdx = logDataTable.getCurrentIndexForOriginalColumn(index); Column col = logDataTable.getColumn(colIdx); if (col.getHeaderRenderer() instanceof CheckboxHeaderRenderer) { CheckboxHeaderRenderer renderer = (CheckboxHeaderRenderer) col .getHeaderRenderer(); JLabel label = (JLabel) list.getModel().getElementAt(index); CheckBoxIcon checkIcon = (CheckBoxIcon) label.getIcon(); checkIcon.setChecked(!checkIcon.isChecked()); if (checkIcon.isChecked()) { checkIcon.setColor(colors.pop()); JTable table = logDataTable.getTable(); TableModel model = table.getModel(); addXYSeries(model, index, col.getHeaderValue().toString(), checkIcon.getColor()); } else { colors.push(checkIcon.getColor()); checkIcon.setColor(renderer.getDefaultColor()); removeXYSeries(index); } list.repaint(); } } } } catch (Exception ex) { ex.printStackTrace(); } } }); headerScrollPane = new JScrollPane(menuList); GridBagConstraints gbc_headersTree = new GridBagConstraints(); gbc_headersTree.insets = insets0; gbc_headersTree.anchor = GridBagConstraints.PAGE_START; gbc_headersTree.fill = GridBagConstraints.BOTH; gbc_headersTree.gridx = 0; gbc_headersTree.gridy = 1; logViewPanel.add(headerScrollPane, gbc_headersTree); headerScrollPane.setVisible(false); } catch (Exception e) { e.printStackTrace(); logger.error(e); } }
From source file:com.smanempat.controller.ControllerEvaluation.java
private double[][] evaluationModel(JTable tableResult, JTable tableConfMatrix, JLabel totalAccuracy, JTable tableTahunTesting, JTable tableDataSetTesting, String[] knnValue, int i, int[] tempK, JPanel panelChart) throws SQLException { int actIPA = 0; int actIPS = 0; int trueIPA = 0; int falseIPA = 0; int trueIPS = 0; int falseIPS = 0; double recIPA; double recIPS; double preIPA; double preIPS; double accuracy; DefaultTableModel tableModelRes = new DefaultTableModel(); tableModelRes = (DefaultTableModel) tableResult.getModel(); String[] tempJurusan = getJurusanTest(tableTahunTesting, tableDataSetTesting); for (int j = 0; j < tableDataSetTesting.getRowCount(); j++) { String nis = tableDataSetTesting.getValueAt(j, 0).toString(); String jurusan = tempJurusan[j]; String classified = knnValue[j]; Object[] tableContent = { nis, jurusan, classified }; tableModelRes.addRow(tableContent); tableResult.setModel(tableModelRes); }//from w w w .j ava 2 s.c o m /*Hitung Jumlah Data Actual IPA dan IPS*/ for (int j = 0; j < tempJurusan.length; j++) { if (tempJurusan[j].equals("IPA")) { actIPA = actIPA + 1; } else if (tempJurusan[j].equals("IPS")) { actIPS = actIPS + 1; } } /*Hitung Jumlah Data Classified IPA dan IPS*/ for (int j = 0; j < knnValue.length; j++) { if (tableResult.getValueAt(j, 1).equals("IPA")) { if (tableResult.getValueAt(j, 1).equals(tableResult.getValueAt(j, 2))) { trueIPA = trueIPA + 1; } else { falseIPS = falseIPS + 1; } } else if (tableResult.getValueAt(j, 1).equals("IPS")) { if (tableResult.getValueAt(j, 1).equals(tableResult.getValueAt(j, 2))) { trueIPS = trueIPS + 1; } else { falseIPA = falseIPA + 1; } } } /*Hitung Nilai Recall, Precision, dan Accuracy*/ preIPA = (double) trueIPA / (trueIPA + falseIPA); preIPS = (double) trueIPS / (trueIPS + falseIPS); recIPA = (double) trueIPA / (trueIPA + falseIPS); recIPS = (double) trueIPS / (trueIPS + falseIPA); accuracy = (double) (trueIPA + trueIPS) / (trueIPA + trueIPS + falseIPA + falseIPS); /*Tampung Nilai Recall, Precision, dan Accuracy*/ double[][] tempEval = new double[3][tempK.length]; tempEval[0][i] = accuracy; tempEval[1][i] = recIPA; tempEval[2][i] = preIPA; /*Set Nilai TF, TN, FP, FN ke Tabel Confusion Matrix*/ tableConfMatrix.setValueAt("Actual IPA", 0, 0); tableConfMatrix.setValueAt("Actual IPS", 1, 0); tableConfMatrix.setValueAt("Class Precision", 2, 0); tableConfMatrix.setValueAt(trueIPA, 0, 1); tableConfMatrix.setValueAt(falseIPS, 0, 2); tableConfMatrix.setValueAt(falseIPA, 1, 1); tableConfMatrix.setValueAt(trueIPS, 1, 2); /*Set Nilai Recall, Precision, dan Accuracy ke Tabel Confusion Matrix*/ if (Double.isNaN(preIPA)) { tableConfMatrix.setValueAt("NaN" + " %", 2, 1); } else { tableConfMatrix.setValueAt(df.format(preIPA * 100) + " %", 2, 1); } if (Double.isNaN(preIPS)) { tableConfMatrix.setValueAt("NaN" + " %", 2, 2); } else { tableConfMatrix.setValueAt(df.format(preIPS * 100) + " %", 2, 2); } if (Double.isNaN(recIPA)) { tableConfMatrix.setValueAt("NaN" + " %", 0, 3); } else { tableConfMatrix.setValueAt(df.format(recIPA * 100) + " %", 0, 3); } if (Double.isNaN(recIPS)) { tableConfMatrix.setValueAt("NaN" + " %", 1, 3); } else { tableConfMatrix.setValueAt(df.format(recIPS * 100) + " %", 1, 3); } if (Double.isNaN(accuracy)) { totalAccuracy.setText("Overall Accuracy is " + "NaN" + " %"); } else { totalAccuracy.setText("Overall Accuracy is " + df.format(accuracy * 100) + " %"); } tableModelRes.setRowCount(0); return tempEval; }
From source file:frames.MainGUI.java
public void LoadFeeDataToJTable(JTable t, File file) { try {/*from w w w.j ava 2s. co m*/ CSVParser parser = CSVParser.parse(file, Charset.forName("UTF-8"), CSVFormat.DEFAULT); //t.setModel(tm); DefaultTableModel model = new DefaultTableModel(); //model.setRowCount(0); for (CSVRecord c : parser) { if (c.getRecordNumber() == 1) { model.addColumn(c.get(datatype.GlobalVariable.TYPE)); model.addColumn(c.get(datatype.GlobalVariable.AMOUNT)); model.addColumn(c.get(datatype.GlobalVariable.PAID_BY)); model.addColumn(c.get(datatype.GlobalVariable.PAYER)); t.setModel(model); model = (DefaultTableModel) t.getModel(); continue; } model.addRow( new Object[] { c.get(datatype.GlobalVariable.TYPE), c.get(datatype.GlobalVariable.AMOUNT), c.get(datatype.GlobalVariable.PAID_BY), c.get(datatype.GlobalVariable.PAYER) }); } } catch (Exception e) { System.out.println(e); } }
From source file:net.sf.jabref.importer.ZipFileChooser.java
/** * New Zip file chooser.// w ww . j av a2 s .co m * * @param owner Owner of the file chooser * @param zipFile Zip-Fle to choose from, must be readable */ public ZipFileChooser(ImportCustomizationDialog importCustomizationDialog, ZipFile zipFile) { super(importCustomizationDialog, Localization.lang("Select file from ZIP-archive"), false); ZipFileChooserTableModel tableModel = new ZipFileChooserTableModel(zipFile, getSelectableZipEntries(zipFile)); JTable table = new JTable(tableModel); TableColumnModel cm = table.getColumnModel(); cm.getColumn(0).setPreferredWidth(200); cm.getColumn(1).setPreferredWidth(150); cm.getColumn(2).setPreferredWidth(100); JScrollPane sp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setPreferredScrollableViewportSize(new Dimension(500, 150)); if (table.getRowCount() > 0) { table.setRowSelectionInterval(0, 0); } // cancel: no entry is selected JButton cancelButton = new JButton(Localization.lang("Cancel")); cancelButton.addActionListener(e -> dispose()); // ok: get selected class and check if it is instantiable as an importer JButton okButton = new JButton(Localization.lang("OK")); okButton.addActionListener(e -> { int row = table.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(this, Localization.lang("Please select an importer.")); } else { ZipFileChooserTableModel model = (ZipFileChooserTableModel) table.getModel(); ZipEntry tempZipEntry = model.getZipEntry(row); CustomImporter importer = new CustomImporter(); importer.setBasePath(model.getZipFile().getName()); String className = tempZipEntry.getName().substring(0, tempZipEntry.getName().lastIndexOf('.')) .replace("/", "."); importer.setClassName(className); try { ImportFormat importFormat = importer.getInstance(); importer.setName(importFormat.getFormatName()); importer.setCliId(importFormat.getId()); importCustomizationDialog.addOrReplaceImporter(importer); dispose(); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException exc) { LOGGER.warn("Could not instantiate importer: " + importer.getName(), exc); JOptionPane.showMessageDialog(this, Localization.lang("Could not instantiate %0 %1", importer.getName() + ":\n", exc.getMessage())); } } }); // Key bindings: JPanel mainPanel = new JPanel(); //ActionMap am = mainPanel.getActionMap(); //InputMap im = mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); //im.put(Globals.getKeyPrefs().getKey(KeyBinds.CLOSE_DIALOG), "close"); //am.put("close", closeAction); mainPanel.setLayout(new BorderLayout()); mainPanel.add(sp, BorderLayout.CENTER); JPanel optionsPanel = new JPanel(); optionsPanel.add(okButton); optionsPanel.add(cancelButton); optionsPanel.add(Box.createHorizontalStrut(5)); getContentPane().add(mainPanel, BorderLayout.CENTER); getContentPane().add(optionsPanel, BorderLayout.SOUTH); this.setSize(getSize()); pack(); this.setLocationRelativeTo(importCustomizationDialog); new FocusRequester(table); }