Example usage for javax.swing.table DefaultTableModel getValueAt

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

Introduction

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

Prototype

public Object getValueAt(int row, int column) 

Source Link

Document

Returns an attribute value for the cell at row and column.

Usage

From source file:graph.plotter.LineGraph.java

/**
   * This method works for showing clicked data in textFields 
   * @param evt /*from  ww  w.  jav a 2 s .com*/
   */
private void TableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TableMouseClicked
    // TODO add your handling code here:]
    DefaultTableModel model = (DefaultTableModel) Table.getModel();
    jTextField2.setText(model.getValueAt(Table.getSelectedRow(), 0).toString());
    jTextField3.setText(model.getValueAt(Table.getSelectedRow(), 1).toString());
}

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

private DefaultTableModel removeColumn(DefaultTableModel dtm, int column) {
    Object[][] data = new Object[dtm.getRowCount()][dtm.getColumnCount() - 1];
    Object[] names = new Object[dtm.getColumnCount() - 1];
    int cnt = 0;/* ww  w. j a  v  a2s .c o m*/
    for (int j = 0; j < dtm.getColumnCount(); j++) {
        if (j != column) {
            names[cnt++] = dtm.getColumnName(j);
        }
    }
    for (int i = 0; i < dtm.getRowCount(); i++) {
        cnt = 0;
        for (int j = 0; j < dtm.getColumnCount(); j++) {
            if (j != column) {
                data[i][cnt++] = dtm.getValueAt(i, j);
            }
        }
    }
    Logger.getLogger(getClass().getName()).log(Level.INFO,
            "Table model has {0} rows and {1} columns with {2} labels",
            new Object[] { data.length, data[0].length, names.length });
    return new DefaultTableModel(data, names);
}

From source file:userInterface.EnergySourceBoardSupervisor.ManageEnergyConsumptionsJPanel.java

