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(Object[][] data, Object[] columnNames) 

Source Link

Document

Constructs a DefaultTableModel and initializes the table by passing data and columnNames to the setDataVector method.

Usage

From source file:Methods.CalculusBisection.java

public static DefaultTableModel getTableData() {// Method used to retrieve data from Stack and transform it in an array and populate a model table 

    Object[][] tableData = new Object[data[0].length][7];
    int i = (Xlower.size() - 1);

    while (!Xlower.isEmpty()) {//while statement used to retrieve data from stack and copy it in an 2d arrray
        tableData[i][1] = Double.parseDouble(Xlower.popElement1().toString());
        tableData[i][2] = Double.parseDouble(Xlower.popElement2().toString());
        tableData[i][3] = Double.parseDouble(Xupper.popElement1().toString());
        tableData[i][4] = Double.parseDouble(Xupper.popElement2().toString());
        i--;// ww w.  j  a va2s  .c  om
    }

    for (i = 0; i < data[0].length; i++) {
        tableData[i][0] = i + 1;
        tableData[i][5] = data[0][i];
        tableData[i][6] = data[1][i];
    }

    String[] columnNames = { "Iteration", "Xlower", "f(Xlower)", "Xupper", "f(Xupper)", "Xnew", "f(Xnew)" };

    DefaultTableModel model = new DefaultTableModel(tableData, columnNames);

    return model;
}

From source file:com.qspin.qtaste.ui.reporter.TestCaseReportTable.java

