Example usage for javax.swing.table DefaultTableModel DefaultTableModel

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

Introduction

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

Prototype

public DefaultTableModel() 

Source Link

Document

Constructs a default DefaultTableModel which is a table of zero columns and zero rows.

Usage

From source file:dk.dma.epd.common.prototype.gui.route.RoutePropertiesDialogCommon.java

/**
 * Initializes the table model used for route details
 * /*from   w  w  w.ja  v  a  2s  .  c om*/
 * @return the table model
 */
private DefaultTableModel createRouteTableModel() {
    return new DefaultTableModel() {
        private static final long serialVersionUID = 1L;

        @Override
        public int getRowCount() {
            return route.getWaypoints().size();
        }

        @Override
        public int getColumnCount() {
            return COL_NAMES.length;
        }

        @Override
        public String getColumnName(int columnIndex) {
            return COL_NAMES[columnIndex];
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            RouteWaypoint wp = route.getWaypoints().get(rowIndex);
            switch (columnIndex) {
            case 0:
                return locked[rowIndex];
            case 1:
                return wp.getName();
            case 2:
                return wp.getPos().getLatitudeAsString();
            case 3:
                return wp.getPos().getLongitudeAsString();
            case 4:
                return wp.getTurnRad() == null ? "N/A" : Formatter.formatDistNM(wp.getTurnRad());
            case 5:
                return "N/A";
            case 6:
                return Formatter.formatTime(route.getWpTtg(rowIndex));
            case 7:
                return Formatter.formatShortDateTimeNoTz(route.getWpEta(rowIndex));
            case 8:
                return Formatter.formatDistNM(route.getWpRng(rowIndex));
            case 9:
                return Formatter.formatDegrees(route.getWpBrg(wp), 2);
            case 10:
                return wp.getHeading();
            case 11:
                return Formatter.formatSpeed(wp.getOutLeg().getSpeed());
            case 12:
                return Formatter.formatMeters(wp.getOutLeg().getXtdStarboardMeters());
            case 13:
                return Formatter.formatMeters(wp.getOutLeg().getXtdPortMeters());
            case 14:
                return Formatter.formatTime(wp.getOutLeg().getSFLenInMilleseconds());
            default:
                return null;
            }
        }

        @Override
        public void setValueAt(Object value, int rowIndex, int columnIndex) {
            try {
                RouteWaypoint wp = route.getWaypoints().get(rowIndex);
                switch (columnIndex) {
                case 0:
                    locked[rowIndex] = ((Boolean) value).booleanValue();
                    checkLockedRows();
                    fireTableRowsUpdated(rowIndex, rowIndex);
                    break;
                case 1:
                    wp.setName(value.toString());
                    break;
                case 2:
                    wp.setPos(Position.create(ParseUtils.parseLatitude(value.toString()),
                            wp.getPos().getLongitude()));
                    adjustStartTime();
                    notifyRouteListeners(RoutesUpdateEvent.ROUTE_CHANGED);
                    break;
                case 3:
                    wp.setPos(Position.create(wp.getPos().getLatitude(),
                            ParseUtils.parseLongitude(value.toString())));
                    adjustStartTime();
                    notifyRouteListeners(RoutesUpdateEvent.ROUTE_CHANGED);
                    break;
                case 4:
                    wp.setTurnRad(parseDouble(value.toString()));
                    break;
                case 6:
                    wp.getInLeg().setSpeedFromTtg(parseTime(value.toString()));
                    adjustStartTime();
                    break;
                case 7:
                    if (value == null) {
                        break;
                    }
                    // Try to change route given ETA
                    route.adjustEta(rowIndex, (EtaAdjust) value);
                    adjustStartTime();
                    break;
                case 10:
                    wp.getOutLeg().setHeading((Heading) value);
                    adjustStartTime();
                    notifyRouteListeners(RoutesUpdateEvent.ROUTE_CHANGED);
                    break;
                case 11:
                    wp.getOutLeg().setSpeed(parseDouble(value.toString()));
                    adjustStartTime();
                    break;
                case 12:
                    wp.getOutLeg().setXtdStarboard(parseDouble(value.toString()) / 1852.0);
                    break;
                case 13:
                    wp.getOutLeg().setXtdPort(parseDouble(value.toString()) / 1852.0);
                    break;
                case 14:
                    wp.getOutLeg().setSFLenInMilliseconds(parseTime(value.toString()));
                    break;
                default:
                }
                routeUpdated();
            } catch (Exception ex) {
                LOG.warn(String.format("Failed updating field '%s' in row %d: %s", COL_NAMES[columnIndex],
                        rowIndex, ex.getMessage()));
                JOptionPane.showMessageDialog(RoutePropertiesDialogCommon.this,
                        "Input error: " + ex.getMessage(), "Input error", JOptionPane.ERROR_MESSAGE);
            }
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return !readOnlyRoute && (columnIndex == 0 || !locked[rowIndex])
                    && (columnIndex < 8 || columnIndex > 9) && !(columnIndex == 6 && rowIndex == 0)
                    && !(columnIndex == 4 && rowIndex == 0) && (columnIndex != 5);

        }
    };
}

