Example usage for javax.swing.event TableModelListener TableModelListener

List of usage examples for javax.swing.event TableModelListener TableModelListener

Introduction

In this page you can find the example usage for javax.swing.event TableModelListener TableModelListener.

Prototype

TableModelListener

Source Link

Usage

From source file:TableModelListenerDemo.java

public static void main(String args[]) {

    final Object rowData[][] = { { "1", "one", "I" }, { "2", "two", "II" }, { "3", "three", "III" } };
    final String columnNames[] = { "#", "English", "Roman" };

    final JTable table = new JTable(rowData, columnNames);
    JScrollPane scrollPane = new JScrollPane(table);
    table.getModel().addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            System.out.println(e);
        }//w  ww.  jav a 2 s  .  com
    });

    table.setValueAt("", 0, 0);
    JFrame frame = new JFrame("Resizing Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 150);
    frame.setVisible(true);

}

From source file:Main.java

Main() {
    JFrame jfrm = new JFrame("JTable Event Demo");
    jfrm.setSize(400, 200);/*from ww w.ja  v a 2  s  .  c  om*/
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    jtabOrders.setPreferredScrollableViewportSize(new Dimension(420, 62));

    ListSelectionModel rowSelMod = jtabOrders.getSelectionModel();

    ListSelectionModel colSelMod = jtabOrders.getColumnModel().getSelectionModel();

    rowSelMod.addListSelectionListener(this);
    colSelMod.addListSelectionListener(this);

    tm = jtabOrders.getModel();

    tm.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent tme) {
            if (tme.getType() == TableModelEvent.UPDATE) {
                System.out.println("Cell " + tme.getFirstRow() + ", " + tme.getColumn() + " changed."
                        + " The new value: " + tm.getValueAt(tme.getFirstRow(), tme.getColumn()));
            }
        }
    });
    jfrm.add(new JScrollPane(jtabOrders));
    jfrm.setVisible(true);

}

From source file:blue.soundObject.tracker.TrackList.java

public TrackList() {
    columnChangeListener = new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            TableModelEvent tme = new TableModelEvent(TrackList.this, TableModelEvent.HEADER_ROW);
            fireTableModelEvent(tme);/*  ww w.  ja  v a  2 s .c om*/
        }
    };
}

From source file:gui.accessories.GraphPopup.java

private BarChart createBarChartDynamic() {
    SampleTableModel tableModel = new SampleTableModel();
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);/*from  w w  w  . java 2  s  .c o m*/
    yAxis.setLabel("Units Sold");

    final BarChart aChart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    aChart.setAnimated(true);
    tableModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) aChart.getData()
                                .get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return aChart;
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelDetailMass.java

public boolean loadData() {
    super.loadData();

    // Tabelle //from   w  w  w .ja  v a  2  s. c om
    MassenTableModel m = new MassenTableModel(app.getXmlClient());
    m.load(objektNode, t, s);
    panelMass.setModel(m);
    panelMass.setObjektNode(objektNode);

    // Grafik
    XYDataset xyDataset = new TableModelXYDataset(m, true);
    StatusItemRenderer statusRenderer = new StatusItemRenderer(m, 2);

    NumberAxis rangeAxis = new NumberAxis(
            ChartUtils.getNumberAxisLabel(app.getXmlClient(), objektNode.getId()));
    DateAxis domainAxis = new DateAxis("Time");
    Plot plot = new StatusXYPlot(xyDataset, domainAxis, rangeAxis, statusRenderer);

    JFreeChart f = new JFreeChart(plot);
    StandardLegend l = new StandardLegend(f);

    panelChart.setChart(f);
    panelChart.setLegend(l);

    // Link 
    m.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            panelChart.repaint();
        }

    });

    return true;
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelDetailLab.java