private void init() {
    final String tableLayoutProperty = interactive ? INTERACTIVE_TABLE_LAYOUT_PROPERTY
            : EXECUTION_TABLE_LAYOUT_PROPERTY;
    final String statusColumnProperty = tableLayoutProperty + ".status";
    final String testCaseColumnProperty = tableLayoutProperty + ".test_case";
    final String detailsColumnProperty = tableLayoutProperty + ".details";
    final String testbedColumnProperty = tableLayoutProperty + ".testbed";
    final String resultColumnProperty = tableLayoutProperty + ".result";

    tcModel = new DefaultTableModel(
            new Object[] { "Status", "Test Case", "Details", "Result", "Testbed", "Time", "." }, 0) {

        @Override//from  www. j  a  v a 2 s. com
        public Class<?> getColumnClass(int columnIndex) {
            Class<?> dataType = super.getColumnClass(columnIndex);
            if (columnIndex == STATUS) {
                dataType = Icon.class;
            }
            return dataType;
        }

        @Override
        public boolean isCellEditable(int rowIndex, int mColIndex) {
            return false;
        }
    };
    tcTable = new SortableJTable(new TableSorter(tcModel)) {

        public String getToolTipText(MouseEvent e) {
            Point p = e.getPoint();
            int rowIndex = rowAtPoint(p);
            int colIndex = columnAtPoint(p);
            if (colIndex < 0) {
                return null;
            }
            return convertObjectToToolTip(getValueAt(rowIndex, colIndex));
        }
    };
    tcTable.setColumnSelectionAllowed(false);

    int tcWidth = interactive ? 360 : 480;
    int tcStatusWidth = 40;
    int tcTestbedWidth = 100;
    int tcDetailsWidth = 360;
    int tcResultWidth = 150;
    GUIConfiguration guiConfiguration = GUIConfiguration.getInstance();
    List<?> list = guiConfiguration.configurationsAt(tableLayoutProperty);
    if (!list.isEmpty()) {
        try {
            tcWidth = guiConfiguration.getInt(testCaseColumnProperty);
        } catch (NoSuchElementException ex) {
            guiConfiguration.setProperty(testCaseColumnProperty, tcWidth);
        }
        try {
            tcStatusWidth = guiConfiguration.getInt(statusColumnProperty);
        } catch (NoSuchElementException ex) {
            guiConfiguration.setProperty(statusColumnProperty, tcStatusWidth);
        }
        try {
            tcDetailsWidth = guiConfiguration.getInt(detailsColumnProperty);
        } catch (NoSuchElementException ex) {
            guiConfiguration.setProperty(detailsColumnProperty, tcDetailsWidth);
        }
        try {
            tcTestbedWidth = guiConfiguration.getInt(testbedColumnProperty);
        } catch (NoSuchElementException ex) {
            guiConfiguration.setProperty(testbedColumnProperty, tcTestbedWidth);
        }
        if (interactive) {
            try {
                tcResultWidth = guiConfiguration.getInt(resultColumnProperty);
            } catch (NoSuchElementException ex) {
                guiConfiguration.setProperty(resultColumnProperty, tcResultWidth);
            }
        }
    } else {
        tcWidth = interactive ? 360 : 480;

        guiConfiguration.setProperty(testCaseColumnProperty, tcWidth);
        guiConfiguration.setProperty(statusColumnProperty, tcStatusWidth);
        guiConfiguration.setProperty(detailsColumnProperty, tcDetailsWidth);
        guiConfiguration.setProperty(testbedColumnProperty, tcTestbedWidth);
        if (interactive) {
            guiConfiguration.setProperty(resultColumnProperty, tcResultWidth);
        }
        try {
            guiConfiguration.save();
        } catch (ConfigurationException ex) {
            logger.error("Error while saving GUI configuration: " + ex.getMessage());
        }
    }

    TableColumnModel tcTableColumnModel = tcTable.getColumnModel();
    tcTableColumnModel.getColumn(TEST_CASE).setPreferredWidth(tcWidth);
    tcTableColumnModel.getColumn(STATUS).setPreferredWidth(tcStatusWidth);
    tcTableColumnModel.getColumn(STATUS).setMaxWidth(40);
    tcTableColumnModel.getColumn(DETAILS).setPreferredWidth(tcDetailsWidth);
    tcTableColumnModel.getColumn(TESTBED).setPreferredWidth(tcTestbedWidth);
    tcTableColumnModel.getColumn(EXEC_TIME).setPreferredWidth(70);
    tcTableColumnModel.getColumn(EXEC_TIME).setMinWidth(70);
    tcTableColumnModel.getColumn(EXEC_TIME).setMaxWidth(70);
    tcTableColumnModel.removeColumn(tcTableColumnModel.getColumn(TC));
    if (!interactive) {
        tcTable.getSelectionModel().addListSelectionListener(new TCResultsSelectionListeners());
    }
    tcTable.setName("tcTable");
    tcTableColumnModel.addColumnModelListener(new TableColumnModelListener() {

        public void columnAdded(TableColumnModelEvent e) {
        }

        public void columnRemoved(TableColumnModelEvent e) {
        }

        public void columnMoved(TableColumnModelEvent e) {
        }

        public void columnMarginChanged(ChangeEvent e) {
            try {
                // save the current layout
                int tcStatusWidth = tcTable.getColumnModel().getColumn(STATUS).getWidth();
                int tcWidth = tcTable.getColumnModel().getColumn(TEST_CASE).getWidth();
                int tcDetailsWidth = tcTable.getColumnModel().getColumn(DETAILS).getWidth();
                int tcResultWidth = tcTable.getColumnModel().getColumn(RESULT).getWidth();
                int tcTestbedWidth = tcTable.getColumnModel().getColumn(TESTBED).getWidth();
                // save it into the settings
                GUIConfiguration guiConfiguration = GUIConfiguration.getInstance();
                guiConfiguration.setProperty(statusColumnProperty, tcStatusWidth);
                guiConfiguration.setProperty(testCaseColumnProperty, tcWidth);
                guiConfiguration.setProperty(detailsColumnProperty, tcDetailsWidth);
                guiConfiguration.setProperty(testbedColumnProperty, tcTestbedWidth);
                if (interactive) {
                    guiConfiguration.setProperty(resultColumnProperty, tcResultWidth);
                }
                guiConfiguration.save();
            } catch (ConfigurationException ex) {
                logger.error("Error while saving GUI configuration: " + ex.getMessage());
            }
        }

        public void columnSelectionChanged(ListSelectionEvent e) {
        }
    });

    try {
        tcTable.setDefaultRenderer(Class.forName("java.lang.Object"), new TableCellRenderer());
    } catch (ClassNotFoundException ex) {
    }

    if (interactive) {
        displayTableForInteractiveMode();
    } else {
        displayTableForExecutionMode();
    }

    tcTable.addMouseListener(new TableMouseListener());

    // use timer for updating elapsed time every seconds
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            updateRunningTestCaseElapsedTime();
        }
    }, 1000, 1000);
}

From source file:cloud.gui.CloudGUI.java

