Example usage for javax.swing.table TableColumn setPreferredWidth

List of usage examples for javax.swing.table TableColumn setPreferredWidth

Introduction

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

Prototype

@BeanProperty(description = "The preferred width of the column.")
public void setPreferredWidth(int preferredWidth) 

Source Link

Document

Sets this column's preferred width to preferredWidth.

Usage

From source file:org.zaproxy.zap.extension.httppanel.view.paramtable.HttpPanelParamTableView.java

@Override
public void setEditable(boolean editable) {
    if (isEditable != editable) {
        if (isEditable) {
            table.getColumnModel().removeColumn(table.getColumnModel().getColumn(3));
        } else {/*from  w ww  .  ja va2  s  .  com*/
            TableColumn column = new TableColumn(3, 150, new ComboBoxCellRenderer(comboBoxAddIns),
                    new DefaultCellEditor(comboBoxAddIns));
            column.setPreferredWidth(150);
            column.setMaxWidth(150);
            table.addColumn(column);
        }

        isEditable = editable;

        httpPanelTabularModel.setEditable(editable);
    }
}

From source file:org.zaproxy.zap.extension.httppanelviews.paramtable.HttpPanelParamTableView.java

private void init() {
    // Table/*  w  w  w.  jav  a  2  s.c o m*/
    table = new JTable();
    table.setName("");
    table.setModel(httpPanelTabularModel);
    table.setGridColor(java.awt.Color.gray);
    table.setIntercellSpacing(new java.awt.Dimension(1, 1));
    table.setRowHeight(18);

    // Set standard row width's
    TableColumn column = table.getColumnModel().getColumn(0);
    column.setPreferredWidth(70);
    column.setWidth(70);
    column.setMaxWidth(70);
    if (table.getColumnCount() == 4) {
        column = table.getColumnModel().getColumn(3);
        column.setPreferredWidth(150);
        column.setWidth(150);
        column.setMaxWidth(150);
    }

    // Main panel
    mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(new JScrollPane(table), BorderLayout.CENTER);
}

From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzerContentPanel.java

public JXTreeTable getFuzzResultTable() {
    if (fuzzResultTable == null) {
        resetFuzzResultTable();//from  www  .  j a  v  a 2s .  c  om
        fuzzResultTable = new JXTreeTable(getResultsModel());
        fuzzResultTable.setName("HttpFuzzResultTable");
        fuzzResultTable.setDoubleBuffered(true);
        fuzzResultTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        fuzzResultTable.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12));
        fuzzResultTable.setDefaultRenderer(Pair.class, new IconTableCellRenderer());

        int[] widths = { 10, 25, 550, 30, 85, 55, 40, 70 };
        for (int i = 0, count = widths.length; i < count; i++) {
            TableColumn column = fuzzResultTable.getColumnModel().getColumn(i);
            column.setPreferredWidth(widths[i]);
        }
        fuzzResultTable.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) {
                if (e.isPopupTrigger() && SwingUtilities.isRightMouseButton(e)) {
                    // Select list item on right click
                    JTable table = (JTable) e.getSource();
                    int row = table.rowAtPoint(e.getPoint());

                    if (!table.isRowSelected(row)) {
                        table.changeSelection(row, 0, false, false);
                    }
                    View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
                }
            }

        });

        fuzzResultTable.getSelectionModel()
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {

                    @Override
                    public void valueChanged(javax.swing.event.ListSelectionEvent e) {
                        if (!e.getValueIsAdjusting()) {
                            if (fuzzResultTable.getSelectedRowCount() == 0) {
                                return;
                            }
                            final int row = fuzzResultTable.getSelectedRow();
                            if (getEntry(row) instanceof HttpFuzzRequestRecord) {
                                final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(
                                        row)).getHistory();
                                try {
                                    displayMessage(historyReference.getHttpMessage());
                                } catch (HttpMalformedHeaderException | SQLException ex) {
                                    logger.error(ex.getMessage(), ex);
                                }
                            }
                        }
                    }
                });
        fuzzResultTable.getTableHeader().addMouseListener(new MouseListener() {
            int sortedOn = -1;

            @Override
            public void mouseReleased(MouseEvent arg0) {
            }

            @Override
            public void mousePressed(MouseEvent arg0) {
            }

            @Override
            public void mouseExited(MouseEvent arg0) {
            }

            @Override
            public void mouseEntered(MouseEvent arg0) {
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                int index = fuzzResultTable.columnAtPoint(e.getPoint());
                List<HttpFuzzRecord> list = getResultsModel().getEntries();
                if (list.size() == 0) {
                    return;
                }
                HttpFuzzRecordComparator comp = new HttpFuzzRecordComparator();
                comp.setFeature(index);
                if (index == sortedOn) {
                    Collections.sort(list, comp);
                    Collections.reverse(list);
                    sortedOn = -1;
                } else {
                    Collections.sort(list, comp);
                    sortedOn = index;
                }
                fuzzResultTable.updateUI();
            }
        });
        fuzzResultTable.setRootVisible(false);
        fuzzResultTable.setVisible(true);
    }
    return fuzzResultTable;
}