From source file:captureplugin.CapturePlugin.java

/**
 * Check the programs after data update.
 *//*from  w  w w . ja v  a2s .c o  m*/
public void handleTvDataUpdateFinished() {
    mNeedsUpdate = true;

    if (mAllowedToShowDialog) {
        mNeedsUpdate = false;

        DeviceIf[] devices = mConfig.getDeviceArray();

        final DefaultTableModel model = new DefaultTableModel() {
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };

        model.setColumnCount(5);
        model.setColumnIdentifiers(new String[] { mLocalizer.msg("device", "Device"),
                Localizer.getLocalization(Localizer.I18N_CHANNEL), mLocalizer.msg("date", "Date"),
                ProgramFieldType.START_TIME_TYPE.getLocalizedName(),
                ProgramFieldType.TITLE_TYPE.getLocalizedName() });

        JTable table = new JTable(model);
        table.getTableHeader().setReorderingAllowed(false);
        table.getTableHeader().setResizingAllowed(false);
        table.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() {
            public Component getTableCellRendererComponent(JTable renderTable, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column) {
                Component c = super.getTableCellRendererComponent(renderTable, value, isSelected, hasFocus, row,
                        column);

                if (value instanceof DeviceIf) {
                    if (((DeviceIf) value).getDeleteRemovedProgramsAutomatically() && !isSelected) {
                        c.setForeground(Color.red);
                    }
                }

                return c;
            }
        });

        int[] columnWidth = new int[5];

        for (int i = 0; i < columnWidth.length; i++) {
            columnWidth[i] = UiUtilities.getStringWidth(table.getFont(), model.getColumnName(i)) + 10;
        }

        for (DeviceIf device : devices) {
            Program[] deleted = device.checkProgramsAfterDataUpdateAndGetDeleted();

            if (deleted != null && deleted.length > 0) {
                for (Program p : deleted) {
                    if (device.getDeleteRemovedProgramsAutomatically() && !p.isExpired() && !p.isOnAir()) {
                        device.remove(UiUtilities.getLastModalChildOf(getParentFrame()), p);
                    } else {
                        device.removeProgramWithoutExecution(p);
                    }

                    if (!p.isExpired()) {
                        Object[] o = new Object[] { device, p.getChannel().getName(), p.getDateString(),
                                p.getTimeString(), p.getTitle() };

                        for (int i = 0; i < columnWidth.length; i++) {
                            columnWidth[i] = Math.max(columnWidth[i],
                                    UiUtilities.getStringWidth(table.getFont(), o[i].toString()) + 10);
                        }

                        model.addRow(o);
                    }
                }
            }

            device.getProgramList();
        }

        if (model.getRowCount() > 0) {
            int sum = 0;

            for (int i = 0; i < columnWidth.length; i++) {
                table.getColumnModel().getColumn(i).setPreferredWidth(columnWidth[i]);

                if (i < columnWidth.length - 1) {
                    table.getColumnModel().getColumn(i).setMaxWidth(columnWidth[i]);
                }

                sum += columnWidth[i];
            }

            JScrollPane scrollPane = new JScrollPane(table);
            scrollPane.setPreferredSize(new Dimension(450, 250));

            if (sum > 500) {
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                scrollPane.getViewport().setPreferredSize(
                        new Dimension(sum, scrollPane.getViewport().getPreferredSize().height));
            }

            JButton export = new JButton(mLocalizer.msg("exportList", "Export list"));
            export.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JFileChooser chooser = new JFileChooser();
                    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
                    chooser.setFileFilter(new FileFilter() {
                        public boolean accept(File f) {
                            return f.isDirectory() || f.toString().toLowerCase().endsWith(".txt");
                        }

                        public String getDescription() {
                            return "*.txt";
                        }
                    });

                    chooser.setSelectedFile(new File("RemovedPrograms.txt"));
                    if (chooser.showSaveDialog(
                            UiUtilities.getLastModalChildOf(getParentFrame())) == JFileChooser.APPROVE_OPTION) {
                        if (chooser.getSelectedFile() != null) {
                            String file = chooser.getSelectedFile().getAbsolutePath();

                            if (!file.toLowerCase().endsWith(".txt") && file.indexOf('.') == -1) {
                                file = file + ".txt";
                            }

                            if (file.indexOf('.') != -1) {
                                try {
                                    RandomAccessFile write = new RandomAccessFile(file, "rw");
                                    write.setLength(0);

                                    String eolStyle = File.separator.equals("/") ? "\n" : "\r\n";

                                    for (int i = 0; i < model.getRowCount(); i++) {
                                        StringBuilder line = new StringBuilder();

                                        for (int j = 0; j < model.getColumnCount(); j++) {
                                            line.append(model.getValueAt(i, j)).append(' ');
                                        }

                                        line.append(eolStyle);

                                        write.writeBytes(line.toString());
                                    }

                                    write.close();
                                } catch (Exception ee) {
                                }
                            }
                        }
                    }
                }
            });

            Object[] message = {
                    mLocalizer.msg("deletedText",
                            "The data was changed and the following programs were deleted:"),
                    scrollPane, export };

            JOptionPane pane = new JOptionPane();
            pane.setMessage(message);
            pane.setMessageType(JOptionPane.PLAIN_MESSAGE);

            final JDialog d = pane.createDialog(UiUtilities.getLastModalChildOf(getParentFrame()),
                    mLocalizer.msg("CapturePlugin", "CapturePlugin") + " - "
                            + mLocalizer.msg("deletedTitle", "Deleted programs"));
            d.setResizable(true);
            d.setModal(false);

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    d.setVisible(true);
                }
            });
        }
    }
}

