Example usage for javax.swing JTable repaint

List of usage examples for javax.swing JTable repaint

Introduction

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

Prototype

public void repaint() 

Source Link

Document

Repaints this component.

Usage

From source file:app.RunApp.java

/**
 * Action for Invert button from multiple datasets tab
 * /*from   www. ja  va  2s  .  c  o  m*/
 * @param evt Event
 * @param jtable Table
 */
private void buttonInvertActionPerformedMulti(java.awt.event.ActionEvent evt, JTable jtable) {
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        if ((Boolean) tmodel.getValueAt(i, 1)) {
            tmodel.setValueAt(Boolean.FALSE, i, 1);
        } else {
            tmodel.setValueAt(Boolean.TRUE, i, 1);
        }
    }

    jtable.setModel(tmodel);
    jtable.repaint();
}

From source file:app.RunApp.java

/**
 * Action for Calculate button from principal tab
 * /*from  ww w .  ja  v  a2s.  c  om*/
 * @param evt Event
 * @param jtable Table
 */
private void buttonCalculateActionPerformedPrincipal(java.awt.event.ActionEvent evt, JTable jtable) {
    ArrayList<String> metricsList = getMetricsSelectedPrincipal(jtable);

    if (dataset == null) {
        JOptionPane.showMessageDialog(null, "You must load a dataset.", "Warning", JOptionPane.ERROR_MESSAGE);
        return;
    } else if (metricsList.isEmpty()) {
        JOptionPane.showMessageDialog(null, "You must select any metric.", "Warning",
                JOptionPane.ERROR_MESSAGE);
        return;
    }

    //ImbalancedFeature[] label_frenquency = MetricUtils.getImbalancedDataByAppearances(dataset);
    //label_frenquency = MetricUtils.sortByFrequency(label_frenquency);// ordena de mayor a menor

    String value;

    progressBar.setMinimum(0);
    progressBar.setMaximum(metricsList.size() + 1);
    progressBar.setValue(0);
    int v = 1;
    for (String metric : metricsList) {
        progressBar.setValue(v);
        //If metric value exists, don't calculate
        if ((tableMetrics.get(metric) == null) || (tableMetrics.get(metric).equals("-"))) {
            value = MetricUtils.getMetricValue(metric, dataset);
            tableMetrics.put(metric, value.replace(",", "."));
        }

        v++;
    }

    TableModel model = jtable.getModel();

    for (int i = 0; i < model.getRowCount(); i++) {
        model.setValueAt(MetricUtils.getValueFormatted(model.getValueAt(i, 0).toString(),
                tableMetrics.get(model.getValueAt(i, 0).toString())), i, 1);
    }

    jtable.repaint();
}

From source file:app.RunApp.java

/**
 * Action for Calculate button from multiple datasets tab
 * /*w  w  w .  ja  va 2s.  c om*/
 * @param evt Event
 * @param jtable Table
 */
private void buttonCalculateActionPerformedMulti(java.awt.event.ActionEvent evt, JTable jtable) {
    ArrayList<String> metricsList = getSelectedMetricsMulti(jtable);

    if (listDatasets == null || listDatasets.size() < 1) {
        JOptionPane.showMessageDialog(null, "You must load a dataset.", "Warning", JOptionPane.ERROR_MESSAGE);
        return;
    } else if (metricsList.isEmpty()) {
        JOptionPane.showMessageDialog(null, "You must select any metric.", "Warning",
                JOptionPane.ERROR_MESSAGE);
        return;
    }

    ImbalancedFeature[] labelsFrequency;
    String value;

    progressBar.setMinimum(0);
    progressBar.setMaximum(metricsList.size() * datasetNames.size() + 1);
    progressBar.setValue(0);
    int v = 1;

    int d = 0;
    for (String dataName : datasetNames) {
        labelsFrequency = MetricUtils.getImbalancedDataByAppearances(listDatasets.get(d));
        labelsFrequency = MetricUtils.sortByFrequency(labelsFrequency);

        if (!tableMetricsMulti.contains(dataName)) {
            tableMetricsMulti.put(dataName, new Hashtable<String, String>());
            initTableMetricsMulti(dataName);
        }

        for (String metric : metricsList) {
            progressBar.setValue(v);

            //If metric value exists, don't calculate
            if ((tableMetricsMulti.get(dataName).get(metric) == null)
                    || (tableMetricsMulti.get(dataName).get(metric).equals("-"))) {
                value = MetricUtils.getMetricValue(metric, listDatasets.get(d));
                tableMetricsMulti.get(dataName).put(metric, value.replace(",", "."));
            }

            v++;
        }

        d++;
    }

    jtable.repaint();
}

From source file:org.openconcerto.task.TodoListPanel.java

