Example usage for javax.swing.table TableModel getValueAt

List of usage examples for javax.swing.table TableModel getValueAt

Introduction

In this page you can find the example usage for javax.swing.table TableModel getValueAt.

Prototype

public Object getValueAt(int rowIndex, int columnIndex);

Source Link

Document

Returns the value for the cell at columnIndex and rowIndex.

Usage

From source file:edu.ku.brc.specify.tasks.ReportsBaseTask.java

/**
 * @param model//from w  ww  .  j  a  v a 2s  . co  m
 * @return
 * @throws Exception
 */
public DynamicReport buildReport(final TableModel model, final PageSetupDlg pageSetupDlg) throws Exception {
    // Find a Sans Serif Font on the System
    String fontName = null;

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (java.awt.Font font : ge.getAllFonts()) {
        String fName = font.getFamily().toLowerCase();
        if (StringUtils.contains(fName, "sansserif") || StringUtils.contains(fName, "arial")
                || StringUtils.contains(fName, "verdana")) {
            fontName = font.getFamily();
        }
    }

    if (fontName == null) {
        fontName = Font._FONT_TIMES_NEW_ROMAN;
    }

    /**
     * Creates the DynamicReportBuilder and sets the basic options for the report
     */
    FastReportBuilder drb = new FastReportBuilder();

    Style columDetail = new Style();
    //columDetail.setBorder(Border.THIN);

    Style columDetailWhite = new Style();
    //columDetailWhite.setBorder(Border.THIN);
    columDetailWhite.setBackgroundColor(Color.WHITE);
    columDetailWhite.setFont(new Font(10, fontName, true));
    columDetailWhite.setHorizontalAlign(HorizontalAlign.CENTER);
    columDetailWhite.setBlankWhenNull(true);

    Style columDetailWhiteBold = new Style();
    //columDetailWhiteBold.setBorder(Border.THIN);
    columDetailWhiteBold.setBackgroundColor(Color.WHITE);

    Style titleStyle = new Style();
    titleStyle.setFont(new Font(14, fontName, true));

    /*Style numberStyle = new Style();
    numberStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
            
    Style amountStyle = new Style();
    amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
    amountStyle.setBackgroundColor(Color.cyan);
    amountStyle.setTransparency(Transparency.OPAQUE);*/

    //Font dataRowFont = new Font(10, Font._FONT_VERDANA, true);

    // Odd Row Style
    Style oddRowStyle = new Style();
    //oddRowStyle.setBorder(Border.NO_BORDER);
    //oddRowStyle.setFont(dataRowFont);
    oddRowStyle.setHorizontalAlign(HorizontalAlign.CENTER);

    Color veryLightGrey = new Color(240, 240, 240);
    oddRowStyle.setBackgroundColor(veryLightGrey);
    oddRowStyle.setTransparency(Transparency.OPAQUE);

    // Event Row Style
    //Style evenRowStyle = new Style();
    //evenRowStyle.setBorder(Border.NO_BORDER);
    //evenRowStyle.setFont(dataRowFont);

    // Create Column Headers for the Report
    for (int i = 0; i < model.getColumnCount(); i++) {
        String colName = model.getColumnName(i);

        Class<?> dataClass = model.getColumnClass(i);
        if (dataClass == Object.class) {
            if (model.getRowCount() > 0) {
                Object data = model.getValueAt(0, i);
                if (data != null) {
                    dataClass = data.getClass();
                } else {
                    // Column in first row was null so search down the rows
                    // for a non-empty cell
                    for (int j = 1; j < model.getRowCount(); j++) {
                        data = model.getValueAt(j, i);
                        if (dataClass != null) {
                            dataClass = data.getClass();
                            break;
                        }
                    }

                    if (dataClass == null) {
                        dataClass = String.class;
                    }
                }
            }
        }

        ColumnBuilder colBldr = ColumnBuilder.getInstance().setColumnProperty(colName, dataClass.getName());
        int bracketInx = colName.indexOf('[');
        if (bracketInx > -1) {
            colName = colName.substring(0, bracketInx - 1);
        }
        colBldr.setTitle(colName);
        //colBldr.setWidth(new Integer(100));

        colBldr.setStyle(columDetailWhite);
        //colBldr.setHeaderStyle(columDetailWhite);

        AbstractColumn column = colBldr.build();
        drb.addColumn(column);

        Style headerStyle = new Style();
        headerStyle.setFont(new Font(12, fontName, true));
        //headerStyle.setBorder(Border.THIN);
        headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
        headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);
        headerStyle.setBackgroundColor(new Color(80, 80, 80));
        headerStyle.setTransparency(Transparency.OPAQUE);
        headerStyle.setTextColor(new Color(255, 255, 255));
        column.setHeaderStyle(headerStyle);
    }

    drb.setTitle(pageSetupDlg.getPageTitle());
    drb.setTitleStyle(titleStyle);
    //drb.setTitleHeight(new Integer(30));
    //drb.setSubtitleHeight(new Integer(20));
    //drb.setDetailHeight(new Integer(15));
    //drb.setDefaultStyles(null, null, null, evenRowStyle);

    drb.setLeftMargin(20);
    drb.setRightMargin(20);
    drb.setTopMargin(10);
    drb.setBottomMargin(10);

    drb.setPrintBackgroundOnOddRows(true);
    drb.setOddRowBackgroundStyle(oddRowStyle);
    drb.setColumnsPerPage(new Integer(1));
    drb.setUseFullPageWidth(true);
    drb.setColumnSpace(new Integer(5));

    // This next line causes an exception
    // Event with DynamicReport 3.0.12 and JasperReposrts 3.7.3
    //drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_CENTER);

    Page[] pageSizes = new Page[] { Page.Page_Letter_Portrait(), Page.Page_Legal_Portrait(),
            Page.Page_A4_Portrait(), Page.Page_Letter_Landscape(), Page.Page_Legal_Landscape(),
            Page.Page_A4_Landscape() };
    int pageSizeInx = pageSetupDlg.getPageSize() + (pageSetupDlg.isPortrait() ? 0 : 3);
    drb.setPageSizeAndOrientation(pageSizes[pageSizeInx]);

    DynamicReport dr = drb.build();

    return dr;
}