public boolean loadData() {
    super.loadData();

    LaborTableModel m = new LaborTableModel(app.getXmlClient());
    m.load(objektNode, t, s);/* w  w w .j a  va  2s.c  o  m*/
    panelLab.setModel(m);
    panelLab.setObjektNode(objektNode);

    // Grafik
    XYDataset xyDataset = new TableModelXYDataset(m, true);
    StatusItemRenderer statusRenderer = new StatusItemRenderer(m, LAB_COL_STAT_ID);

    NumberAxis rangeAxis = new NumberAxis(
            ChartUtils.getNumberAxisLabel(app.getXmlClient(), objektNode.getId()));
    DateAxis domainAxis = new DateAxis("Time");
    Plot plot = new StatusXYPlot(xyDataset, domainAxis, rangeAxis, statusRenderer);
    JFreeChart f = new JFreeChart(plot);
    StandardLegend l = new StandardLegend(f);

    panelChart.setChart(f);
    panelChart.setLegend(l);

    // Link 
    m.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            panelChart.repaint();
        }

    });

    return true;
}

From source file:eu.apenet.dpt.standalone.gui.dateconversion.DateConversionRulesDialog.java

private void createDataConversionRulesList() {
    Vector<String> columnNames = new Vector<String>();
    columnNames.add(labels.getString("dateConversion.valueRead"));
    columnNames.add(labels.getString("dateConversion.valueConverted"));
    dm = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);
    dm.addRow(new Vector<String>());
    dm.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            if (ruleTable.getEditingRow() != ruleTable.getRowCount() - 1
                    && (StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                            && StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1)))) {
                dm.removeRow(ruleTable.getEditingRow());
            }/*from w  w  w .j a  va2  s. c o m*/
            if (ruleTable.getEditingRow() == ruleTable.getRowCount() - 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                        && StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    dm.addRow(new Vector<String>());
                }
            }
            if (ruleTable.getEditingColumn() == 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))
                        && !isCorrectDateFormat((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    createOptionPaneForIsoDate(ruleTable.getEditingRow(), 1);
                }
            }
        }
    });

    ruleTable = new JTable(dm);
    oldModel = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);

    JButton saveButton = new JButton(labels.getString("saveBtn"));
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            for (int i = 0; i < data.size() - 1; i++) {
                Vector<String> vector = data.elementAt(i);
                if (vector.elementAt(1) != null && !isCorrectDateFormat((String) vector.elementAt(1))) {
                    createOptionPaneForIsoDate(i, 1);
                }
            }
            xmlFilehandler.saveDataToFile(data, FILENAME);
            saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                    new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
        }
    });

    JButton closeButton = new JButton(labels.getString("quit"));
    closeButton.addActionListener(new ActionListener() {
        // boolean cancel = true;

        public void actionPerformed(ActionEvent e) {
            /*System.out.println(Boolean.toString(oldModel.getRowCount() == (ruleTable.getModel().getRowCount() - 1)) + "<<" + oldModel.getRowCount() + ", " + (ruleTable.getModel().getRowCount() - 1));
            if (oldModel.getRowCount() != ruleTable.getModel().getRowCount() - 1) {
            cancel = showUnsavedChangesDialog();
            } else {
            for (int i = 0; i < (ruleTable.getModel().getRowCount() - 1); i++) {
                for (int j = 0; j <= 1; j++) {
                    System.out.println(oldModel.getValueAt(i, j) == ruleTable.getModel().getValueAt(i, j) + " >> " + oldModel.getValueAt(i, j) + ", " + ruleTable.getModel().getValueAt(i, j));
                    if (oldModel.getValueAt(i, j) != ruleTable.getModel().getValueAt(i, j)) {
                        cancel = showUnsavedChangesDialog();
                    }
                }
            }
            }
            if (cancel) {*/
            dispose();
            //  }
        }
    });

    JButton downloadButton = new JButton(labels.getString("downloadBtn"));
    downloadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            File currentLocation = new File(retrieveFromDb.retrieveOpenLocation());
            JFileChooser fileChooser = new JFileChooser(currentLocation);
            fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
            fileChooser.setFileFilter(new FileNameExtensionFilter("XML file", "xml"));
            int returnedVal = fileChooser.showSaveDialog(getParent());

            if (returnedVal == JFileChooser.APPROVE_OPTION) {
                String fileName = fileChooser.getSelectedFile().toString();
                if (!fileName.endsWith(".xml")) {
                    fileName = fileName + ".xml";
                }
                xmlFilehandler.saveDataToFile(data, fileName);
                //additionally save data to standard file
                xmlFilehandler.saveDataToFile(data, FILENAME);
                saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                        new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
            }
        }
    });

    JPanel contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(new JScrollPane(ruleTable));
    saveMessage = new JLabel();
    contentPanel.add(saveMessage, BorderLayout.SOUTH);

    JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
    buttonPanel.add(saveButton);
    buttonPanel.add(closeButton);
    buttonPanel.add(downloadButton);

    JPanel pane = new JPanel(new BorderLayout());
    pane.add(contentPanel, BorderLayout.PAGE_START);
    pane.add(buttonPanel, BorderLayout.PAGE_END);
    add(pane);
}

