Example usage for javax.swing.table TableColumnModel getColumn

List of usage examples for javax.swing.table TableColumnModel getColumn

Introduction

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

Prototype

public TableColumn getColumn(int columnIndex);

Source Link

Document

Returns the TableColumn object for the column at columnIndex.

Usage

From source file:plugins.ImageRectificationPanel.java

public final void createGui() {
    this.removeAll();

    if (imageGCPsXCoords == null) {
        return;//w  ww  .ja  va 2 s .c om
    }
    int i;
    int newN = 0;
    for (i = 0; i < imageGCPsXCoords.length; i++) {
        if (useGCP[i]) {
            newN++;
        }
    }
    double[] X1 = new double[newN];
    double[] Y1 = new double[newN];
    double[] X2 = new double[newN];
    double[] Y2 = new double[newN];

    int j = 0;
    for (i = 0; i < imageGCPsXCoords.length; i++) {
        if (useGCP[i]) {
            X1[j] = imageGCPsXCoords[i];
            Y1[j] = imageGCPsYCoords[i];
            X2[j] = mapGCPsXCoords[i];
            Y2[j] = mapGCPsYCoords[i];
            j++;
        }
    }

    calculateEquations(X1, Y1, X2, Y2);

    // gui stuff
    this.setLayout(new BorderLayout());

    DecimalFormat df = new DecimalFormat("###,###,##0.000");

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
    JButton btnOK = createButton(bundle.getString("OK"), bundle.getString("OK"), "ok");
    JButton btnExit = createButton(bundle.getString("Close"), bundle.getString("Close"), "close");
    //JButton btnRefresh = createButton("Cancel", "Cancel");

    buttonPane.add(Box.createHorizontalStrut(10));
    buttonPane.add(btnOK);
    buttonPane.add(Box.createHorizontalStrut(5));
    //buttonPane.add(btnRefresh);
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(btnExit);
    buttonPane.add(Box.createHorizontalGlue());

    progressBar = new JProgressBar(0, 100);
    buttonPane.add(progressBar);
    buttonPane.add(Box.createHorizontalStrut(5));
    cancel = new JLabel(bundle.getString("Cancel"));
    cancel.setForeground(Color.BLUE.darker());
    cancel.addMouseListener(this);
    buttonPane.add(cancel);
    buttonPane.add(Box.createHorizontalStrut(10));

    this.add(buttonPane, BorderLayout.SOUTH);

    Box mainBox = Box.createVerticalBox();
    mainBox.add(Box.createVerticalStrut(10));

    Box box1 = Box.createHorizontalBox();
    box1.add(Box.createHorizontalStrut(10));
    box1.add(new JLabel(bundle.getString("PolynomialOrder") + ": "));
    SpinnerModel model = new SpinnerNumberModel(polyOrder, //initial value
            1, //min
            5, //max
            1); //step

    polyOrderSpinner = new JSpinner(model);
    polyOrderSpinner.setPreferredSize(new Dimension(15, polyOrderSpinner.getPreferredSize().height));
    polyOrderSpinner.addChangeListener(this);

    JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) polyOrderSpinner.getEditor();
    editor.getTextField().setEnabled(true);
    editor.getTextField().setEditable(false);

    box1.add(polyOrderSpinner);
    box1.add(Box.createHorizontalGlue());
    JLabel label = new JLabel("RMSE: " + df.format(overallRMSE));
    box1.add(label);
    box1.add(Box.createHorizontalStrut(10));
    mainBox.add(box1);

    mainBox.add(Box.createVerticalStrut(10));

    // Create columns names
    int numPoints = imageGCPsXCoords.length;
    Object dataValues[][] = new Object[numPoints][7];
    j = 0;
    for (i = 0; i < numPoints; i++) {
        dataValues[i][0] = i + 1;
        dataValues[i][1] = df.format(imageGCPsXCoords[i]);
        dataValues[i][2] = df.format(imageGCPsYCoords[i]);
        dataValues[i][3] = df.format(mapGCPsXCoords[i]);
        dataValues[i][4] = df.format(mapGCPsYCoords[i]);
        if (useGCP[i]) {
            dataValues[i][5] = df.format(residualsXY[j]);
            j++;
        } else {
            dataValues[i][5] = null;
        }
        dataValues[i][6] = useGCP[i];
    }

    String columnNames[] = { "GCP", bundle.getString("Image") + " X", bundle.getString("Image") + " Y",
            bundle.getString("Map") + " X", bundle.getString("Map") + " Y", messages.getString("Error"),
            "Use" };

    DefaultTableModel tableModel = new DefaultTableModel(dataValues, columnNames);

    dataTable = new JTable(tableModel) {
        private static final long serialVersionUID = 1L;

        @Override
        public Class getColumnClass(int column) {
            switch (column) {
            case 0:
                return Integer.class;
            case 1:
                return String.class; //Double.class;
            case 2:
                return String.class; //Double.class;
            case 3:
                return String.class; //Double.class;
            case 4:
                return String.class; //Double.class;
            case 5:
                return String.class; //Double.class;
            case 6:
                return Boolean.class;
            default:
                return String.class; //Double.class;
            }
        }

        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int index_row, int index_col) {
            Component comp = super.prepareRenderer(renderer, index_row, index_col);
            //even index, selected or not selected

            if (index_row % 2 == 0) {
                comp.setBackground(Color.WHITE);
                comp.setForeground(Color.BLACK);
            } else {
                comp.setBackground(new Color(225, 245, 255)); //new Color(210, 230, 255));
                comp.setForeground(Color.BLACK);
            }
            if (isCellSelected(index_row, index_col)) {
                comp.setForeground(Color.RED);
            }
            return comp;
        }
    };

    tableModel.addTableModelListener(this);

    TableCellRenderer rend = dataTable.getTableHeader().getDefaultRenderer();
    TableColumnModel tcm = dataTable.getColumnModel();
    //for (int j = 0; j < tcm.getColumnCount(); j += 1) {
    TableColumn tc = tcm.getColumn(0);
    TableCellRenderer rendCol = tc.getHeaderRenderer(); // likely null  
    if (rendCol == null) {
        rendCol = rend;
    }
    Component c = rendCol.getTableCellRendererComponent(dataTable, tc.getHeaderValue(), false, false, 0, 0);
    tc.setPreferredWidth(35);

    tc = tcm.getColumn(6);
    rendCol = tc.getHeaderRenderer(); // likely null  
    if (rendCol == null) {
        rendCol = rend;
    }
    c = rendCol.getTableCellRendererComponent(dataTable, tc.getHeaderValue(), false, false, 0, 6);
    tc.setPreferredWidth(35);

    JScrollPane scroll = new JScrollPane(dataTable);
    mainBox.add(scroll);

    this.add(mainBox, BorderLayout.CENTER);

    this.validate();
}