From source file:GUI.AllForDealFrame.java

private void tblMesServicesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblMesServicesMouseClicked
    // TODO add your handling code here:
    int i = tblMesServices.getSelectedRow();
    TableModel model = tblMesServices.getModel();

    //tfId.setText(model.getValueAt(i, 0).toString());
    labelId1.setText(model.getValueAt(i, 0).toString());
    tfNomService.setText(model.getValueAt(i, 1).toString());
    tfDescription1.setText(model.getValueAt(i, 2).toString());

    cbCat1.setSelectedItem(tblMesServices.getValueAt(i, 3));
    cbZoneX.setSelectedItem(tblMesServices.getValueAt(i, 5));
    cbEtat.setSelectedItem(tblMesServices.getValueAt(i, 4));

}

From source file:GUI.AllForDealFrame.java

private void tblMesProduitsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblMesProduitsMouseClicked
    int i = tblMesProduits.getSelectedRow();
    TableModel model = tblMesProduits.getModel();

    //tfId.setText(model.getValueAt(i, 0).toString());
    labelId.setText(model.getValueAt(i, 0).toString());
    tfNomP2.setText(model.getValueAt(i, 1).toString());
    cbCategorie2.setSelectedItem(tblMesProduits.getValueAt(i, 2));
    tfQuantite2.setText(model.getValueAt(i, 3).toString());
    taDescription2.setText(model.getValueAt(i, 4).toString());
    tfPrix2.setText(model.getValueAt(i, 5).toString());
    tfPointBonus2.setText(model.getValueAt(i, 6).toString());
    cbZone3.setSelectedItem(tblMesProduits.getValueAt(i, 7));
    tfTVA2.setText(model.getValueAt(i, 9).toString());
    tfReduction2.setText(model.getValueAt(i, 10).toString());

}

From source file:GUI.AllForDealFrame.java