void initPopUp() {
    TablePopupMouseListener.add(this.t, new ITransformer<MouseEvent, JPopupMenu>() {

        @Override//from  w w  w  .jav  a2 s  .  c  o m
        public JPopupMenu transformChecked(MouseEvent evt) {
            final JTable table = (JTable) evt.getSource();
            final int modelIndex = TodoListPanel.this.sorter.modelIndex(table.getSelectedRow());
            final JPopupMenu res = new JPopupMenu();

            // Avancer d'un jour
            Action act = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    final TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
                    if (element != null) {
                        final Date ts = element.getExpectedDate();
                        final Calendar cal = Calendar.getInstance();
                        cal.setTimeInMillis(ts.getTime());
                        cal.add(Calendar.DAY_OF_YEAR, 1);
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                ts.setTime(cal.getTimeInMillis());
                                element.setExpectedDate(ts);
                                element.commitChangesAndWait();
                                table.repaint();
                            }
                        });
                    }
                }
            };
            act.putValue(Action.NAME, TM.tr("moveOneDay"));
            res.add(act);

            // Marquer comme ralis
            act = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
                    if (element != null) {
                        element.setDone(true);
                        element.commitChangesAndWait();
                        table.repaint();
                    }
                }
            };
            act.putValue(Action.NAME, TM.tr("markDone"));
            res.add(act);

            // Suppression
            act = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    TodoListPanel.this.model.deleteTaskAtIndex(modelIndex);
                    table.repaint();
                }
            };
            act.putValue(Action.NAME, TM.tr("delete"));
            res.add(act);

            final TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
            SQLRowValues rowTache = element.getRowValues();

            List<AbstractAction> actions = TacheActionManager.getInstance().getActionsForTaskRow(rowTache);

            for (AbstractAction abstractAction : actions) {
                res.add(abstractAction);
            }

            return res;
        }
    });
}

From source file:org.rdv.datapanel.DigitalTabularDataPanel.java

private void useEngineeringRenderer(boolean useEngineeringRenderer) {
    dataCellRenderer.setShowEngineeringFormat(useEngineeringRenderer);
    doubleCellRenderer.setShowEngineeringFormat(useEngineeringRenderer);

    for (JTable table : tables) {
        table.repaint();
    }/*from   w  w w.j ava2  s .co m*/

    if (useEngineeringRenderer) {
        engineeringButton.setSelected(true);
        properties.setProperty("renderer", "engineering");
    } else {
        decimalButton.setSelected(true);
        properties.remove("renderer");
    }
}

From source file:org.revager.tools.GUITools.java

/**
 * Creates a new standard table./*w w w  . jav  a  2  s  . c o m*/
 * 
 * @param model
 *            the table model
 * @param showHeader
 *            true if the header of the table should be visible
 * 
 * @return the newly created table
 */
@SuppressWarnings("serial")
public static JTable newStandardTable(TableModel model, boolean showHeader) {
    /*
     * Prep. for rollover
     */
    if (lastRolloverKey == Integer.MAX_VALUE) {
        lastRolloverKey = 0;
    } else {
        lastRolloverKey++;
    }

    final int keyIdx = lastRolloverKey;

    rollOverRowIndex.put(keyIdx, -1);

    final JTable table = new JTable(model) {

        @Override
        public boolean editCellAt(int row, int column, java.util.EventObject e) {
            boolean result = super.editCellAt(row, column, e);
            final Component editor = getEditorComponent();

            TableCellRenderer renderer = this.getColumnModel().getColumn(column).getCellRenderer();
            Font cellFont = null;
            if (renderer instanceof DefaultTableCellRenderer) {
                cellFont = ((DefaultTableCellRenderer) renderer).getFont();
            }
            if (editor != null && editor instanceof JTextComponent) {
                JTextComponent jTextComponent = (JTextComponent) editor;
                if (e == null) {
                    jTextComponent.selectAll();
                } else {
                    SwingUtilities.invokeLater(jTextComponent::selectAll);
                }
                jTextComponent.setBorder(UI.MARKED_BORDER_INLINE);
                if (cellFont != null) {
                    jTextComponent.setFont(cellFont);
                }
                editor.requestFocusInWindow();
            }
            return result;
        }

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            TableCellRenderer renderer = super.getCellRenderer(row, column);
            if (renderer instanceof DefaultTableCellRenderer) {
                ((DefaultTableCellRenderer) renderer).setBorder(new EmptyBorder(3, 3, 3, 3));
            }
            return renderer;
        }

        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
            Component comp = super.prepareRenderer(renderer, row, col);
            // Rollover
            comp.setBackground(getBackground());
            comp = super.prepareRenderer(renderer, row, col);
            if (!isRowSelected(row) && row == rollOverRowIndex.get(keyIdx)) {
                comp.setForeground(getForeground());
                comp.setBackground(UI.BLUE_BACKGROUND_COLOR);
            }

            // Tooltips
            JComponent jcomp = (JComponent) comp;
            if (renderer instanceof DefaultTableCellRenderer) {
                String toolTip = ((DefaultTableCellRenderer) renderer).getToolTipText();
                if (!StringUtils.isEmpty(toolTip)) {
                    jcomp.setToolTipText(toolTip);
                }
            }
            return comp;
        }
    };

    // Table properties
    table.setRowHeight(UI.TABLE_ROW_HEIGHT);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setShowGrid(false);
    table.setShowHorizontalLines(true);
    table.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

    // Rollover
    MouseInputAdapter rolloverListener = new MouseInputAdapter() {
        @Override
        public void mouseExited(MouseEvent e) {
            rollOverRowIndex.put(keyIdx, -1);
            table.repaint();
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            int row = table.rowAtPoint(e.getPoint());
            if (row != rollOverRowIndex.get(keyIdx)) {
                rollOverRowIndex.put(keyIdx, row);
                table.repaint();
            }
        }
    };
    table.addMouseMotionListener(rolloverListener);
    table.addMouseListener(rolloverListener);

    // Header
    if (!showHeader) {
        table.setTableHeader(null);
    }
    return table;
}