From source file:qic.ui.QicFrame.java

private void setColumnWidths(TableColumnModel columnModel, List<Integer> widths) {
    for (int i = 0; i < widths.size(); i++) {
        columnModel.getColumn(i).setMinWidth(widths.get(i));
    }//from   w  ww . ja  v a2s  .c  o m
}

From source file:savant.agp.HTTPBrowser.java

private void updateDirectory() {
    try {//  w w w . j a  v  a 2  s  .  com
        List<String> files = listFiles();
        addressLabel.setText("Current directory: http://" + host + curDir.getPath().replace("\\", "/"));
        table.setModel(new HTTPTableModel(files, !curDir.equals(rootDir)));
        TableColumnModel columns = table.getColumnModel();
        columns.getColumn(0).setMaxWidth(40); // icon
        columns.getColumn(1).setPreferredWidth(400); // name
        //columns.getColumn(2).setPreferredWidth(60);     // size
    } catch (IOException ex) {
        Logger.getLogger(HTTPBrowser.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:savant.thousandgenomes.FTPBrowser.java

private void updateDirectory() throws IOException {
    FTPFile[] files = getFTPClient().listFiles(curDir.getPath().replace("\\", "/"));
    addressField.setText("ftp://" + host + curDir.getPath().replace("\\", "/"));
    table.setModel(new FTPTableModel(files, !curDir.equals(rootDir)));

    TableColumnModel columns = table.getColumnModel();
    columns.getColumn(0).setMaxWidth(40); // icon
    columns.getColumn(1).setPreferredWidth(400); // name
    columns.getColumn(2).setPreferredWidth(60); // size

    //Renderers are being set to null (somehow) on Linux only. Replacing them here.
    columns.getColumn(0).setCellRenderer(iconCellRenderer);
    columns.getColumn(1).setCellRenderer(defaultCellRenderer);
    columns.getColumn(2).setCellRenderer(defaultCellRenderer);
}

From source file:se.trixon.toolbox.geotagger.GeotaggerTopComponent.java

private void init() {
    openButton.setIcon(Pict.Actions.DOCUMENT_OPEN.get(TOOLBAR_ICON_SIZE));
    editToggleButton.setIcon(Pict.Actions.DOCUMENT_EDIT.get(TOOLBAR_ICON_SIZE));

    closeButton.setIcon(Pict.Actions.WINDOW_CLOSE.get(TOOLBAR_ICON_SIZE));
    closeButton.setEnabled(false);/*from w ww . j  a  va  2  s.co m*/

    startButton.setIcon(Pict.Actions.ARROW_RIGHT.get(ICON_SIZE));
    startButton.setToolTipText(Dict.START.getString());
    startButton.setEnabled(false);

    saveLogButton.setIcon(Pict.Actions.DOCUMENT_SAVE.get(ICON_SIZE));
    saveLogButton.setEnabled(false);

    helpButton.setIcon(Pict.Actions.HELP_CONTENTS.get(ICON_SIZE));
    helpButton.setToolTipText(Dict.HELP.getString());

    DropTarget dropTarget = new DropTarget() {
        @Override
        public synchronized void drop(DropTargetDropEvent evt) {
            try {
                evt.acceptDrop(DnDConstants.ACTION_COPY);
                List<File> droppedFiles = (List<File>) evt.getTransferable()
                        .getTransferData(DataFlavor.javaFileListFlavor);
                if (droppedFiles.get(0).isFile()) {
                    openFile(droppedFiles.get(0));
                }
            } catch (UnsupportedFlavorException | IOException ex) {
            }
        }
    };

    scrollPane.setDropTarget(dropTarget);

    mTableModel = new GeotagTableModel();
    table.setModel(mTableModel);
    mTableRowSorter = new TableRowSorter<>(mTableModel);
    table.setRowSorter(mTableRowSorter);

    TableColumnModel columnModel = table.getColumnModel();

    NumericTableCellRenderer cooNumericTableCellRenderer = new NumericTableCellRenderer(Double.class, 6);
    NumericTableCellRenderer altNumericTableCellRenderer = new NumericTableCellRenderer(Double.class, 4);

    columnModel.getColumn(GeotagTableModel.COLUMN_LATITUDE).setCellRenderer(cooNumericTableCellRenderer);
    columnModel.getColumn(GeotagTableModel.COLUMN_LONGITUDE).setCellRenderer(cooNumericTableCellRenderer);
    columnModel.getColumn(GeotagTableModel.COLUMN_ALTITUDE).setCellRenderer(altNumericTableCellRenderer);

    columnModel.getColumn(GeotagTableModel.COLUMN_NAME).setPreferredWidth(200);
    columnModel.getColumn(GeotagTableModel.COLUMN_LATITUDE).setPreferredWidth(100);
    columnModel.getColumn(GeotagTableModel.COLUMN_LONGITUDE).setPreferredWidth(100);
    columnModel.getColumn(GeotagTableModel.COLUMN_ALTITUDE).setPreferredWidth(50);
}

From source file:vista.promocion.DiagPromocion.java

private void configurarTabla(JTable tbl) {
    JViewport scroll = (JViewport) tbl.getParent();
    int ancho = scroll.getWidth();
    int anchoColumna = 0;
    TableColumnModel modeloColumna = tbl.getColumnModel();
    TableColumn columnaTabla;/*from   w ww.  ja v a 2s .c  o  m*/
    for (int i = 0; i < tbl.getColumnCount(); i++) {
        columnaTabla = modeloColumna.getColumn(i);
        switch (i) {
        case 0:
            anchoColumna = (1 * ancho) / 100;
            break;
        case 1:
            anchoColumna = (20 * ancho) / 100;
            break;
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
        case 11:
        case 12:
            anchoColumna = (5 * ancho) / 100;
            break;
        }
        columnaTabla.setPreferredWidth(anchoColumna);
        tbl.setColumnModel(modeloColumna);
    }
    tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10));
    tbl.getTableHeader().setBackground(java.awt.Color.WHITE);
    tbl.getTableHeader().setForeground(Color.BLACK);
    //Si le queremos cambiar el tamao a la tablita
    tbl.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10));
}