private void sendAlertBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendAlertBtnActionPerformed
    int selectedRow = applianceTable.getSelectedRow();
    Date requestDate = new Date();
    Person person = (Person) houseAdminComboBox.getSelectedItem();
    //account.getPerson().getPersonName();
    String consumption = (String) applianceTable.getValueAt(selectedRow, 4);
    for (UserAccount ua : houseOrg.getUserAccDir().getUserAccountList()) {
        if (ua.getPerson().getPersonName().equals(person.getPersonName())) {
            account = ua;/*from w ww  .j  a va  2s.  c  om*/
        }
    }
    if (selectedRow >= 0) {
        if (!consumption.equals("Efficient")) {
            if (!commentsTxt.getText().equals("")) {
                DefaultTableModel model = (DefaultTableModel) applianceTable.getModel();
                Sensor sensor = (Sensor) model.getValueAt(selectedRow, 0);
                String message = sensor.getSensorType().getValue();
                HighEnergyConsumptionWorkRequest request = new HighEnergyConsumptionWorkRequest();
                request.setMessage(message);
                request.setSender(userAccount);
                request.setReceiver(account);
                request.setStatus("sent");
                request.setEnergyConsumed(sensor.getNumberWatt());
                String comment = commentsTxt.getText();
                request.setComment(comment);
                request.setRequestDate(requestDate);
                Organization org = null;
                for (Organization organization : enterprise.getOrganizationList().getOrganizationList()) {
                    if (organization instanceof HouseholdOrg) {
                        org = organization;
                        break;
                    }
                }
                if (org != null) {
                    userAccount.getWorkQueue().getWorkRequestList().add(request);
                    account.getWorkQueue().getWorkRequestList().add(request);
                }
                populateAlertTable();
                JOptionPane.showMessageDialog(null, "Alert Sent", "INFORMATION",
                        JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(null, "Kindly enter an alert message", "ERROR",
                        JOptionPane.ERROR_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Consumption is efficient.Alert not triggered", "MESSAGE",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    } else {
        JOptionPane.showMessageDialog(null, "Please Select a Row", "WARNING", JOptionPane.WARNING_MESSAGE);
    }

}

From source file:gtu._work.ui.RegexCatchReplacer_Ebao.java

private void initGUI() {
    try {/*  w  ww .ja va  2 s.com*/
        {
        }
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("source", null, jPanel1, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    {
                        replaceArea = new JTextArea();
                        jScrollPane1.setViewportView(replaceArea);
                        replaceArea.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                JPopupMenuUtil.newInstance(replaceArea).applyEvent(evt)
                                        .addJMenuItem("load from file", true, new ActionListener() {

                                            Thread newThread;

                                            public void actionPerformed(ActionEvent arg0) {
                                                if (newThread != null
                                                        && newThread.getState() != Thread.State.TERMINATED) {
                                                    JCommonUtil._jOptionPane_showMessageDialog_error(
                                                            "file is loading!");
                                                    return;
                                                }

                                                final File file = JCommonUtil._jFileChooser_selectFileOnly();
                                                if (file == null) {
                                                    JCommonUtil._jOptionPane_showMessageDialog_error(
                                                            "file is not correct!");
                                                    return;
                                                }
                                                String defaultCharset = Charset.defaultCharset().displayName();
                                                String chst = (String) JCommonUtil._jOptionPane_showInputDialog(
                                                        "input your charset!", defaultCharset);
                                                final Charset charset2 = Charset.forName(
                                                        StringUtils.defaultIfEmpty(chst, defaultCharset));

                                                newThread = new Thread(Thread.currentThread().getThreadGroup(),
                                                        new Runnable() {
                                                            public void run() {
                                                                try {
                                                                    loadFromFileSb = new StringBuilder();
                                                                    BufferedReader reader = new BufferedReader(
                                                                            new InputStreamReader(
                                                                                    new FileInputStream(file),
                                                                                    charset2));
                                                                    for (String line = null; (line = reader
                                                                            .readLine()) != null;) {
                                                                        loadFromFileSb.append(line + "\n");
                                                                    }
                                                                    reader.close();
                                                                    replaceArea
                                                                            .setText(loadFromFileSb.toString());
                                                                    JCommonUtil
                                                                            ._jOptionPane_showMessageDialog_info(
                                                                                    "load completed!");
                                                                } catch (Exception e) {
                                                                    JCommonUtil.handleException(e);
                                                                }
                                                            }
                                                        }, "" + System.currentTimeMillis());
                                                newThread.setDaemon(true);
                                                newThread.start();
                                            }
                                        }).show();
                            }
                        });
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("param", null, jPanel2, null);
                {
                    exeucte = new JButton();
                    jPanel2.add(exeucte, BorderLayout.SOUTH);
                    exeucte.setText("exeucte");
                    exeucte.setPreferredSize(new java.awt.Dimension(491, 125));
                    exeucte.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            exeucteActionPerformed(evt);
                        }
                    });
                }
                {
                    jPanel3 = new JPanel();
                    GroupLayout jPanel3Layout = new GroupLayout((JComponent) jPanel3);
                    jPanel3.setLayout(jPanel3Layout);
                    jPanel2.add(jPanel3, BorderLayout.CENTER);
                    {
                        repFromText = new JTextField();
                    }
                    {
                        repToText = new JTextField();
                    }
                    jPanel3Layout.setHorizontalGroup(jPanel3Layout.createSequentialGroup()
                            .addContainerGap(25, 25)
                            .addGroup(jPanel3Layout.createParallelGroup()
                                    .addGroup(jPanel3Layout.createSequentialGroup().addComponent(repFromText,
                                            GroupLayout.PREFERRED_SIZE, 446, GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel3Layout.createSequentialGroup().addComponent(repToText,
                                            GroupLayout.PREFERRED_SIZE, 446, GroupLayout.PREFERRED_SIZE)))
                            .addContainerGap(20, Short.MAX_VALUE));
                    jPanel3Layout.setVerticalGroup(jPanel3Layout.createSequentialGroup().addContainerGap()
                            .addComponent(repFromText, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(repToText, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
                            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
                }
                {
                    addToTemplate = new JButton();
                    jPanel2.add(addToTemplate, BorderLayout.NORTH);
                    addToTemplate.setText("add to template");
                    addToTemplate.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            prop.put(repFromText.getText(), repToText.getText());
                            reloadTemplateList();
                        }
                    });
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("result", null, jPanel4, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel4.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(491, 283));
                    {
                        DefaultTableModel resultAreaModel = JTableUtil.createModel(true, "match", "count");
                        resultArea = new JTable();
                        jScrollPane2.setViewportView(resultArea);
                        JTableUtil.defaultSetting(resultArea);
                        resultArea.setModel(resultAreaModel);
                    }
                }
            }
            {
                jPanel5 = new JPanel();
                BorderLayout jPanel5Layout = new BorderLayout();
                jPanel5.setLayout(jPanel5Layout);
                jTabbedPane1.addTab("template", null, jPanel5, null);
                {
                    jScrollPane3 = new JScrollPane();
                    jPanel5.add(jScrollPane3, BorderLayout.CENTER);
                    {
                        templateList = new JList();
                        jScrollPane3.setViewportView(templateList);
                        reloadTemplateList();
                    }
                    templateList.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                            if (templateList.getLeadSelectionIndex() == -1) {
                                return;
                            }
                            Entry<Object, Object> entry = (Entry<Object, Object>) JListUtil
                                    .getLeadSelectionObject(templateList);
                            repFromText.setText((String) entry.getKey());
                            repToText.setText((String) entry.getValue());
                        }
                    });
                    templateList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            JListUtil.newInstance(templateList).defaultJListKeyPressed(evt);
                        }
                    });
                }
            }
            {
                jPanel6 = new JPanel();
                FlowLayout jPanel6Layout = new FlowLayout();
                jPanel6.setLayout(jPanel6Layout);
                jTabbedPane1.addTab("result1", null, jPanel6, null);
                {
                    resultBtn1 = new JButton();
                    jPanel6.add(resultBtn1);
                    resultBtn1.setText("to String[]");
                    resultBtn1.setPreferredSize(new java.awt.Dimension(105, 32));
                    resultBtn1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            JTableUtil tableUtil = JTableUtil.newInstance(resultArea);
                            int[] rowPoss = tableUtil.getSelectedRows();
                            DefaultTableModel model = tableUtil.getModel();
                            List<Object> valueList = new ArrayList<Object>();
                            for (int ii = 0; ii < rowPoss.length; ii++) {
                                valueList.add(model.getValueAt(rowPoss[ii], 0));
                            }
                            String reult = valueList.toString().replaceAll("[\\s]", "")
                                    .replaceAll("[\\,]", "\",\"").replaceAll("[\\[\\]]", "\"");
                            ClipboardUtil.getInstance().setContents(reult);
                        }
                    });
                }
                {
                    resultBtn2 = new JButton();
                    jPanel6.add(resultBtn2);
                    resultBtn2.setText("TODO");
                    resultBtn2.setPreferredSize(new java.awt.Dimension(105, 32));
                    resultBtn2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            System.out.println("resultBtn1.actionPerformed, event=" + evt);
                            // TODO add your code for
                            // resultBtn1.actionPerformed
                            JCommonUtil._jOptionPane_showMessageDialog_info("TODO");
                        }
                    });
                }
            }
        }
        this.setSize(512, 350);
        JCommonUtil.setFont(repToText, repFromText, replaceArea, templateList);
        {
            panel = new JPanel();
            jTabbedPane1.addTab("eBao", null, panel, null);
            panel.setLayout(new BorderLayout(0, 0));
            {
                scrollPane = new JScrollPane();
                panel.add(scrollPane, BorderLayout.CENTER);
                {
                    ebaoTable = new JTable();
                    scrollPane.setViewportView(ebaoTable);
                    // TODO
                    DefaultTableModel ebaoModel = JTableUtil.createModel(true, "match", "label");
                    JTableUtil.defaultSetting(ebaoTable);
                    ebaoTable.setModel(ebaoModel);
                }
            }
            {
                exactEbaoSearchChk = new JCheckBox("");
                panel.add(exactEbaoSearchChk, BorderLayout.NORTH);
            }
        }

        JCommonUtil.frameCloseDo(this, new WindowAdapter() {
            public void windowClosing(WindowEvent paramWindowEvent) {
                if (StringUtils.isNotBlank(repFromText.getText())) {
                    prop.put(repFromText.getText(), repToText.getText());
                }
                try {
                    prop.store(new FileOutputStream(propFile), "regexText");
                } catch (Exception e) {
                    JCommonUtil.handleException("properties store error!", e);
                }
                setVisible(false);
                dispose();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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) + ",";
    }/*w w  w .  j a  va  2  s . c  o  m*/
    s += "\n";
    return s;
}