private void createSnapshotTable() {
    snapshotModel = new DefaultTableModel(new String[][] {}, snapshotTableColumns);
    snapshotTable = new JTable(snapshotModel) {
        private static final long serialVersionUID = 6454534842446167244L;

        public boolean isCellEditable(int rowIndex, int colIndex) {
            return false;
        }/*from  w w w . ja v a2s .com*/
    };

    snapshotTable.addMouseListener(snapshotPopupListener);
    snapshotTable.getColumnModel().getColumn(0).setPreferredWidth(20);
    JScrollPane pane = new JScrollPane(snapshotTable);
    snapshotPanel.add(pane);

}

From source file:edu.harvard.i2b2.patientMapping.ui.PatientMappingJPanel.java

/** Creates new form PatientMappingJPanel */
public PatientMappingJPanel(java.awt.Container oAwtContainer) {
    columns = new ArrayList<SiteColumnData>();

    initComponents();//from  w w w  .  j av a2  s  .c o  m
    DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
    //model.addColumn("addedColumn1");
    //model.addColumn("addedColumn2");

    String[] columns = new String[3];
    columns[0] = new String("HIVE");
    columns[1] = new String("");
    columns[2] = new String("");
    //columns[3] = new String("");
    DefaultTableModel model1 = new DefaultTableModel(columns, 100);
    jTable1.setModel(model1);
    jTable1.setCellSelectionEnabled(true);
    TableColumn col = jTable1.getColumnModel().getColumn(0);
    DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
    dtcr.setHorizontalAlignment(SwingConstants.CENTER);
    col.setCellRenderer(dtcr);
    //jTable1.setCellSelectionEnabled(false);
    //model.setRowCount(100);
    //model.setValueAt(235600004, 0, 4);
    //model.setValueAt(235600005, 1, 5);
    //model.setValueAt(235600006, 5, 4);
    //model.setValueAt(235600007, 5, 5);
    //model.setValueAt(235600008, 6, 5);

    thisPanel = this;
    parent = oAwtContainer;

    //this.jLeftButton.setEnabled(false);
    this.jRightButton.setEnabled(false);
    this.jStartTextField.setEditable(false);
    this.jIncrementTextField.setEditable(false);
    //jAutoSaveCheckBox.setSelected(true);
}

From source file:generadorqr.jifrGestionArticulos.java

public static DefaultTableModel LlenarTablaArticulosporCategora() {
    try {/*w w  w. j av  a2 s.  c  o m*/
        String titulos[] = { "ID", "CATEGORIA", "NOMBRE", "CANTIDAD", "DESCRIPCION", "IMG 1", "IMG 2", "IMG 3",
                "SONIDO", "VIDEO", "IMAGEN QR" };
        String SQLTA = "SELECT a.IDARTICULO, c.NOMBRECATEGORIA, a.NOMBREARTICULO,a.CANTIDADARTICULO, a.DESCRIPCIONARTICULO, a.IMAGENUNOARTICULO, a.IMAGENDOSARTICULO, a.IMAGENTRESARTICULO, a.SONIDOARTICULO, a.VIDEOARTICULO, a.IMAGENQRARTICULO FROM articulos AS a INNER JOIN categorias AS c USING(IDCATEGORIA) WHERE c.IDCATEGORIA = "
                + ItemSeleccionado.idCategoria + " ORDER BY a.IDARTICULO ASC";
        DefaultTableModel model = new DefaultTableModel(null, titulos);
        Statement sent = conn.createStatement();
        ResultSet rs = sent.executeQuery(SQLTA);
        String[] fila = new String[11];
        while (rs.next()) {
            fila[0] = rs.getString("IDARTICULO");
            fila[1] = rs.getString("NOMBRECATEGORIA");
            fila[2] = rs.getString("NOMBREARTICULO");
            fila[3] = rs.getString("CANTIDADARTICULO");
            fila[4] = rs.getString("DESCRIPCIONARTICULO");
            fila[5] = rs.getString("IMAGENUNOARTICULO");
            fila[6] = rs.getString("IMAGENDOSARTICULO");
            fila[7] = rs.getString("IMAGENTRESARTICULO");
            fila[8] = rs.getString("SONIDOARTICULO");
            fila[9] = rs.getString("VIDEOARTICULO");
            fila[10] = rs.getString("IMAGENQRARTICULO");
            model.addRow(fila);
        }
        return model;
    } catch (Exception e) {
        return null;
    }
}

From source file:canreg.client.gui.dataentry.PDSEditorInternalFrame.java