From source file:org.hsh.bfr.db.gui.dbtable.editoren.MyChartDialog.java

MyChartDialog(JDialog owner, String Datenpunkte, String xAxis, String yAxis) {
    super(owner);
    this.Datenpunkte = Datenpunkte;
    origDatenpunkte = Datenpunkte;//from w w  w.ja  v a  2s .  c o  m
    initComponents();

    series2 = new XYSeries("Datenpunkte");
    fillTable(xAxis, yAxis);
    dataset = createDataset();
    final JFreeChart chart = createChart(dataset, xAxis, yAxis);
    final ChartPanel chartPanel = new ChartPanel(chart);
    panel1.remove(button1);
    panel1.add(chartPanel, new CellConstraints().xywh(1, 1, 1, 1, CellConstraints.FILL, CellConstraints.FILL));
    this.setTitle(xAxis + "-" + yAxis + "-Profil");

    table1.getModel().addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            dataset = createDataset();
        }
    });
}

From source file:net.kamhon.ieagle.swing.table.KTableTestPanel.java

private Component createCenterPanel() {
    List<Student> students = populateStudents();

    KTableColumn[] columns = new KTableColumn[] { //
            new KTableRowCheckBoxColumn(), //
            new KTableCheckBoxColumn("name", "Label"), //
            new KTableTextColumn("name", "Name"), //
            new KTableTextColumn("age", "Age"), //
            new KTableTextColumn("weight", "Weight") };
    table = new KTable<Student>(columns);

    table.getModel().addTableModelListener(new TableModelListener() {
        @Override//from  w w  w .  jav  a 2s  .  c o m
        public void tableChanged(TableModelEvent e) {
            log.debug("e = " + e);
        }
    });

    // table.setColumns(Arrays.asList(new KTableTextColumn("name", "Name"), new KTableTextColumn("age", "Age")));
    table.setData(students);

    JScrollPane scrollPane = new JScrollPane(table);

    return scrollPane;
}

From source file:org.geotoolkit.gui.swing.propertyedit.styleproperty.JAnalizePanel.java

private void refresh() {
    guiCount.setText(String.valueOf(analyze.getCount()));
    guiSum.setText(FORMAT.format(analyze.getSum()));
    guiMinimum.setText(FORMAT.format(analyze.getMinimum()));
    guiMaximum.setText(FORMAT.format(analyze.getMaximum()));
    guiMean.setText(FORMAT.format(analyze.getMean()));
    guiMedian.setText(FORMAT.format(analyze.getMedian()));

    guiChart.removeAll();//from w w  w  .  j av a2s  .  c om
    guiChart.add(new ChartPanel(getChart((Integer) guiDivision.getModel().getValue())));

    double[] values = analyze.getValues();
    Double[][] vals = new Double[values.length][1];

    for (int i = 0; i < values.length; i++) {
        vals[i][0] = values[i];
    }

    guiTable.setTableHeader(null);
    guiTable.setModel(new DefaultTableModel(vals, new String[] { "" }) {

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return Double.class;
        }

    });
    guiTable.setShowGrid(false, false);
    guiTable.setHighlighters(new Highlighter[] {
            HighlighterFactory.createAlternateStriping(Color.white, HighlighterFactory.QUICKSILVER, 1) });
    guiTable.revalidate();
    guiTable.repaint();

    guiTable.setEditable(analyze.getMethod() == METHOD.MANUAL);

    guiTable.getModel().addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            double[] values = new double[guiTable.getModel().getRowCount()];
            for (int i = 0; i < values.length; i++) {
                values[i] = Double.valueOf(guiTable.getModel().getValueAt(i, 0).toString());
            }

            analyze.setValues(values);

        }
    });

    guiMethod.setSelectedItem(analyze.getMethod());

}