From source file:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java

private void configureTree() {
    createNodes();//from   w  ww.  j  a  va  2s. c  om
    tree.setShowsRootHandles(true);
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final TreeSelectionEvent event) {
            ExtendedTreeNode node = (ExtendedTreeNode) tree.getLastSelectedPathComponent();
            if (node != null && (node.isAlgorithm() || node.isProblemChild() || node.isStopConditionChild()
                    || node.isMeassurementChild())) {
                configureTable((Entity) node.getUserObject());
            } else {
                table.setModel(new DefaultTableModel());
            }
        }
    });
}

From source file:com.smanempat.controller.ControllerClassification.java

public void showClassificationResult(JTable tableResult, JTable tablePreview, String[] knnValue,
        int rowCountData, JLabel labelSiswaIPA, JLabel labelSiswaIPS, JLabel labelKeterangan,
        JYearChooser jYearChooser1, JYearChooser jYearChooser2, int kValue) {
    DefaultTableModel tableModelResult = new DefaultTableModel();
    tableModelResult = (DefaultTableModel) tableResult.getModel();
    int jumlahSiswaIPA = 0;
    int jumlahSiswaIPS = 0;

    for (int i = 0; i < rowCountData; i++) {
        if (knnValue[i].equals("IPA")) {
            jumlahSiswaIPA = jumlahSiswaIPA + 1;
        } else if (knnValue[i].equalsIgnoreCase("IPS")) {
            jumlahSiswaIPS = jumlahSiswaIPS + 1;
        }//w w w .j ava2  s .com

        String nis = tablePreview.getValueAt(i, 0).toString();
        String nama = tablePreview.getValueAt(i, 1).toString();
        String jenKel = tablePreview.getValueAt(i, 2).toString();
        String nilaiUN = tablePreview.getValueAt(i, 3).toString();
        String ptBindo = tablePreview.getValueAt(i, 4).toString();
        String ptMtk = tablePreview.getValueAt(i, 5).toString();
        String ptBing = tablePreview.getValueAt(i, 6).toString();
        String ptIpa = tablePreview.getValueAt(i, 7).toString();
        String minat = tablePreview.getValueAt(i, 8).toString();
        String jurusan = knnValue[i];
        Object[] resultData = { nis, nama, jenKel, nilaiUN, ptBindo, ptMtk, ptBing, ptIpa, minat, jurusan };
        tableModelResult.addRow(resultData);
    }
    tableResult.setModel(tableModelResult);
    labelSiswaIPA.setText(jumlahSiswaIPA + "");
    labelSiswaIPS.setText(jumlahSiswaIPS + "");
    labelKeterangan.setText("Hasil Klasifikasi Penjurusan Siswa Pada Tahun Ajaran " + jYearChooser1.getYear()
            + "/" + jYearChooser2.getYear() + ", dengan paramater K = " + kValue + " adalah sebagai berikut ");
}