private void refreshPopulationDataSetTable() {
    AgeGroupStructure ags = (AgeGroupStructure) ageGroupStructureComboBox.getSelectedItem();
    String[] ageGroupNames = ags.getAgeGroupNames();
    String[][] ageGroupLabels = new String[ageGroupNames.length][];

    for (int i = 0; i < ageGroupNames.length; i++) {
        ageGroupLabels[i] = new String[] { ageGroupNames[i] };
    }// w w  w.j  ava 2  s . co m

    ageGroupLabelsTable.setModel(new DefaultTableModel(ageGroupLabels,
            new String[] { java.util.ResourceBundle
                    .getBundle("canreg/client/gui/dataentry/resources/PDSEditorInternalFrame")
                    .getString("AGE_GROUP") }) {

        Class[] types = new Class[] { java.lang.String.class };
        boolean[] canEdit = new boolean[] { false };

        @Override
        public Class getColumnClass(int columnIndex) {
            return types[columnIndex];
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
        }
    });

    PopulationDatasetsEntry[] ageGroups;
    Object[][] pdsTableData = new Object[ageGroupNames.length][2];

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

    if (pds != null) {
        ageGroups = pds.getAgeGroups();
        for (PopulationDatasetsEntry pdse : ageGroups) {
            if (pdse.getAgeGroup() < pdsTableData.length && pdse.getSex() <= 2) {
                pdsTableData[pdse.getAgeGroup()][pdse.getSex() - 1] = pdse.getCount();
            } else {
                Logger.getLogger(PDSEditorInternalFrame.class.getName()).log(Level.WARNING, "{0}{1} {2}",
                        new Object[] { java.util.ResourceBundle
                                .getBundle("canreg/client/gui/dataentry/resources/PDSEditorInternalFrame")
                                .getString("OUTSIDE_SKOPE:_"), pdse.getAgeGroup(), pdse.getSex() });
            }
        }
    }

    pdsTable.setModel(new javax.swing.table.DefaultTableModel(pdsTableData, new String[] {
            java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/PDSEditorInternalFrame")
                    .getString("MALE"),
            java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/PDSEditorInternalFrame")
                    .getString("FEMALE") }) {

        Class[] types = new Class[] { java.lang.Integer.class, java.lang.Integer.class };
        boolean[] canEdit = new boolean[] { true, true };

        @Override
        public Class getColumnClass(int columnIndex) {
            return types[columnIndex];
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
        }
    });
    updateTotals();
}

From source file:regresiones.RegresionSimple.java