From source file:userInterface.EnergySourceBoardSupervisor.ManageEnergyConsumptionsJPanel.java

public void populateCalculations() {
    int reading = 0;
    int hours = 0;
    float energyPerDay = 0;
    float energyPerMonth = 0;
    float energyPerYear = 0;
    DefaultTableModel dtm = (DefaultTableModel) applianceTable.getModel();
    int count = dtm.getRowCount();
    for (int row = count - 1; row >= 0; row--) {
        reading = (int) dtm.getValueAt(row, 2);
        hours = (int) dtm.getValueAt(row, 3);
        energyPerDay = energyPerDay + ((reading * hours) / 1000);
    }//from  www  .  ja va 2s  . co m

    energyPerDayTxt.setText(String.valueOf(energyPerDay));
    energyPerMonth = energyPerDay * 30;
    energyPerMonthTxt.setText(String.valueOf(energyPerMonth));
    energyPerYear = energyPerDay * 365;
    energyPerYearTxt.setText(String.valueOf(energyPerYear));
}

From source file:Software_Jframes.chart.java

void print_excel_report(JTable jTable5) {
    Access ac = new Access();
    try {/*from ww  w. ja va  2  s  .c  om*/
        String filename = ac.chooseFile();

        WritableWorkbook wworkbook;
        wworkbook = Workbook.createWorkbook(new File(filename + ".xls"));
        WritableSheet wsheet = wworkbook.createSheet("First Sheet", 0);

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

        jxl.write.Label label1 = new jxl.write.Label(0, 0, "Good Name");
        wsheet.addCell(label1);
        jxl.write.Label label2 = new jxl.write.Label(1, 0, "Project Name");
        wsheet.addCell(label2);
        jxl.write.Label label3 = new jxl.write.Label(2, 0, "Cost");
        wsheet.addCell(label3);

        int i = 0;
        int j = 0;

        for (i = 0; i < count_row; i++) {
            for (j = 0; j < count_col; j++) {
                int temp_i = i + 2;
                jxl.write.Label label = new jxl.write.Label(j, temp_i, dtm.getValueAt(i, j) + "");
                wsheet.addCell(label);
            }
        }
        wworkbook.write();
        wworkbook.close();
        JOptionPane.showMessageDialog(null, "Successfully Create a excel file");

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

From source file:uk.ac.ox.cbrg.cpfp.uploadapp.UploadApplet.java

private void btnDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDelActionPerformed

    int selRows[] = fileTable.getSelectedRows();

    DefaultTableModel fileModel = (DefaultTableModel) fileTable.getModel();

    // Delete all selected files from the table AND file list
    int numRows = fileTable.getSelectedRows().length;
    for (int i = 0; i < numRows; i++) {
        int delRow = fileTable.getSelectedRow();
        String fileName = (String) fileModel.getValueAt(delRow, 0);
        uploadFiles.remove(delRow);/*from  ww  w.j  a  va2  s .  co  m*/
        fileModel.removeRow(delRow);
    }

    // if not files left disable upload
    if (uploadFiles.isEmpty()) {
        btnUpload.setEnabled(false);
    }
}

From source file:area.math.nm.ui.GUIInterpolationJPanel.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel) jTable1.getModel();

    int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
    double[][] tableData = new double[nRow][nCol];

    for (int i = 0; i < nRow; i++)
        for (int j = 0; j < nCol; j++) {
            if (dtm.getValueAt(i, j) != null) {
                tableData[i][j] = Double.parseDouble((String) dtm.getValueAt(i, j));

                System.out.println(i + " " + j + " " + tableData[i][j]);
            } else
                tableData[i][j] = -100000;
        }/*from   w w w  .j  av  a  2s  .c om*/
    int size = 0;
    for (int i = 0; i < 10; i++) {
        if (tableData[i][1] == -100000 || tableData[i][0] == -100000)
            break;
        else
            size++;
    }
    double[] x = new double[size];
    double[] y = new double[size];

    for (int i = 0; i < size; i++) {
        x[i] = tableData[i][0];
        y[i] = tableData[i][1];
    }
    String option = (String) jComboBox1.getSelectedItem();
    Interpolation ip = new Interpolation();
    double input = Double.parseDouble(jTextField1.getText());
    switch (option) {
    case "SplineInterpolator":
        String result = ip.splineInterpolation(x, y, input);
        JOptionPane.showMessageDialog(null, result);
        break;
    default:
        break;
    }

}