From source file:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java

private void configureTable(Object entity) {
    TableModel model = null;//from w w w. jav a  2  s. c o  m
    if (entity == null) {
        model = new DefaultTableModel();
    } else {
        String[] columnNames = new String[] { "Parameter", "Value" };
        Object[][] data = new Object[EntityPropertyManager.getParametersNameFromFields(entity).size()][2];
        prepareTableData(entity, data);

        model = new ExtendedTableModel(entity, columnNames, data);
    }
    table.setModel(model);
}

From source file:jp.massbank.spectrumsearch.SearchPage.java

/**
 * ?// w w  w  .ja  va  2  s .c o m
 */
private void createWindow() {

    // ??
    ToolTipManager ttm = ToolTipManager.sharedInstance();
    ttm.setInitialDelay(50);
    ttm.setDismissDelay(8000);

    // Search?
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    Border border = BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(),
            new EmptyBorder(1, 1, 1, 1));
    mainPanel.setBorder(border);

    // *********************************************************************
    // User File Query
    // *********************************************************************
    DefaultTableModel fileDm = new DefaultTableModel();
    fileSorter = new TableSorter(fileDm, TABLE_QUERY_FILE);
    queryFileTable = new JTable(fileSorter) {
        @Override
        public boolean isCellEditable(int row, int column) {
            //            super.isCellEditable(row, column);
            // ??????
            return false;
        }
    };
    queryFileTable.addMouseListener(new TblMouseListener());
    fileSorter.setTableHeader(queryFileTable.getTableHeader());
    queryFileTable.setRowSelectionAllowed(true);
    queryFileTable.setColumnSelectionAllowed(false);
    queryFileTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    String[] col = { COL_LABEL_NO, COL_LABEL_NAME, COL_LABEL_ID };
    ((DefaultTableModel) fileSorter.getTableModel()).setColumnIdentifiers(col);
    (queryFileTable.getColumn(queryFileTable.getColumnName(0))).setPreferredWidth(44);
    (queryFileTable.getColumn(queryFileTable.getColumnName(1))).setPreferredWidth(LEFT_PANEL_WIDTH - 44);
    (queryFileTable.getColumn(queryFileTable.getColumnName(2))).setPreferredWidth(70);

    ListSelectionModel lm = queryFileTable.getSelectionModel();
    lm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lm.addListSelectionListener(new LmFileListener());
    queryFilePane = new JScrollPane(queryFileTable);
    queryFilePane.addMouseListener(new PaneMouseListener());
    queryFilePane.setPreferredSize(new Dimension(300, 300));

    // *********************************************************************
    // Result
    // *********************************************************************
    DefaultTableModel resultDm = new DefaultTableModel();
    resultSorter = new TableSorter(resultDm, TABLE_RESULT);
    resultTable = new JTable(resultSorter) {
        @Override
        public String getToolTipText(MouseEvent me) {
            //            super.getToolTipText(me);
            // ?????
            Point pt = me.getPoint();
            int row = rowAtPoint(pt);
            if (row < 0) {
                return null;
            } else {
                int nameCol = getColumnModel().getColumnIndex(COL_LABEL_NAME);
                return " " + getValueAt(row, nameCol) + " ";
            }
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            //            super.isCellEditable(row, column);
            // ??????
            return false;
        }
    };
    resultTable.addMouseListener(new TblMouseListener());
    resultSorter.setTableHeader(resultTable.getTableHeader());

    JPanel dbPanel = new JPanel();
    dbPanel.setLayout(new BorderLayout());
    resultPane = new JScrollPane(resultTable);
    resultPane.addMouseListener(new PaneMouseListener());

    resultTable.setRowSelectionAllowed(true);
    resultTable.setColumnSelectionAllowed(false);
    resultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    String[] col2 = { COL_LABEL_NAME, COL_LABEL_SCORE, COL_LABEL_HIT, COL_LABEL_ID, COL_LABEL_ION,
            COL_LABEL_CONTRIBUTOR, COL_LABEL_NO };

    resultDm.setColumnIdentifiers(col2);
    (resultTable.getColumn(resultTable.getColumnName(0))).setPreferredWidth(LEFT_PANEL_WIDTH - 180);
    (resultTable.getColumn(resultTable.getColumnName(1))).setPreferredWidth(70);
    (resultTable.getColumn(resultTable.getColumnName(2))).setPreferredWidth(20);
    (resultTable.getColumn(resultTable.getColumnName(3))).setPreferredWidth(70);
    (resultTable.getColumn(resultTable.getColumnName(4))).setPreferredWidth(20);
    (resultTable.getColumn(resultTable.getColumnName(5))).setPreferredWidth(70);
    (resultTable.getColumn(resultTable.getColumnName(6))).setPreferredWidth(50);

    ListSelectionModel lm2 = resultTable.getSelectionModel();
    lm2.addListSelectionListener(new LmResultListener());

    resultPane.setPreferredSize(new Dimension(LEFT_PANEL_WIDTH, 200));
    dbPanel.add(resultPane, BorderLayout.CENTER);

    // *********************************************************************
    // DB Query
    // *********************************************************************
    DefaultTableModel dbDm = new DefaultTableModel();
    querySorter = new TableSorter(dbDm, TABLE_QUERY_DB);
    queryDbTable = new JTable(querySorter) {
        @Override
        public boolean isCellEditable(int row, int column) {
            //            super.isCellEditable(row, column);
            // ??????
            return false;
        }
    };
    queryDbTable.addMouseListener(new TblMouseListener());
    querySorter.setTableHeader(queryDbTable.getTableHeader());
    queryDbPane = new JScrollPane(queryDbTable);
    queryDbPane.addMouseListener(new PaneMouseListener());

    int h = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
    queryDbPane.setPreferredSize(new Dimension(LEFT_PANEL_WIDTH, h));
    queryDbTable.setRowSelectionAllowed(true);
    queryDbTable.setColumnSelectionAllowed(false);
    queryDbTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    String[] col3 = { COL_LABEL_ID, COL_LABEL_NAME, COL_LABEL_CONTRIBUTOR, COL_LABEL_NO };
    DefaultTableModel model = (DefaultTableModel) querySorter.getTableModel();
    model.setColumnIdentifiers(col3);

    // 
    queryDbTable.getColumn(queryDbTable.getColumnName(0)).setPreferredWidth(70);
    queryDbTable.getColumn(queryDbTable.getColumnName(1)).setPreferredWidth(LEFT_PANEL_WIDTH - 70);
    queryDbTable.getColumn(queryDbTable.getColumnName(2)).setPreferredWidth(70);
    queryDbTable.getColumn(queryDbTable.getColumnName(3)).setPreferredWidth(50);

    ListSelectionModel lm3 = queryDbTable.getSelectionModel();
    lm3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lm3.addListSelectionListener(new LmQueryDbListener());

    // ?
    JPanel btnPanel = new JPanel();
    btnName.addActionListener(new BtnSearchNameListener());
    btnAll.addActionListener(new BtnAllListener());
    btnPanel.add(btnName);
    btnPanel.add(btnAll);

    parentPanel2 = new JPanel();
    parentPanel2.setLayout(new BoxLayout(parentPanel2, BoxLayout.PAGE_AXIS));
    parentPanel2.add(btnPanel);
    parentPanel2.add(queryDbPane);

    // ?
    JPanel dispModePanel = new JPanel();
    isDispSelected = dispSelected.isSelected();
    isDispRelated = dispRelated.isSelected();
    if (isDispSelected) {
        resultTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    } else if (isDispRelated) {
        resultTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }
    Object[] retRadio = new Object[] { dispSelected, dispRelated };
    for (int i = 0; i < retRadio.length; i++) {
        ((JRadioButton) retRadio[i]).addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                if (isDispSelected != dispSelected.isSelected() || isDispRelated != dispRelated.isSelected()) {

                    isDispSelected = dispSelected.isSelected();
                    isDispRelated = dispRelated.isSelected();

                    // ??
                    resultTable.clearSelection();
                    resultPlot.clear();
                    compPlot.setPeaks(null, 1);
                    resultPlot.setPeaks(null, 0);
                    setAllPlotAreaRange();
                    pkgView.initResultRecInfo();

                    if (isDispSelected) {
                        resultTable.getSelectionModel()
                                .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
                    } else if (isDispRelated) {
                        resultTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                    }
                }
            }
        });
    }
    ButtonGroup disGroup = new ButtonGroup();
    disGroup.add(dispSelected);
    disGroup.add(dispRelated);
    dispModePanel.add(lbl2);
    dispModePanel.add(dispSelected);
    dispModePanel.add(dispRelated);

    JPanel paramPanel = new JPanel();
    paramPanel.add(etcPropertyButton);
    etcPropertyButton.setMargin(new Insets(0, 10, 0, 10));
    etcPropertyButton.addActionListener(new ActionListener() {
        private ParameterSetWindow ps = null;

        public void actionPerformed(ActionEvent e) {
            // ??????????
            if (!isSubWindow) {
                ps = new ParameterSetWindow(getParentFrame());
            } else {
                ps.requestFocus();
            }
        }
    });

    JPanel optionPanel = new JPanel();
    optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.Y_AXIS));
    optionPanel.add(dispModePanel);
    optionPanel.add(paramPanel);

    // PackageView?????
    pkgView = new PackageViewPanel();
    pkgView.initAllRecInfo();

    queryTabPane.addTab("DB", parentPanel2);
    queryTabPane.setToolTipTextAt(TAB_ORDER_DB, "Query from DB.");
    queryTabPane.addTab("File", queryFilePane);
    queryTabPane.setToolTipTextAt(TAB_ORDER_FILE, "Query from user file.");
    queryTabPane.setSelectedIndex(TAB_ORDER_DB);
    queryTabPane.setFocusable(false);
    queryTabPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {

            // ?
            queryPlot.clear();
            compPlot.clear();
            resultPlot.clear();
            queryPlot.setPeaks(null, 0);
            compPlot.setPeaks(null, 1);
            resultPlot.setPeaks(null, 0);

            // PackageView?
            pkgView.initAllRecInfo();

            // DB Hit?
            if (resultTabPane.getTabCount() > 0) {
                resultTabPane.setSelectedIndex(0);
            }
            DefaultTableModel dataModel = (DefaultTableModel) resultSorter.getTableModel();
            dataModel.setRowCount(0);
            hitLabel.setText(" ");

            // DB?User File??????
            queryTabPane.update(queryTabPane.getGraphics());
            if (queryTabPane.getSelectedIndex() == TAB_ORDER_DB) {
                parentPanel2.update(parentPanel2.getGraphics());
                updateSelectQueryTable(queryDbTable);
            } else if (queryTabPane.getSelectedIndex() == TAB_ORDER_FILE) {
                queryFilePane.update(queryFilePane.getGraphics());
                updateSelectQueryTable(queryFileTable);
            }
        }
    });

    //       
    JPanel queryPanel = new JPanel();
    queryPanel.setLayout(new BorderLayout());
    queryPanel.add(queryTabPane, BorderLayout.CENTER);
    queryPanel.add(optionPanel, BorderLayout.SOUTH);
    queryPanel.setMinimumSize(new Dimension(0, 170));

    JPanel jtp2Panel = new JPanel();
    jtp2Panel.setLayout(new BorderLayout());
    jtp2Panel.add(dbPanel, BorderLayout.CENTER);
    jtp2Panel.add(hitLabel, BorderLayout.SOUTH);
    jtp2Panel.setMinimumSize(new Dimension(0, 70));
    Color colorGreen = new Color(0, 128, 0);
    hitLabel.setForeground(colorGreen);

    resultTabPane.addTab("Result", jtp2Panel);
    resultTabPane.setToolTipTextAt(TAB_RESULT_DB, "Result of DB hit.");
    resultTabPane.setFocusable(false);

    queryPlot.setMinimumSize(new Dimension(0, 100));
    compPlot.setMinimumSize(new Dimension(0, 120));
    resultPlot.setMinimumSize(new Dimension(0, 100));
    int height = initAppletHight / 3;
    JSplitPane jsp_cmp2db = new JSplitPane(JSplitPane.VERTICAL_SPLIT, compPlot, resultPlot);
    JSplitPane jsp_qry2cmp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, queryPlot, jsp_cmp2db);
    jsp_cmp2db.setDividerLocation(height);
    jsp_qry2cmp.setDividerLocation(height - 25);
    jsp_qry2cmp.setMinimumSize(new Dimension(190, 0));

    viewTabPane.addTab("Compare View", jsp_qry2cmp);
    viewTabPane.addTab("Package View", pkgView);
    viewTabPane.setToolTipTextAt(TAB_VIEW_COMPARE, "Comparison of query and result spectrum.");
    viewTabPane.setToolTipTextAt(TAB_VIEW_PACKAGE, "Package comparison of query and result spectrum.");
    viewTabPane.setSelectedIndex(TAB_VIEW_COMPARE);
    viewTabPane.setFocusable(false);

    JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, queryPanel, resultTabPane);
    jsp.setDividerLocation(310);
    jsp.setMinimumSize(new Dimension(180, 0));
    jsp.setOneTouchExpandable(true);

    JSplitPane jsp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jsp, viewTabPane);
    int divideSize = (int) (initAppletWidth * 0.4);
    divideSize = (divideSize >= 180) ? divideSize : 180;
    jsp2.setDividerLocation(divideSize);
    jsp2.setOneTouchExpandable(true);

    mainPanel.add(jsp2, BorderLayout.CENTER);
    add(mainPanel);

    queryPlot.setSearchPage(this);
    compPlot.setSearchPage(this);
    resultPlot.setSearchPage(this);

    setJMenuBar(MenuBarGenerator.generateMenuBar(this));
}