From source file:plugins.ImageRectificationPanel.java

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

    if (imageGCPsXCoords == null) {
        return;/*from www . j a  v a  2  s . c  o m*/
    }
    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:put.semantic.fcanew.ui.MainWindow.java

private void continueStart() {
    final List<Attribute> forced = getAttributes(2);
    if (forced.isEmpty()) {
        forced.addAll(getAttributes(1));
    }/*ww  w  . j  av  a2 s .c om*/
    logger.trace("START");
    for (Attribute a : getUsedAttributes()) {
        logger.trace("ATTR: {}", a);
    }
    context = new PartialContext(new SimpleSetOfAttributes(getUsedAttributes()), kb);
    context.addProgressListener(progressListener);
    context.updateContext();
    contextTable.setRowSorter(new TableRowSorter<>());
    contextTable.setModel(new ContextDataModel(context));
    contextTable.setDefaultRenderer(Object.class, new PODCellRenderer(kb.getReasoner()));
    Enumeration<TableColumn> e = contextTable.getColumnModel().getColumns();
    JComboBox comboBox = new JComboBox(new Object[] { "+", "-", " " });
    while (e.hasMoreElements()) {
        TableColumn col = e.nextElement();
        col.setHeaderRenderer(new VerticalTableHeaderCellRenderer());
        col.setCellEditor(new DefaultCellEditor(comboBox));
        if (col.getModelIndex() >= 1) {
            col.setPreferredWidth(20);
        }
    }
    List<? extends FeatureCalculator> calculators = availableCalculatorsModel.getChecked();
    for (FeatureCalculator calc : calculators) {
        if (calc instanceof EndpointCalculator) {
            ((EndpointCalculator) calc).setMappings(mappingsPanel1.getMappings());
        }
    }
    Classifier classifier = (Classifier) classifierToUse.getSelectedItem();
    classifier.setRejectedWeight((Double) rejectedWeight.getValue());
    mlExpert = new MLExpert(classifier, (Integer) credibilityTreshold.getValue(), calculators,
            getIgnoreTreshold(), context, getAutoAcceptTreshold());
    mlExpert.addEventListener(new MLExpertEventListener() {

        @Override
        public void implicationAccepted(ImplicationDescription i, boolean autoDecision) {
            logger.trace("ACCEPT");
            setButtonsEnabled(false);
            ((ConfusionMatrix) confusionMatrix.getModel()).add(i.getSuggestion(), Expert.Decision.ACCEPT);
            registerImplication(i.getImplication(), i.getClassificationOutcome(), Expert.Decision.ACCEPT);
        }

        @Override
        public void implicationRejected(ImplicationDescription i, boolean autoDecision) {
            logger.trace("REJECT");
            setButtonsEnabled(false);
            ((ConfusionMatrix) confusionMatrix.getModel()).add(i.getSuggestion(), Expert.Decision.REJECT);
            registerImplication(i.getImplication(), i.getClassificationOutcome(), Expert.Decision.REJECT);
        }

        private TableModel getFeaturesTableModel(Map<String, Double> features) {
            DefaultTableModel model = new DefaultTableModel(new String[] { "feature", "value" }, 0);
            for (Map.Entry<String, Double> f : features.entrySet()) {
                model.addRow(new Object[] { f.getKey(), f.getValue() });
            }
            return model;
        }

        @Override
        public void ask(ImplicationDescription i, String justification) {
            logger.trace("ASK: {}", i.getImplication());
            highlightButton(i.getSuggestion());
            ((ContextDataModel) contextTable.getModel()).setCurrentImplication(i.getImplication());
            justificationText.setText(justification);
            implicationText.setText(String.format("<html>%s</html>", i.getImplication().toString()));
            {
                Map<String, String> desc = i.getImplication().describe(kb);
                String s = "<html><table border=\"1\">";
                s += "<tr><th>Attribute</th><th>Label</th></tr>";
                for (Map.Entry<String, String> e : desc.entrySet()) {
                    s += String.format("<tr><td>%s</td><td><pre>%s</pre></td></tr>", e.getKey(), e.getValue());
                }
                s += "</table></html>";
                implicationText.setToolTipText(s);
            }
            setButtonsEnabled(true);
            featuresTable.setModel(getFeaturesTableModel(i.getFeatures()));
        }
    });
    learningExamplesTable.setModel(classifier.getExamplesTableModel());
    fca = new FCA();
    fca.setContext(context);
    fca.setExpert(mlExpert);
    new SwingWorker() {
        @Override
        protected Object doInBackground() throws Exception {
            fca.reset(forced);
            fca.run();
            return null;
        }

        @Override
        protected void done() {
            try {
                get();
                logger.trace("FINISHED");
                if (script != null) {
                    String name = JOptionPane.showInputDialog(MainWindow.this,
                            "Jeeli chcesz otrzyma punkty z TSiSS, podaj swoje imi, nazwisko i nr indeksu",
                            "TSiSS", JOptionPane.QUESTION_MESSAGE);
                    if (name != null) {
                        logger.trace("NAME: {}", name);
                    }
                    script.submitLog(new File("fca.log"));
                }
                implicationText.setText("Bye-bye");
            } catch (InterruptedException | ExecutionException ex) {
                implicationText.setText(ex.getLocalizedMessage());
                ex.printStackTrace();
            }
        }
    }.execute();
}