private void btnConsulterSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsulterSActionPerformed
    // TODO add your handling code here:
    int i = tblMesServices.getSelectedRow();
    Object l = tblMesServices.getValueAt(i, 0);
    service_id = (int) l;
    System.out.println(service_id);
    TableModel model = tblMesServices.getModel();
    //labelId.setText(model.getValueAt(i, 0).toString());
    tfNomService1.setText(model.getValueAt(i, 1).toString());
    tfDescription2.setText(model.getValueAt(i, 2).toString());

    cbCat2.setSelectedItem(tblMesServices.getValueAt(i, 3));
    cbEtat1.setSelectedItem(tblMesServices.getValueAt(i, 4));
    cbZone2.setSelectedItem(model.getValueAt(i, 5).toString());
    ParentPanel.removeAll();/*from w w  w.j  ava2s . c o  m*/
    ParentPanel.add(pConsulterS);
    ParentPanel.repaint();
    ParentPanel.revalidate();
    jTableCommentMesServ.setModel(new CommentSModel());
    jTableCommentMesServ.getColumnModel().getColumn(0).setMinWidth(0);
    jTableCommentMesServ.getColumnModel().getColumn(0).setMaxWidth(0);
    jTableCommentMesServ.getColumnModel().getColumn(0).setWidth(0);

    //        pConsulterS.setVisible(true);
}

From source file:GUI.AllForDealFrame.java

private void bntConsulter1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntConsulter1ActionPerformed
    int i = tblMesProduits.getSelectedRow();
    TableModel model = tblMesProduits.getModel();
    Object l = tblMesProduits.getValueAt(i, 0);
    produit_id = (int) l;
    System.out.println(tblMesProduits);

    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());
    //        //from   www  .ja v  a 2  s. c o  m

    Produit p = pdao.findById(produit_id);

    MesProduitsConsultationPanel.removeAll();
    MesProduitsConsultationPanel.add(ConsultationPanel);
    MesProduitsConsultationPanel.repaint();
    MesProduitsConsultationPanel.revalidate();
}

From source file:GUI.AllForDealFrame.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;

    tbCommentairesProduits.setModel(new CommentPModel());
    tbCommentairesProduits.setVisible(true);
    tbCommentairesProduits.getColumnModel().getColumn(0).setMinWidth(0);
    tbCommentairesProduits.getColumnModel().getColumn(0).setMaxWidth(0);
    tbCommentairesProduits.getColumnModel().getColumn(0).setWidth(0);

    lNomProduit1.setText(model.getValueAt(i, 1).toString());
    lCategorie1.setText(model.getValueAt(i, 2).toString());
    lQuantite1.setText(model.getValueAt(i, 3).toString());
    lDescription1.setText(model.getValueAt(i, 4).toString());
    lPrix1.setText(model.getValueAt(i, 5).toString());
    lPointBonus1.setText(model.getValueAt(i, 6).toString());
    lZone1.setText(model.getValueAt(i, 7).toString());
    lTVA1.setText(model.getValueAt(i, 9).toString());
    lReduction1.setText(model.getValueAt(i, 10).toString());

    Produit p = pdao.findById(produit_id);

    offresProduitsPan.removeAll();//from w  w  w .  j a  va  2 s  .c om
    offresProduitsPan.add(ConsultationPanel1);
    offresProduitsPan.repaint();
    offresProduitsPan.revalidate();
}

From source file:GUI.AllForDealFrame.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;

    tbCommentairesService.setModel(new CommentSModel());
    tbCommentairesService.setVisible(true);
    tbCommentairesService.getColumnModel().getColumn(0).setMinWidth(0);
    tbCommentairesService.getColumnModel().getColumn(0).setMaxWidth(0);
    tbCommentairesService.getColumnModel().getColumn(0).setWidth(0);
    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.j  a v a2  s  .co 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);
    }

    ParentPanel2.removeAll();
    ParentPanel2.add(pConsulterS2);
    ParentPanel2.repaint();
    ParentPanel2.revalidate();

}

From source file:com.cch.aj.entryrecorder.frame.SettingsJFrame.java

@Override
public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting() && tblCheck.getSelectedRow() != -1) {
        TableModel model = tblCheck.getModel();
        int checkId = (int) model.getValueAt(tblCheck.getSelectedRow(), 0);
        String desc = model.getValueAt(tblCheck.getSelectedRow(), 1).toString();
        this.settingCheckId = checkId;
        this.txtCheckDesc.setText(desc);
    }//from  www  .  jav  a 2  s. c om
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Adjust all the column width for the data in the column, this may be handles with JDK 1.6 (6.)
 * @param tableArg the table that should have it's columns adjusted
 *//*w  w w  .ja va 2  s .  c om*/