From source file:generadorqr.jifrGestionArticulos.java

void SeleccionarItemTablaCA(java.awt.event.MouseEvent evt) {
    DefaultTableModel modelo = (DefaultTableModel) jtContenidosArticulos.getModel();
    idA = String.valueOf(modelo.getValueAt(jtContenidosArticulos.getSelectedRow(), 0));
    categoria = String.valueOf(modelo.getValueAt(jtContenidosArticulos.getSelectedRow(), 1));
    imagenes = String.valueOf(modelo.getValueAt(jtContenidosArticulos.getSelectedRow(), 5));
    MostrarVisualizador(lblVistaPreviaImagen1, imagenes);
    imagenes = String.valueOf(modelo.getValueAt(jtContenidosArticulos.getSelectedRow(), 6));
    if (!StringUtils.isNullOrEmpty(imagenes) && !imagenes.contains("null"))
        MostrarVisualizador(lblVistaPreviaImagen2, imagenes);
    else//from  w w  w.j  av a  2 s .  co  m
        lblVistaPreviaImagen2.setIcon(null);
    imagenes = String.valueOf(modelo.getValueAt(jtContenidosArticulos.getSelectedRow(), 7));
    if (!StringUtils.isNullOrEmpty(imagenes) && !imagenes.contains("null"))
        MostrarVisualizador(lblVistaPreviaImagen3, imagenes);
    else
        lblVistaPreviaImagen3.setIcon(null);
    imagenes = String.valueOf(modelo.getValueAt(jtContenidosArticulos.getSelectedRow(), 10));
    if (!StringUtils.isNullOrEmpty(imagenes) && !imagenes.contains("null"))
        MostrarVisualizador(lblVistaPreviaImagen4, imagenes);
    else
        lblVistaPreviaImagen4.setIcon(null);
    lblEtiquetaPreviewImagenes.setVisible(true);
    lblEtiquetaPreviewQr.setVisible(true);
}