From source file:dbseer.gui.chart.DBSeerChartFactory.java

public static JTable createErrorTable(PredictionCenter center) throws Exception {
    JTable errorTable = null;/*from   w w  w  . j  a v a2s. c om*/
    DefaultTableModel errorTableModel = null;
    StatisticalPackageRunner runner = DBSeerGUI.runner;

    Object[] maeList = (Object[]) runner.getVariableCell("meanAbsError");
    Object[] mreList = (Object[]) runner.getVariableCell("meanRelError");
    Object[] headers = (Object[]) runner.getVariableCell("errorHeader");

    if (maeList.length > 0 || mreList.length > 0) {
        errorTableModel = new DefaultTableModel() {
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        //errorTable = new JTable();
        errorTableModel.addColumn(null, new String[] { "", "MAE", "MRE" }); // first empty column

        final java.util.List<String> transactionNames = center.getTrainConfig().getDataset(0)
                .getTransactionTypeNames();
        for (int i = 0; i < maeList.length; ++i) {
            Object maeObj = maeList[i];
            Object mreObj = mreList[i];

            double[] mae = (double[]) maeObj;
            double[] mre = (double[]) mreObj;

            String header = (String) headers[i];
            for (int j = 0; j < transactionNames.size(); ++j) {
                if (header.contains("Type " + (j + 1))) {
                    headers[i] = header.replace("Type " + (j + 1), transactionNames.get(j));
                    break;
                }
            }

            errorTableModel.addColumn(null,
                    new Object[] { headers[i], String.format("%.3f", mae[0]), String.format("%.3f", mre[0]) });
        }
        errorTable = new JTable(errorTableModel);
    }

    return errorTable;
}

From source file:app.NewJFrame.java

private void buttonClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonClearActionPerformed
    // TODO add your handling code here:
    jTable1.setModel(new DefaultTableModel());
}

