Example usage for javax.swing JTable getValueAt

List of usage examples for javax.swing JTable getValueAt

Introduction

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

Prototype

public Object getValueAt(int row, int column) 

Source Link

Document

Returns the cell value at row and column.

Usage

From source file:es.emergya.ui.plugins.admin.AdminRoles.java

private FiltrarAction getFiltrarAction() {
    return roles.new FiltrarAction() {

        private static final long serialVersionUID = -2344175197357308765L;

        @Override/*ww  w .j a va2  s .c  om*/
        protected void applyFilter(JTable filters) {
            final Rol example = new Rol();
            final Object valueAt = filters.getValueAt(0, 1);
            if (valueAt != null && valueAt.toString().length() > 0) {
                example.setNombre(valueAt.toString());
            }
            roles.setTableData(getAll(example));
        }
    };
}

From source file:es.emergya.ui.plugins.admin.AdminSquads.java

private FiltrarAction getFiltrarAction() {
    return squads.new FiltrarAction() {

        private static final long serialVersionUID = -1096192874098385825L;

        @Override//from  w ww  . j a  v  a  2s. c o m
        protected void applyFilter(JTable filters) {
            final Patrulla example = new Patrulla();
            final Object valueAt = filters.getValueAt(0, 1);
            if (valueAt != null && valueAt.toString().length() > 0) {
                example.setNombre(valueAt.toString());
            }
            squads.setTableData(getAll(example));
        }
    };
}

From source file:latexstudio.editor.DropboxRevisionsTopComponent.java

private void jTable1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MousePressed
    if (evt.getClickCount() == 2) {
        // Resolving which row has been double-clicked
        Point point = evt.getPoint();
        JTable table = (JTable) evt.getSource();
        int row = table.rowAtPoint(point);
        // Finding revision using information from the clicked row
        Object revisionNumber = table.getValueAt(row, REVISION_COLUMN);
        if (revisionNumber != null) {
            loadRevision(revisionNumber.toString());
        }// w w w . ja va2  s . c o  m
    }
}

From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java

private static JTable createTable(TableModel m) {
    JTable t = new JTable(m) {
        @Override/*from  w  w w  . j a v  a2 s.c o m*/
        public String getToolTipText(MouseEvent event) {
            JTable t = (JTable) event.getSource();
            int x = t.rowAtPoint(event.getPoint());
            if (x == -1)
                return null;
            int y = t.columnAtPoint(event.getPoint());
            if (y == -1)
                return null;
            Object o = t.getValueAt(x, y);
            if (o == null)
                return null;
            return String.valueOf(o);
        }

    };
    t.setToolTipText("");
    t.setShowVerticalLines(false);
    DefaultTableCellRenderer render = new DefaultTableCellRenderer() {
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (!isSelected && !hasFocus)
                this.setBackground(row % 2 == 0 ? color1 : color2);
            if (value != null && value instanceof Boolean) {
                if (Boolean.TRUE.equals(value))
                    this.setText("\u2612");
                else if (Boolean.FALSE.equals(value))
                    this.setText("");
            }
            return c;
        }
    };
    render.setOpaque(true);
    for (int i = 0; i < t.getColumnModel().getColumnCount(); ++i) {
        t.getColumnModel().getColumn(i).setCellRenderer(render);
    }
    return t;
}

From source file:latexstudio.editor.DropboxRevisionsTopComponent.java

public void updateRevisionsList(String path) {
    DbxClient client = DbxUtil.getDbxClient();
    List<DbxEntry.File> entries = null;

    if (path != null) {
        try {/*from  w ww.  j  a v  a2 s  .co  m*/
            entries = client.getRevisions(path);
        } catch (DbxException ex) {
            DbxUtil.showDbxAccessDeniedPrompt();
        }
    }

    dlm.clear();
    DefaultTableModel model = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            return column == REVIEW_COLUMN;
        }
    };
    model.addColumn(REVISION_COLUMN_NAME);
    model.addColumn(MODIFIED_COLUMN_NAME);
    model.addColumn(FILE_SIZE_COLUMN_NAME);
    model.addColumn(REVIEW_COLUMN_NAME);

    if (entries != null && entries.size() > 0) {
        for (DbxEntry.File dbxEntry : entries) {
            dlm.addElement(new DbxEntryRevision(dbxEntry));
            model.addRow(new Object[] { dbxEntry.rev, dbxEntry.lastModified, dbxEntry.humanSize,
                    REVIEW_BUTTON_LABEL });
        }
    }

    Action showVersion = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Resolving which row has been double-clicked
            JTable table = (JTable) e.getSource();
            int row = Integer.valueOf(e.getActionCommand());
            // Finding revision using information from the clicked row
            String revisionNumber = table.getValueAt(row, REVISION_COLUMN).toString();
            loadRevision(revisionNumber);
        }
    };

    jTable1.setModel(model);
    ButtonColumn buttonColumn = new ButtonColumn(jTable1, showVersion, REVIEW_COLUMN);
    buttonColumn.setMnemonic(KeyEvent.VK_D);
}