From source file:vista.ventas.DiagOrdenesDeCompra.java

private void configurarTabla(JTable tbl) {
    JViewport scroll = (JViewport) tbl.getParent();
    int ancho = scroll.getWidth();
    int anchoColumna = 0;
    TableColumnModel modeloColumna = tbl.getColumnModel();
    TableColumn columnaTabla;//from  www . ja  v  a  2 s . co m
    for (int i = 0; i < tbl.getColumnCount(); i++) {
        columnaTabla = modeloColumna.getColumn(i);
        switch (i) {
        case 0:
            anchoColumna = (1 * ancho) / 100;
            break;
        case 1:
            anchoColumna = (20 * ancho) / 100;
            break;
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
        case 11:
        case 12:
            anchoColumna = (5 * ancho) / 100;
            break;
        }
        columnaTabla.setPreferredWidth(anchoColumna);
        tbl.setColumnModel(modeloColumna);
    }
    tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10));
    tbl.getTableHeader().setBackground(java.awt.Color.WHITE);
    tbl.getTableHeader().setForeground(Color.BLACK);
    tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 18));
    //Si le queremos cambiar el tamao a la tablita
    tbl.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 18));
}

From source file:vista.ventas.DialogEntregas.java

private void configurarTabla(JTable tbl) {
    JViewport scroll = (JViewport) tbl.getParent();
    int ancho = scroll.getWidth();
    int anchoColumna = 0;
    TableColumnModel modeloColumna = tbl.getColumnModel();
    TableColumn columnaTabla;//  w  w  w  .  ja  va  2  s .  co m
    for (int i = 0; i < tbl.getColumnCount(); i++) {
        columnaTabla = modeloColumna.getColumn(i);
        switch (i) {
        case 0:
            anchoColumna = 1 / 100;
            break;
        case 1:
            anchoColumna = (20 * ancho) / 100;
            break;
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
        case 11:
        case 12:
            anchoColumna = (5 * ancho) / 100;
            break;
        }
        columnaTabla.setPreferredWidth(anchoColumna);
        tbl.setColumnModel(modeloColumna);
    }
    tbl.getTableHeader().setBackground(java.awt.Color.WHITE);
    tbl.getTableHeader().setForeground(Color.BLACK);
    tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 14));
    //Si le queremos cambiar el tamao a la tablita
    tbl.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 14));
}