private void initColumnSizes(final JTable tableArg, final JButton theSaveBtn) throws Exception {
    TableModel tblModel = tableArg.getModel();
    TableColumn column = null;
    Component comp = null;
    int headerWidth = 0;
    int cellWidth = 0;

    Element uploadDefs = null;
    if (WorkbenchTask.isCustomizedSchema()) {
        uploadDefs = XMLHelper.readFileToDOM4J(
                new File(UIRegistry.getAppDataDir() + File.separator + "specify_workbench_upload_def.xml"));
    } else {
        uploadDefs = XMLHelper.readDOMFromConfigDir("specify_workbench_upload_def.xml");
    }

    //UIRegistry.getInstance().hookUpUndoableEditListener(cellEditor);

    Vector<WorkbenchTemplateMappingItem> wbtmis = new Vector<WorkbenchTemplateMappingItem>();
    wbtmis.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems());
    Collections.sort(wbtmis);

    DBTableIdMgr databaseSchema = WorkbenchTask.getDatabaseSchema();

    columnMaxWidths = new Integer[tableArg.getColumnCount()];
    for (int i = 0; i < wbtmis.size() /*tableArg.getColumnCount()*/; i++) {
        TableCellRenderer headerRenderer = tableArg.getColumnModel().getColumn(i).getHeaderRenderer();
        WorkbenchTemplateMappingItem wbtmi = wbtmis.elementAt(i);

        // Now go retrieve the data length
        int fieldWidth = WorkbenchDataItem.getMaxWBCellLength();
        DBTableInfo ti = databaseSchema.getInfoById(wbtmi.getSrcTableId());
        if (ti != null) {
            DBFieldInfo fi = ti.getFieldByName(wbtmi.getFieldName());
            if (fi != null) {
                wbtmi.setFieldInfo(fi);
                //System.out.println(fi.getName()+"  "+fi.getLength()+"  "+fi.getType());
                if (RecordTypeCodeBuilder.getTypeCode(fi) == null && fi.getLength() > 0) {
                    fieldWidth = Math.min(fi.getLength(), WorkbenchDataItem.getMaxWBCellLength());
                }
            } else {
                log.error("Can't find field with name [" + wbtmi.getFieldName() + "]");
            }
        } else {
            log.error("Can't find table [" + wbtmi.getSrcTableId() + "]");
        }
        columnMaxWidths[i] = new Integer(fieldWidth);
        GridCellEditor cellEditor = getCellEditor(wbtmi, fieldWidth, theSaveBtn, uploadDefs);
        column = tableArg.getColumnModel().getColumn(i);

        comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);
        headerWidth = comp.getPreferredSize().width;

        comp = tableArg.getDefaultRenderer(tblModel.getColumnClass(i)).getTableCellRendererComponent(tableArg,
                tblModel.getValueAt(0, i), false, false, 0, i);

        cellWidth = comp.getPreferredSize().width;

        //comp.setBackground(Color.WHITE);

        int maxWidth = headerWidth + 10;
        TableModel m = tableArg.getModel();
        FontMetrics fm = comp.getFontMetrics(comp.getFont());
        for (int row = 0; row < tableArg.getModel().getRowCount(); row++) {
            String text = m.getValueAt(row, i).toString();
            maxWidth = Math.max(maxWidth, fm.stringWidth(text) + 10);
            //log.debug(i+" "+maxWidth);
        }

        //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
        //log.debug(Math.max(maxWidth, cellWidth));
        //log.debug(Math.min(Math.max(maxWidth, cellWidth), 400));
        column.setPreferredWidth(Math.min(Math.max(maxWidth, cellWidth), 400));

        column.setCellEditor(cellEditor);
    }
    //tableArg.setCellEditor(cellEditor);
}

From source file:app.RunApp.java

/**
 * Get selected metrics in table from principal tab
 * /*from   www .j a v  a2 s .  co  m*/
 * @param jtable Table
 * @return List with the selected metrics
 */
private ArrayList<String> getMetricsSelectedPrincipal(JTable jtable) {
    ArrayList<String> result = new ArrayList();
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        if ((Boolean) tmodel.getValueAt(i, 2)) {
            String selected = (String) tmodel.getValueAt(i, 0);
            result.add(selected);
        }
    }
    return result;
}