List of usage examples for javax.swing.table TableModel getValueAt
public Object getValueAt(int rowIndex, int columnIndex);
columnIndex
and rowIndex
. From source file:uk.ac.lkl.cram.ui.report.Report.java
private void addTutorPreparationHours() { MainDocumentPart mdp = wordMLPackage.getMainDocumentPart(); mdp.addStyledParagraphOfText("Heading2", "Tutor Preparation Hours"); Tbl table = factory.createTbl();// ww w .j ava 2 s . c o m Tr tableHead = factory.createTr(); TableModel tableModel = new TutorHoursTableModel(module); addTableCell(tableHead, tableModel.getColumnName(0), JcEnumeration.CENTER, true); for (int col = 1; col < 4; col++) { addTableCell(tableHead, tableModel.getColumnName(col), JcEnumeration.CENTER, true); } table.getContent().add(tableHead); for (int row = 0; row < tableModel.getRowCount(); row++) { boolean lastRow = row == tableModel.getRowCount() - 1; Tr tableRow = factory.createTr(); if (lastRow) { addTableCell(tableRow, tableModel.getValueAt(row, 0).toString(), JcEnumeration.LEFT, true); } else { addSimpleTableCell(tableRow, tableModel.getValueAt(row, 0).toString()); } for (int col = 1; col < 4; col++) { addTableCell(tableRow, FLOAT_FORMATTER.format(tableModel.getValueAt(row, col)), JcEnumeration.RIGHT, lastRow); } table.getContent().add(tableRow); } addBorders(table); mdp.addObject(table); }
From source file:uk.ac.lkl.cram.ui.report.Report.java
private void addTutorSupportHours() { MainDocumentPart mdp = wordMLPackage.getMainDocumentPart(); mdp.addStyledParagraphOfText("Heading2", "Tutor Support Hours"); Tbl table = factory.createTbl();// w w w. j a v a 2 s. c o m Tr tableHead = factory.createTr(); TableModel tableModel = new TutorHoursTableModel(module); addTableCell(tableHead, tableModel.getColumnName(0), JcEnumeration.CENTER, true); for (int col = 4; col < 7; col++) { addTableCell(tableHead, tableModel.getColumnName(col), JcEnumeration.CENTER, true); } table.getContent().add(tableHead); for (int row = 0; row < tableModel.getRowCount(); row++) { boolean lastRow = row == tableModel.getRowCount() - 1; Tr tableRow = factory.createTr(); if (lastRow) { addTableCell(tableRow, tableModel.getValueAt(row, 0).toString(), JcEnumeration.LEFT, true); } else { addSimpleTableCell(tableRow, tableModel.getValueAt(row, 0).toString()); } for (int col = 4; col < 7; col++) { addTableCell(tableRow, FLOAT_FORMATTER.format(tableModel.getValueAt(row, col)), JcEnumeration.RIGHT, lastRow); } table.getContent().add(tableRow); } addBorders(table); mdp.addObject(table); float[] tutor_hours_online = new float[3]; float[] tutor_hours_f2f = new float[3]; List<ModulePresentation> modulePresentations = module.getModulePresentations(); for (int i = 0; i < modulePresentations.size(); i++) { ModulePresentation mp = modulePresentations.get(i); for (TLALineItem tLALineItem : module.getTLALineItems()) { SupportTime st = tLALineItem.getSupportTime(mp); float tutor_hours = st.getTotalHours(module, mp, tLALineItem); StudentTeacherInteraction sti = tLALineItem.getActivity().getStudentTeacherInteraction(); if (sti.isOnline()) { tutor_hours_online[i] += tutor_hours; } if (sti.isTutorSupported() && sti.isLocationSpecific()) { tutor_hours_f2f[i] += tutor_hours; } } } mdp.addParagraphOfText(""); table = factory.createTbl(); tableHead = factory.createTr(); addSimpleTableCell(tableHead, ""); table.getContent().add(tableHead); for (int col = 4; col < 7; col++) { addTableCell(tableHead, tableModel.getColumnName(col), JcEnumeration.CENTER, true); } Tr tableRow = factory.createTr(); addSimpleTableCell(tableRow, "Tutor hours online"); for (int i = 0; i < tutor_hours_online.length; i++) { addTableCell(tableRow, INTEGER_FORMATTER.format(tutor_hours_online[i]), JcEnumeration.RIGHT, false); } table.getContent().add(tableRow); tableRow = factory.createTr(); addSimpleTableCell(tableRow, "Tutor hours face-to-face"); for (int i = 0; i < tutor_hours_f2f.length; i++) { addTableCell(tableRow, INTEGER_FORMATTER.format(tutor_hours_f2f[i]), JcEnumeration.RIGHT, false); } table.getContent().add(tableRow); addBorders(table); mdp.addObject(table); }
From source file:gdt.jgui.tool.JEntityEditor.java
private void save() { try {//from w w w.j a va 2 s . c o m int eCnt = tabbedPane.getComponentCount(); Sack candidate = new Sack(); String element$; JScrollPane scrollPane; JTable table; int rCnt; Core row; TableModel model; for (int i = 0; i < eCnt; i++) { element$ = tabbedPane.getTitleAt(i); candidate.createElement(element$); scrollPane = (JScrollPane) tabbedPane.getComponentAt(i); table = (JTable) scrollPane.getViewport().getView(); rCnt = table.getRowCount(); model = table.getModel(); for (int j = 0; j < rCnt; j++) { row = new Core((String) model.getValueAt(j, 0), (String) model.getValueAt(j, 1), (String) model.getValueAt(j, 2)); if ("attributes".equals(element$)) candidate.putAttribute(row); else candidate.putElementItem(element$, row); } } candidate.setKey(entityKey$); candidate.saveXML(entihome$ + "/" + Entigrator.ENTITY_BASE + "/data/" + entityKey$); } catch (Exception e) { LOGGER.severe(e.toString()); } }
From source file:mekhq.Utilities.java
/** * Export a JTable to a CSV file//from www . j a va2 s .co m * @param table * @param file * @return report */ public static String exportTabletoCSV(JTable table, File file) { String report; try { TableModel model = table.getModel(); BufferedWriter writer = Files.newBufferedWriter(Paths.get(file.getPath())); String[] columns = new String[model.getColumnCount()]; for (int i = 0; i < model.getColumnCount(); i++) { columns[i] = model.getColumnName(i); } CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT.withHeader(columns)); for (int i = 0; i < model.getRowCount(); i++) { Object[] towrite = new String[model.getColumnCount()]; for (int j = 0; j < model.getColumnCount(); j++) { // use regex to remove any HTML tags towrite[j] = model.getValueAt(i, j).toString().replaceAll("\\<[^>]*>", ""); } csvPrinter.printRecord(towrite); } csvPrinter.flush(); csvPrinter.close(); report = model.getRowCount() + " " + resourceMap.getString("RowsWritten.text"); } catch (Exception ioe) { MekHQ.getLogger().log(Utilities.class, "exportTabletoCSV", LogLevel.INFO, "Error exporting JTable"); report = "Error exporting JTable. See log for details."; } return report; }
From source file:GUI.DashbordAdminFrame.java
private void btnConsulterProduitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsulterProduitActionPerformed int i = tbProduits.getSelectedRow(); TableModel model = tbProduits.getModel(); Object l = tbProduits.getValueAt(i, 0); produit_id = (int) l; System.out.println(tbProduits); lNomProduit.setText(model.getValueAt(i, 1).toString()); lCategorie.setText(model.getValueAt(i, 2).toString()); lQuantite.setText(model.getValueAt(i, 3).toString()); lDescription.setText(model.getValueAt(i, 4).toString()); lPrix.setText(model.getValueAt(i, 5).toString()); lPointBonus.setText(model.getValueAt(i, 6).toString()); lZone.setText(model.getValueAt(i, 7).toString()); lTVA.setText(model.getValueAt(i, 9).toString()); lReduction.setText(model.getValueAt(i, 10).toString()); Produit p = pdao.findById(produit_id); tbCommProd.setModel(new CommentDPModel()); tbCommProd.setVisible(true);/* w ww . j a va 2 s . c o m*/ tbCommProd.getColumnModel().getColumn(0).setMinWidth(0); tbCommProd.getColumnModel().getColumn(0).setMaxWidth(0); tbCommProd.getColumnModel().getColumn(0).setWidth(0); produitPanel.removeAll(); produitPanel.add(ConsultationPanel); produitPanel.repaint(); produitPanel.revalidate(); }
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); }/* w w w . java 2 s . c o 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:gtu._work.mvn.MavenRepositoryUI.java
List<File> fetchPomDependencyTableJarList() { TableModel model = pomDenpendencyTable.getModel(); PomFile pomFile = null;/*from w w w . j a va2 s. c o m*/ List<File> list = new ArrayList<File>(); for (int ii = 0; ii < model.getRowCount(); ii++) { pomFile = (PomFile) model.getValueAt(ii, 3); if (pomFile != null && pomFile.jarFile != null && !list.contains(pomFile.jarFile)) { list.add(pomFile.jarFile); } } Collections.sort(list); return list; }
From source file:GUI.DashbordAdminFrame.java
private void btnConsulterS1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsulterS1ActionPerformed // TODO add your handling code here: int i = tblAllServices.getSelectedRow(); TableModel model = tblAllServices.getModel(); Object l = tblAllServices.getValueAt(i, 0); service_id = (int) l; System.out.println(service_id); tbCommentairesService.setModel(new CommentSModel()); tbCommentairesService.setVisible(true); lNomSAll.setText(model.getValueAt(i, 1).toString()); lDescriptionSAll.setText(model.getValueAt(i, 2).toString()); lCategorieServiceAll.setText(tblAllServices.getValueAt(i, 3).toString()); lEtatSAll.setText(tblAllServices.getValueAt(i, 4).toString()); lZoneSAll.setText(model.getValueAt(i, 5).toString()); Service s = sdao.findById(service_id); System.out.println(s.getZone()); pShowMap.setLayout(new BorderLayout()); //pShowMap.add(view.getComponent(0), BorderLayout.CENTER); java.util.List<Zone> obj = new ArrayList(); obj = sdao.findByZone(s.getZone());/*from ww w. ja v a 2s . c o m*/ double x; double y; for (Object o : obj) { x = ((Zone) o).getLat(); y = ((Zone) o).getLon(); System.out.println(x + "dddddddddd" + y); //browser.loadURL("https://maps.googleapis.com/maps/api/staticmap?center=" + x + "," + y + "&zoom=12&size=700x500&maptype=roadmap&markers=icone%7Clabel:S%7C" + x + "," + y); } tbCommentairesService.setModel(new CommentDSModel()); tbCommentairesService.setVisible(true); tbCommentairesService.getColumnModel().getColumn(0).setMinWidth(0); tbCommentairesService.getColumnModel().getColumn(0).setMaxWidth(0); tbCommentairesService.getColumnModel().getColumn(0).setWidth(0); ServicePanel.removeAll(); ServicePanel.add(pConsulterS2); ServicePanel.repaint(); ServicePanel.revalidate(); }
From source file:org.jas.gui.MainWindow.java
private int getRow(Metadata metadataTarget) { TableModel model = getDescriptionTable().getModel(); List<Metadata> metadataList = viewEngineConfigurator.getViewEngine().get(Model.METADATA); for (int i = 0; i < model.getRowCount(); i++) { String artist = (String) model.getValueAt(i, 0); String title = (String) model.getValueAt(i, 1); if (artist.equals(metadataTarget.getArtist()) && title.equals(metadataTarget.getTitle())) { return i; }/*from www .j av a2 s . c o m*/ } return 0; }
From source file:userInterface.HospitalAdminRole.ManagePatientsJPanel.java
private void saveReportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveReportBtnActionPerformed try {/* www .j a v a 2s .co m*/ HSSFWorkbook fWorkbook = new HSSFWorkbook(); HSSFSheet fSheet = fWorkbook.createSheet("new Sheet"); HSSFFont sheetTitleFont = fWorkbook.createFont(); File file = new File("C:\\Users\\Reshmi\\OneDrive\\Documents\\reports.xls"); HSSFCellStyle cellStyle = fWorkbook.createCellStyle(); sheetTitleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //sheetTitleFont.setColor(); TableModel model = vitalSignjTable.getModel(); TableColumnModel tcm = vitalSignjTable.getColumnModel(); HSSFRow fRow1 = fSheet.createRow((short) 0); for (int j = 0; j < tcm.getColumnCount(); j++) { HSSFCell cell = fRow1.createCell((short) j); cell.setCellValue(tcm.getColumn(j).getHeaderValue().toString()); } for (int i = 0; i < model.getRowCount(); i++) { HSSFRow fRow = fSheet.createRow((short) i + 1); for (int j = 0; j < model.getColumnCount(); j++) { HSSFCell cell = fRow.createCell((short) j); cell.setCellValue(tcm.getColumn(j).getHeaderValue().toString()); cell.setCellValue(model.getValueAt(i, j).toString()); cell.setCellStyle(cellStyle); } } FileOutputStream fileOutputStream; fileOutputStream = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream); fWorkbook.write(bos); bos.close(); fileOutputStream.close(); JOptionPane.showMessageDialog(null, "File saved as reports.xls ", "Export", JOptionPane.INFORMATION_MESSAGE); // Runtime run = Runtime.getRuntime(); // run.exec("cmd.exetart " + file); } catch (Exception e) { JOptionPane.showMessageDialog(null, "File not saved", "Export", JOptionPane.INFORMATION_MESSAGE); } }