public void Resolver(JTabbedPane resultados) {

    for (int i = 0; i < 9; i++) {
        sumatorias[i] = 0.0;/*w  w w .j av a  2s .c o m*/
    }
    try {
        System.out.println("TOTAL DE DATOS: " + N);
        for (int i = 0; i < N; i++) {
            xiyi[i] = datos[i][0] * datos[i][1];
            System.out.println("X*Y" + i + ": " + xiyi[i]);
            x2[i] = datos[i][0] * datos[i][0]; //elevamos al cuadrado las x's
            y2[i] = datos[i][1] * datos[i][1]; //elevamos al cuadrado las y's
            sumatorias[0] += datos[i][0]; //sumatoria de x
            sumatorias[1] += datos[i][1]; //sumatoria de y

        }
        //sumatoria de xi*yi
        for (int j = 0; j < N; j++) {
            sumatorias[2] += xiyi[j];
        }

        //sumatoria de x^2
        for (int j = 0; j < N; j++) {
            sumatorias[3] += x2[j];
        }

        //sumatoria de y^2
        for (int j = 0; j < N; j++) {
            sumatorias[4] += y2[j];
        }

        mediax = sumatorias[0] / N;
        mediay = sumatorias[1] / N;

        System.out.println("RAIS 25: " + Math.sqrt(25));

        DecimalFormat df = new DecimalFormat("##.##");
        df.setRoundingMode(RoundingMode.DOWN);
        System.out.println("redondeo x^2-- " + df.format(sumatorias[3]));
        System.out.println("redondeo y^2-- " + df.format(sumatorias[4]));
        redondeoSumatoriax2 = Double.parseDouble(df.format(sumatorias[3]));
        redondeoSumatoriay2 = Double.parseDouble(df.format(sumatorias[4]));
        dxy = ((sumatorias[2]) / N) - mediax * mediay;
        dy = Math.sqrt(((redondeoSumatoriay2 / N) - (mediay * mediay)));
        dx = Math.sqrt(((redondeoSumatoriax2 / N) - (mediax * mediax)));

        b1 = ((sumatorias[2] * N) - sumatorias[0] * sumatorias[1])
                / ((sumatorias[3] * N) - (sumatorias[0] * sumatorias[0]));
        b0 = (sumatorias[1] / N) - ((b1 * sumatorias[0]) / N);

        // Y ESTIMADA
        for (int i = 0; i < N; i++) {
            yEstimada[i] = b0 + (b1 * datos[i][0]);
        }

        Se = Math.sqrt((sumatorias[4] - (b0 * sumatorias[1]) - (b1 * sumatorias[2])) / (N - 2));
        r = dxy / (dx * dy);
        System.out.println("sum x: " + sumatorias[0]);
        System.out.println("sum y: " + sumatorias[1]);
        System.out.println("sum x*y: " + sumatorias[2]);
        System.out.println("sum x^2: " + sumatorias[3]);
        System.out.println("sum y^2: " + sumatorias[4]);
        System.out.println("DX7: " + dxy);
        System.out.println("DY: " + dy);
        System.out.println("DX: " + dx);
        System.out.println("B0: " + b0);
        System.out.println("B1: " + b1);

        // mostramos resultados para la pestaa resultados***********************************************************************
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBackground(Color.white);
        JLabel titulo = new JLabel("Resultados");//creamos el titulo
        panel.add(titulo, BorderLayout.PAGE_START);//lo agregamos al inicio
        jtable = new JTable();//creamos la tabla a mostrar
        jtable.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 0), 2, true));
        jtable.setFont(new java.awt.Font("Arial", 1, 14));
        jtable.setColumnSelectionAllowed(true);
        jtable.setCursor(new java.awt.Cursor(java.awt.Cursor.N_RESIZE_CURSOR));
        jtable.setInheritsPopupMenu(true);
        jtable.setMinimumSize(new java.awt.Dimension(80, 80));
        String[] titulos = { "X", "Y", "Xi*Yi", "X2", "Y2", "Y estimada" };//los titulos de la tabla
        arregloFinal = new String[N][6];
        DecimalFormat formato = new DecimalFormat("0.00");
        for (int i = 0; i < N; i++) {//armamos el arreglo
            arregloFinal[i][0] = datos[i][0] + ""; //X
            arregloFinal[i][1] = datos[i][1] + "";//Y
            arregloFinal[i][2] = formato.format(xiyi[i]);
            arregloFinal[i][3] = formato.format(x2[i]);
            arregloFinal[i][4] = formato.format(y2[i]);
            arregloFinal[i][5] = formato.format(yEstimada[i]);
        }
        DefaultTableModel TableModel = new DefaultTableModel(arregloFinal, titulos);
        jtable.setModel(TableModel);
        JScrollPane jScrollPane1 = new JScrollPane();
        jScrollPane1.setViewportView(jtable);
        jtable.getColumnModel().getSelectionModel()
                .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        panel.add(jScrollPane1, BorderLayout.CENTER);
        JPanel panel2 = new JPanel(new GridLayout(0, 4));//creo un panel con rejilla de 4 columnas
        JLabel etiquetaN = new JLabel("N");
        JTextField cajaN = new JTextField();
        cajaN.setText(N + "");
        JLabel etiquetab0 = new JLabel("b0");
        JTextField cajab0 = new JTextField();
        cajab0.setText(b0 + "");
        JLabel etiquetab1 = new JLabel("b1");
        JTextField cajab1 = new JTextField();
        cajab1.setText(b1 + "");
        JLabel etiquetadxy = new JLabel("DXy");
        JTextField cajadxy = new JTextField();
        cajadxy.setText(dxy + "");
        JLabel etiquetadx = new JLabel("DX");
        JTextField cajadx = new JTextField();
        cajadx.setText(dx + "");
        JLabel etiquetady = new JLabel("DY");
        JTextField cajady = new JTextField();
        cajady.setText(dy + "");
        JLabel etiquetaR = new JLabel("R");
        JTextField cajaR = new JTextField();
        cajaR.setText(r + "");
        JLabel etiquetaSE = new JLabel("SE");
        JTextField cajaSE = new JTextField();
        cajaSE.setText(Se + "");
        JButton boton = new JButton("Exportar a PDF");
        boton.addActionListener(this);
        panel2.add(etiquetaN);
        panel2.add(cajaN);
        panel2.add(etiquetab0);
        panel2.add(cajab0);
        panel2.add(etiquetab1);
        panel2.add(cajab1);
        panel2.add(etiquetadxy);
        panel2.add(cajadxy);
        panel2.add(etiquetadx);
        panel2.add(cajadx);
        panel2.add(etiquetady);
        panel2.add(cajady);
        panel2.add(etiquetaR);
        panel2.add(cajaR);
        panel2.add(etiquetaSE);
        panel2.add(cajaSE);
        panel2.add(boton);
        panel.add(panel2, BorderLayout.SOUTH);//agrego el panel2 con rejilla en el panel principal al sur
        resultados.addTab("resultado", panel);
        //**************************************************************************************
        //intervalos de confianza
        JPanel intervalos = new JPanel(new BorderLayout());
        JPanel variables = new JPanel(new GridLayout(0, 2));
        JLabel variableX1 = new JLabel("X1");
        cajaVariableX1 = new JTextField();
        boton = new JButton("calcular");
        boton.addActionListener(this);
        JLabel variableEfectividad = new JLabel("Efectividad");
        String[] efectividades = { "80", "85", "90", "95", "99" };
        combo = new JComboBox(efectividades);
        variables.add(variableX1);
        variables.add(cajaVariableX1);
        variables.add(variableEfectividad);
        variables.add(combo);
        variables.add(boton);//comentario
        //cometario2
        intervalos.add(variables, BorderLayout.NORTH);
        jtable2 = new JTable();//creamos la tabla a mostrar
        jtable2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 0), 2, true));
        jtable2.setFont(new java.awt.Font("Arial", 1, 14));
        jtable2.setColumnSelectionAllowed(true);
        jtable2.setCursor(new java.awt.Cursor(java.awt.Cursor.N_RESIZE_CURSOR));
        jtable2.setInheritsPopupMenu(true);
        jtable2.setMinimumSize(new java.awt.Dimension(80, 80));
        String[] titulos2 = { "Y estimada", "Li", "Ls" };//los titulos de la tabla
        String[][] pruebaIntervalos = { { "", "", "" } };
        DefaultTableModel TableModel2 = new DefaultTableModel(pruebaIntervalos, titulos2);
        jtable2.setModel(TableModel2);
        JScrollPane jScrollPane2 = new JScrollPane();
        jScrollPane2.setViewportView(jtable2);
        jtable2.getColumnModel().getSelectionModel()
                .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        intervalos.add(jScrollPane2, BorderLayout.CENTER);
        resultados.addTab("intervalos", intervalos);
        // ***********************************************************************
        JPanel graficas = new JPanel(new GridLayout(0, 1));
        XYDataset dataset = createSampleDataset();
        JFreeChart chart = ChartFactory.createXYLineChart("Grafica", "X", "Y", dataset,
                PlotOrientation.VERTICAL, true, false, false);
        XYPlot plot = (XYPlot) chart.getPlot();
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(0, true);
        renderer.setSeriesShapesVisible(0, true);
        renderer.setSeriesLinesVisible(1, true);
        renderer.setSeriesShapesVisible(1, true);
        plot.setRenderer(renderer);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
        graficas.add(chartPanel);//agregamos la primer grafica
        resultados.addTab("Graficas", graficas);
        //IMPRIMIR JTABLE
        /* MessageFormat headerFormat = new MessageFormat("MI CABECERA");
         MessageFormat footerFormat = new MessageFormat("- Pgina {0} -");
         jtable.print(PrintMode.FIT_WIDTH, headerFormat, footerFormat);
         */

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