From source file:labr_client.GUI.forms.EhealthSearch.java

private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
    // TODO add your handling code here:
    if (evt.getClickCount() == 2) {
        JTable target = (JTable) evt.getSource();
        String id = (String) target.getValueAt(target.getSelectedRow(), 2);

        // setInfo();
    }// www. j  a  v a 2  s .com
}

From source file:fitmon.WorkoutLog.java

private void removeItem(java.awt.event.MouseEvent evt) {

    if (evt.getClickCount() == 1) {
        JTable target = (JTable) evt.getSource();
        int row = target.getSelectedRow();
        int column = target.getSelectedColumn();
        String selectedwkt = (String) target.getValueAt(row, 0);
        //int index = selectedwkt.indexOf("--");
        // String foodName = selectedFood.substring(0, index);
        //int calorie = selectedFood.substring(index+2);
        if (target.getColumnName(target.getSelectedColumn()).equals("Edit")) {
            DefaultTableModel model = (DefaultTableModel) tab.getModel();
            model.removeRow(row);/*  w w w  . j  a  v  a  2  s . c om*/
            for (int i = 0; i < wkt.size(); i++) {
                if (wkt.get(i).getWorkout().equals(selectedwkt)) //&& wkt.get(i).getCal().equals(calorie))
                {
                    wkt.remove(i);
                    break;
                }
            }
        }
        // do some action if appropriate column
    }

    // TODO add your handling code here:
}

From source file:lectorarchivos.MostrarGraficaCSV.java

/**
 * Creates new form MostrarGraficaCSV/*from  w  w w  . j  av a  2 s . co m*/
 */
public MostrarGraficaCSV(JTable jTableInfoCSV) {
    initComponents();
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    panel = new JPanel();
    getContentPane().add(panel);

    //Fuente de datos
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    //Recorremos la columna del consumo de la tabla
    for (int i = jTableInfoCSV.getRowCount() - 1; i >= 0; i--) {
        if (Double.parseDouble(jTableInfoCSV.getValueAt(i, 4).toString()) > 0)
            dataset.setValue(Double.parseDouble(jTableInfoCSV.getValueAt(i, 4).toString()), "Consumo",
                    jTableInfoCSV.getValueAt(i, 0).toString());
    }

    //Creando el grfico
    JFreeChart chart = ChartFactory.createBarChart3D("Consumo", "Fecha", "Consumo", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.cyan);
    chart.getTitle().setPaint(Color.black);
    chart.setBackgroundPaint(Color.white);
    chart.removeLegend();

    //Cambiar color de barras
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
    barRenderer.setSeriesPaint(0, Color.decode("#5882FA"));

    // Mostrar Grafico
    ChartFrame frame = new ChartFrame("CONSUMO", chart);
    frame.pack();
    frame.getChartPanel().setMouseZoomable(false);
    frame.setVisible(true);

    panel.add(frame);

}

From source file:fitmon.WorkoutLog.java

private void removeItem(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeItem

    if (evt.getClickCount() == 1) {
        JTable target = (JTable) evt.getSource();
        int row = target.getSelectedRow();
        int column = target.getSelectedColumn();
        String selectedwkt = (String) target.getValueAt(row, 0);
        //int index = selectedwkt.indexOf("--");
        // String foodName = selectedFood.substring(0, index);
        //int calorie = selectedFood.substring(index+2);
        if (target.getColumnName(target.getSelectedColumn()).equals("Edit")) {
            DefaultTableModel model = (DefaultTableModel) tab.getModel();
            model.removeRow(row);/*ww  w  . ja v a2 s.c o  m*/
            for (int i = 0; i < wkt.size(); i++) {
                if (wkt.get(i).getWorkout().equals(selectedwkt)) //&& wkt.get(i).getCal().equals(calorie))
                {
                    wkt.remove(i);
                    break;
                }
            }
        }
        // do some action if appropriate column
    }

    // TODO add your handling code here:
}

From source file:Main.java

public Main() {
    JTable table = new JTable(3, 3);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    for (int i = 0; i < table.getColumnCount(); i++) {
        DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
        TableColumn col = colModel.getColumn(i);
        int width = 0;

        TableCellRenderer renderer = col.getHeaderRenderer();
        for (int r = 0; r < table.getRowCount(); r++) {
            renderer = table.getCellRenderer(r, i);
            Component comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, i), false, false,
                    r, i);/*w  ww.j  a va 2  s . com*/
            width = Math.max(width, comp.getPreferredSize().width);
        }
        col.setPreferredWidth(width + 2);
    }
    JFrame f = new JFrame();
    f.add(new JScrollPane(table));
    f.setSize(300, 300);
    f.setVisible(true);
}