From source file:dataviewer.DataViewer.java

private void cb_tableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_tableActionPerformed
    try {/*from w w w.java2s .  c om*/
        table = cb_table.getSelectedItem().toString();
        DB db = new DB("./db/" + table + ".db");
        db.open();
        String[] cols = db.get_table_columns(table);
        db.close();

        DefaultTableModel model = new DefaultTableModel();
        //model.addColumn("Column Index");
        model.addColumn("Field");
        int i = 1;

        StyleContext sc = StyleContext.getDefaultStyleContext();
        TabSet tabs = new TabSet(new TabStop[] { new TabStop(20) });
        AttributeSet paraSet = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabs);
        tp_sql.setParagraphAttributes(paraSet, false);

        StyledDocument doc = tp_sql.getStyledDocument();

        doc.remove(0, doc.getLength());

        doc.insertString(doc.getLength(), "SELECT", null);
        doc.insertString(doc.getLength(), "\n", null);

        for (int j = 1; j < cols.length; ++j) {
            String s = cols[j];
            //model.addRow(new Object[]{i++, s});
            model.addRow(new Object[] { s });
            doc.insertString(doc.getLength(), "\t", null);
            doc.insertString(doc.getLength(), s, null);
            if (j < cols.length - 1) {
                doc.insertString(doc.getLength(), ",", null);
            }
            doc.insertString(doc.getLength(), "\n", null);
        }

        doc.insertString(doc.getLength(), "FROM", null);
        doc.insertString(doc.getLength(), "\n", null);
        doc.insertString(doc.getLength(), "\t", null);
        doc.insertString(doc.getLength(), table, null);
        /*doc.insertString(doc.getLength(), "\n", null);
         doc.insertString(doc.getLength(), "WHERE", null);
         doc.insertString(doc.getLength(), "\n", null);
         doc.insertString(doc.getLength(), "\t", null);
         doc.insertString(doc.getLength(), "_N_ <= " + N, null);
         doc.insertString(doc.getLength(), ";", null);*/

        tb_columns.setModel(model);

        TableRowSorter trs = new TableRowSorter(model);
        trs.setComparator(0, new IntComparator());
        tb_columns.setRowSorter(trs);

        //highline();
    } catch (Exception e) {
        txt_count.setText(e.getMessage());
    }
}

From source file:NewApplication.java

public void LoadTable(Class clazz) {

    model = new DefaultTableModel();

    Field[] fields = clazz.getDeclaredFields();

    Integer C = fields.length;/*  w  w  w  . j ava  2  s  .  c om*/

    model.setColumnCount(C);

    jTable1.setModel(model);

    for (int i = 0; i < C; i++) {

        TableColumn tc = jTable1.getColumnModel().getColumn(i);

        Field field = fields[i];

        tc.setHeaderValue(field.getName());

    }

    // Replace model

    jTable1.repaint();
}