From source file:Methods.CalculusNewtonRaphson.java

public static DefaultTableModel getTableData() {// Method used to retrieve data from the linked lists transform it in an array and populate a model table 

    Object[][] tableData = new Object[xNewLinkedList.size()][5];
    int i = 0;//  ww  w.  j  a  v a2 s  .  c om

    xNewHead = xNewLinkedList.head;
    xHead = xLinkedList.head;
    xNewHead = xNewHead.getNext();
    xHead = xHead.getNext();
    while (xNewHead != null) {//while statement used to retrieve data from linked list and copy it in an 2d arrray
        tableData[i][0] = i + 1;
        tableData[i][1] = xNewHead.getElement1();
        tableData[i][2] = xNewHead.getElement2();
        tableData[i][3] = xHead.getElement1();
        tableData[i][4] = xHead.getElement2();

        i++;
        xNewHead = xNewHead.getNext();
        xHead = xHead.getNext();
    }

    String[] columnNames = { "Iteration", "Xold", "f(Xold)", "Xnew", "f(Xnew)" };

    DefaultTableModel model = new DefaultTableModel(tableData, columnNames);

    return model;
}

From source file:regresiones.RegresionMultiple.java

private void pintar(Double[] Yestimada, JTabbedPane resultados, Double[][] auxiliar) {
    // mostramos resultados para la pestaa resultados***********************************************************************
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBackground(Color.white);
    JLabel titulo = new JLabel("Resultados");//creamos el titulo
    panel.add(titulo, BorderLayout.PAGE_START);//lo agregamos al inicio
    jtable = new JTable();//creamos la tabla a mostrar
    jtable.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 0), 2, true));
    jtable.setFont(new java.awt.Font("Arial", 1, 14));
    jtable.setColumnSelectionAllowed(true);
    jtable.setCursor(new java.awt.Cursor(java.awt.Cursor.N_RESIZE_CURSOR));
    jtable.setInheritsPopupMenu(true);//  ww  w. ja va2  s.c o  m
    jtable.setMinimumSize(new java.awt.Dimension(80, 80));
    String[] titulos = { "X1", "X2", "Y", "Y estimada", "X1^2", "X2^2", "X1*Y", "X2*Y", "Y-Y estimada" };//los titulos de la tabla
    arregloFinal = new String[N][9];
    DecimalFormat formato = new DecimalFormat("0.00");
    for (int i = 0; i < N; i++) {//armamos el arreglo
        arregloFinal[i][0] = datos[i][0] + "";
        arregloFinal[i][1] = datos[i][1] + "";
        arregloFinal[i][2] = datos[i][2] + "";
        arregloFinal[i][3] = formato.format(Yestimada[i]);
        arregloFinal[i][4] = formato.format(auxiliar[i][0]);
        arregloFinal[i][5] = formato.format(auxiliar[i][1]);
        arregloFinal[i][6] = formato.format(auxiliar[i][2]);
        arregloFinal[i][7] = formato.format(auxiliar[i][3]);
        arregloFinal[i][8] = formato.format(auxiliar[i][4]);
    }
    DefaultTableModel TableModel = new DefaultTableModel(arregloFinal, titulos);
    jtable.setModel(TableModel);
    JScrollPane jScrollPane1 = new JScrollPane();
    jScrollPane1.setViewportView(jtable);
    jtable.getColumnModel().getSelectionModel()
            .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

    panel.add(jScrollPane1, BorderLayout.CENTER);
    JPanel panel2 = new JPanel(new GridLayout(0, 6));//creo un panel con rejilla de 4 columnas
    JLabel etiquetaN = new JLabel("N");
    JTextField cajaN = new JTextField();
    cajaN.setText(N + "");
    cajaN.setEditable(false);

    JLabel etiquetaK = new JLabel("K");
    JTextField cajaK = new JTextField();
    cajaK.setText("2");
    cajaK.setEditable(false);

    JLabel etiquetab0 = new JLabel("b0");
    JTextField cajab0 = new JTextField();
    cajab0.setText(formato.format(b0) + "");
    cajab0.setEditable(false);

    JLabel etiquetab1 = new JLabel("b1");
    JTextField cajab1 = new JTextField();
    cajab1.setText(formato.format(b1) + "");
    cajab1.setEditable(false);

    JLabel etiquetab2 = new JLabel("b2");
    JTextField cajab2 = new JTextField();
    cajab2.setText(formato.format(b2) + "");
    cajab2.setEditable(false);

    JLabel etiquetaSe = new JLabel("Se");
    JTextField cajaSe = new JTextField();
    cajaSe.setText(Se + "");
    cajaSe.setEditable(false);
    cajaSe.setAutoscrolls(true);

    JButton botonI = new JButton("Exportar a PDF");
    botonI.addActionListener(this);

    panel2.add(etiquetaN);
    panel2.add(cajaN);
    panel2.add(etiquetaK);
    panel2.add(cajaK);
    panel2.add(etiquetab2);
    panel2.add(etiquetab0);
    panel2.add(cajab0);
    panel2.add(etiquetab1);
    panel2.add(cajab1);
    panel2.add(etiquetab2);
    panel2.add(cajab2);
    panel2.add(etiquetaSe);
    panel2.add(cajaSe);
    panel2.add(botonI);
    panel.add(panel2, BorderLayout.SOUTH);//agrego el panel2 con rejilla en el panel principal al sur
    resultados.addTab("resultado", panel);
    //**************************************************************************************
    //intervalos de confianza
    JPanel intervalos = new JPanel(new BorderLayout());
    JPanel variables = new JPanel(new GridLayout(0, 2));
    JLabel variableX1 = new JLabel("X1");
    cajaVariableX1 = new JTextField();
    JLabel variableX2 = new JLabel("X2");
    cajaVariableX2 = new JTextField();
    boton = new JButton("calcular");
    boton.addActionListener(this);
    JLabel variableEfectividad = new JLabel("Efectividad");
    String[] efectividades = { "80", "85", "90", "95", "99" };
    combo = new JComboBox(efectividades);
    variables.add(variableX1);
    variables.add(cajaVariableX1);
    variables.add(variableX2);
    variables.add(cajaVariableX2);
    variables.add(variableEfectividad);
    variables.add(combo);
    variables.add(boton);
    intervalos.add(variables, BorderLayout.NORTH);
    jtable2 = new JTable();//creamos la tabla a mostrar
    jtable2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 0), 2, true));
    jtable2.setFont(new java.awt.Font("Arial", 1, 14));
    jtable2.setColumnSelectionAllowed(true);
    jtable2.setCursor(new java.awt.Cursor(java.awt.Cursor.N_RESIZE_CURSOR));
    jtable2.setInheritsPopupMenu(true);
    jtable2.setMinimumSize(new java.awt.Dimension(80, 80));
    String[] titulos2 = { "Y estimada", "Li", "Ls" };//los titulos de la tabla
    String[][] pruebaIntervalos = { { "", "", "" } };
    DefaultTableModel TableModel2 = new DefaultTableModel(pruebaIntervalos, titulos2);
    jtable2.setModel(TableModel2);
    JScrollPane jScrollPane2 = new JScrollPane();
    jScrollPane2.setViewportView(jtable2);
    jtable2.getColumnModel().getSelectionModel()
            .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    intervalos.add(jScrollPane2, BorderLayout.CENTER);
    resultados.addTab("intervalos", intervalos);
    //***************************************************************************
    JPanel graficas = new JPanel(new GridLayout(0, 1));
    XYDataset dataset = createSampleDataset(Yestimada, 1);
    JFreeChart chart = ChartFactory.createXYLineChart("Grafica 1 - X1", "X", "Y", dataset,
            PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(1, true);
    plot.setRenderer(renderer);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
    graficas.add(chartPanel);//agregamos la primer grafica
    //********** creamos la segunda grafica
    XYDataset dataset2 = createSampleDataset(Yestimada, 2);
    JFreeChart chart2 = ChartFactory.createXYLineChart("Grafica 2 -X2", "X", "Y", dataset2,
            PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot2 = (XYPlot) chart2.getPlot();
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setSeriesLinesVisible(0, true);
    renderer2.setSeriesShapesVisible(0, true);
    renderer2.setSeriesLinesVisible(1, true);
    renderer2.setSeriesShapesVisible(1, true);
    plot2.setRenderer(renderer2);
    final ChartPanel chartPanel2 = new ChartPanel(chart2);
    chartPanel2.setPreferredSize(new java.awt.Dimension(500, 300));
    graficas.add(chartPanel2);
    resultados.addTab("graficas", graficas);
}

From source file:com.willwinder.universalgcodesender.uielements.panels.ControllerProcessorSettingsPanel.java

private JTable initCustomRemoverTable(JTable table) {
    final String[] columnNames = { Localization.getString("settings.processors.enabled"),
            Localization.getString("PatternRemover") };

    final Class[] columnTypes = { Boolean.class, String.class };

    DefaultTableModel model = new DefaultTableModel(null, columnNames) {
        @Override//from  w  ww .j  a  v  a 2 s . c o  m
        public Class<?> getColumnClass(int idx) {
            return columnTypes[idx];
        }
    };

    table.setModel(model);
    table.getTableHeader().setReorderingAllowed(false);
    table.getModel().addTableModelListener((TableModelEvent e) -> change());

    return table;
}