From source file:uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetDisplay.java

public GeneSetDisplay(DataCollection dataCollection, String description, DataStore fromStore, DataStore toStore,
        Probe[] probes, Hashtable zScoreLookupTable, MappedGeneSetTTestValue[] filterResults,
        ProbeList startingProbeList, float[][] customRegressionValues, SimpleRegression simpleRegression) {

    super(SeqMonkApplication.getInstance(), "Gene Set Results");
    this.collection = dataCollection;
    this.filterResultsPVals = filterResults;
    this.startingProbeList = startingProbeList;
    this.description = description;
    this.fromStore = fromStore;
    this.toStore = toStore;
    this.probes = probes;
    this.zScoreLookupTable = zScoreLookupTable;
    this.customRegressionValues = customRegressionValues;
    this.simpleRegression = simpleRegression;
    this.addWindowListener(this);

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    // This is to hold the scatterPanel and its associated bits.
    plotPanel = new JPanel();
    plotPanel.setLayout(new BorderLayout());

    scatterPlotPanel = new JPanel();
    plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);

    dotSizeSlider = new JSlider(JSlider.VERTICAL, 1, 100, 3);

    // This call is left in to work around a bug in the Windows 7 LAF
    // which makes the slider stupidly thin in ticks are not drawn.
    dotSizeSlider.setPaintTicks(true);//from  w w  w.  j ava 2  s .  c  om
    dotSizeSlider.addChangeListener(this);
    plotPanel.add(dotSizeSlider, BorderLayout.EAST);

    JPanel plotButtonPanel = new JPanel();
    plotButtonPanel.setLayout(new GridBagLayout());
    GridBagConstraints c1 = new GridBagConstraints();
    c1.insets = new Insets(2, 2, 2, 2);
    c1.gridx = 0;
    c1.gridy = 0;

    saveImageButton = new JButton("Save Image");
    saveImageButton.addActionListener(this);
    saveImageButton.setActionCommand("save_image");

    plotButtonPanel.add(saveImageButton, c1);

    c1.gridx++;
    swapPlotButton = new JToggleButton("Display standard scatterplot");
    swapPlotButton.addActionListener(this);
    swapPlotButton.setActionCommand("swap_plot");

    plotButtonPanel.add(swapPlotButton, c1);

    plotPanel.add(plotButtonPanel, BorderLayout.SOUTH);

    /** The table where the probe lists are displayed */
    tableModel = new GeneSetTableModel(filterResultsPVals);
    table = new JTable(new TableSorter(tableModel));
    table.setRowSelectionAllowed(true);
    table.addMouseListener(this);
    table.setAutoCreateRowSorter(true);
    table.getSelectionModel().addListSelectionListener(this);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // sort by z-score
    table.getRowSorter().toggleSortOrder(3);

    // Set our initial column widths
    TableColumn column = null;
    for (int i = 0; i < tableModel.getColumnCount(); i++) {
        column = table.getColumnModel().getColumn(i);
        if (i == 0) {
            column.setPreferredWidth(40);
        } else if (i == 1) {
            column.setPreferredWidth(200);
        } else {
            column.setPreferredWidth(80);
        }
    }

    JScrollPane scrollPane = new JScrollPane(table);
    JPanel tablePanel = new JPanel();

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    GridBagConstraints c2 = new GridBagConstraints();
    c2.insets = new Insets(2, 2, 2, 2);
    c2.gridx = 0;
    c2.gridy = 0;

    selectAllButton = new JToggleButton("Select all");
    selectAllButton.addActionListener(this);
    selectAllButton.setActionCommand("select_all");

    buttonPanel.add(selectAllButton, c2);

    saveSelectedProbeListsButton = new JButton("Save selected probe lists");
    saveSelectedProbeListsButton.addActionListener(this);
    saveSelectedProbeListsButton.setActionCommand("save_selected_probelists");
    c2.gridx++;
    c2.gridx++;
    buttonPanel.add(saveSelectedProbeListsButton, c2);

    saveTableButton = new JButton("Save table");
    saveTableButton.addActionListener(this);
    saveTableButton.setActionCommand("save_table");
    c2.gridx++;
    c2.gridx++;
    buttonPanel.add(saveTableButton, c2);

    closeButton = new JButton("Close");
    closeButton.addActionListener(this);
    closeButton.setActionCommand("close");
    c2.gridx++;
    buttonPanel.add(closeButton, c2);

    tablePanel.setLayout(new BorderLayout());
    tablePanel.add(scrollPane, BorderLayout.CENTER);
    tablePanel.add(buttonPanel, BorderLayout.SOUTH);

    // sort this out 
    mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    mainPane.setLeftComponent(plotPanel);
    mainPane.setRightComponent(tablePanel);

    mainPane.setResizeWeight(0.6);
    mainPane.setDividerLocation(500);

    getContentPane().add(BorderLayout.CENTER, mainPane);

    if (storesQuantitated()) {

        plotPanel.remove(scatterPlotPanel);
        scatterPlotPanel = new ZScoreScatterPlotPanel(fromStore, toStore, probes, currentSelectedProbeList,
                dotSizeSlider.getValue(), zScoreLookupTable);
        plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);
    }

    setSize(1000, 500);
    setVisible(true);

}

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;
    for (int i = 0; i < tbl.getColumnCount(); i++) {
        columnaTabla = modeloColumna.getColumn(i);
        switch (i) {
        case 0:/* w  w w .j  av a2s  .  c  o  m*/
            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;
    for (int i = 0; i < tbl.getColumnCount(); i++) {
        columnaTabla = modeloColumna.getColumn(i);
        switch (i) {
        case 0://from w w  w . j av a2  s .  c om
            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;
    for (int i = 0; i < tbl.getColumnCount(); i++) {
        columnaTabla = modeloColumna.getColumn(i);
        switch (i) {
        case 0://from w w w  .  ja  va 2  s. c  om
            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));
}