Example usage for javax.swing JTable setFont

List of usage examples for javax.swing JTable setFont

Introduction

In this page you can find the example usage for javax.swing JTable setFont.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The font for the component.")
public void setFont(Font font) 

Source Link

Document

Sets the font for this component.

Usage

From source file:com.stam.batchmove.BatchMoveUtils.java

public static void showFilesFrame(Object[][] data, String[] columnNames, final JFrame callerFrame) {
    final FilesFrame filesFrame = new FilesFrame();

    DefaultTableModel model = new DefaultTableModel(data, columnNames) {

        private static final long serialVersionUID = 1L;

        @Override/*from  ww  w  .  j a  v a2  s  . co m*/
        public Class<?> getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            return column == 0;
        }
    };
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setHorizontalAlignment(JLabel.CENTER);
    final JTable table = new JTable(model);
    for (int i = 1; i < table.getColumnCount(); i++) {
        table.setDefaultRenderer(table.getColumnClass(i), renderer);
    }
    //            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setRowHeight(30);
    table.getTableHeader().setFont(new Font("Serif", Font.BOLD, 14));
    table.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
    table.setRowSelectionAllowed(false);
    table.getColumnModel().getColumn(0).setMaxWidth(35);
    table.getColumnModel().getColumn(1).setPreferredWidth(350);
    table.getColumnModel().getColumn(2).setPreferredWidth(90);
    table.getColumnModel().getColumn(2).setMaxWidth(140);
    table.getColumnModel().getColumn(3).setMaxWidth(90);

    JPanel tblPanel = new JPanel();
    JPanel btnPanel = new JPanel();

    tblPanel.setLayout(new BorderLayout());
    if (table.getRowCount() > 15) {
        JScrollPane scrollPane = new JScrollPane(table);
        tblPanel.add(scrollPane, BorderLayout.CENTER);
    } else {
        tblPanel.add(table.getTableHeader(), BorderLayout.NORTH);
        tblPanel.add(table, BorderLayout.CENTER);
    }

    btnPanel.setLayout(new FlowLayout(FlowLayout.LEFT));

    filesFrame.setMinimumSize(new Dimension(800, 600));
    filesFrame.setLayout(new BorderLayout());
    filesFrame.add(tblPanel, BorderLayout.NORTH);
    filesFrame.add(btnPanel, BorderLayout.SOUTH);

    final JLabel resultsLabel = new JLabel();

    JButton cancelBtn = new JButton("Cancel");
    cancelBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            filesFrame.setVisible(false);
            callerFrame.setVisible(true);
        }
    });

    JButton moveBtn = new JButton("Copy");
    moveBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fileChooser.setDialogTitle("Choose target directory");
            int selVal = fileChooser.showOpenDialog(null);
            if (selVal == JFileChooser.APPROVE_OPTION) {
                File selection = fileChooser.getSelectedFile();
                String targetPath = selection.getAbsolutePath();

                DefaultTableModel dtm = (DefaultTableModel) table.getModel();
                int nRow = dtm.getRowCount();
                int copied = 0;
                for (int i = 0; i < nRow; i++) {
                    Boolean selected = (Boolean) dtm.getValueAt(i, 0);
                    String filePath = dtm.getValueAt(i, 1).toString();

                    if (selected) {
                        try {
                            FileUtils.copyFileToDirectory(new File(filePath), new File(targetPath));
                            dtm.setValueAt("Copied", i, 3);
                            copied++;
                        } catch (Exception ex) {
                            Logger.getLogger(SelectionFrame.class.getName()).log(Level.SEVERE, null, ex);
                            dtm.setValueAt("Failed", i, 3);
                        }
                    }
                }
                resultsLabel.setText(copied + " files copied. Finished!");
            }
        }
    });
    btnPanel.add(cancelBtn);
    btnPanel.add(moveBtn);
    btnPanel.add(resultsLabel);

    filesFrame.revalidate();
    filesFrame.setVisible(true);

    callerFrame.setVisible(false);
}

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

@Override
public JXTreeTable getTable() {
    if (table == null) {
        if (model == null) {
            model = new HttpFuzzTableModel();
        }//  www .  jav  a 2  s.  c  o m
        table = new JXTreeTable(model);
        table.setDoubleBuffered(true);
        table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        table.setName("HttpFuzzResultTable");
        table.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12));
        table.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 = table.getColumnModel().getColumn(i);
            column.setPreferredWidth(widths[i]);
        }
        table.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()) {
                    if (e.isPopupTrigger()) {
                        // 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());
                    }
                }
            }

        });
        table.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() {

            @Override
            public void valueChanged(javax.swing.event.ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    if (table.getSelectedRowCount() == 0) {
                        return;
                    }
                    final int row = table.getSelectedRow();
                    if (getEntry(row) instanceof HttpFuzzRequestRecord) {
                        final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(row))
                                .getHistory();
                        try {
                            getMessageInspection().setMessage(historyReference.getHttpMessage());
                        } catch (HttpMalformedHeaderException | SQLException ex) {
                            logger.error(ex.getMessage(), ex);
                        }
                    }
                    updateValues();
                    redrawDiagrams();
                }
            }
        });
    }
    table.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 = table.columnAtPoint(e.getPoint());
            List<HttpFuzzRecord> list = model.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;
            }
            table.updateUI();
        }
    });
    table.setRootVisible(false);
    table.setVisible(true);
    return table;
}

From source file:org.biojava.bio.view.MotifAnalyzer.java

private JPanel getStatisticsTab(int excelNum) throws IOException {
    JPanel panel = new JPanel();
    GroupLayout panelLayout = new GroupLayout((JComponent) panel);
    panel.setLayout(panelLayout);/*  ww  w .  j  a v a  2s .c  o m*/
    panel.setPreferredSize(new java.awt.Dimension(676, 557));

    Object[][] tableData = FileConverterTools.readExcel(FileNames.getStatisticsExcelFileName(excelNum));
    Object columnName[] = new Object[tableData[0].length];
    for (int i = 0; i < columnName.length; i++)
        columnName[i] = i;
    tableData = null; //free memory

    final JTable table = new JTable();
    JScrollPane jScrollPane = new JScrollPane(table);
    table.setFont(new Font(Font.DIALOG, Font.BOLD, 15));
    table.setEnabled(false);
    File file = new File(FileNames.getStatisticsExcelFileName(excelNum));
    JTableReadTableModelTask task = new JTableReadTableModelTask(file, null, null, table);
    task.execute();

    JButton button = new JButton("Save to Excel");
    panelLayout.setVerticalGroup(panelLayout.createSequentialGroup()
            .addComponent(jScrollPane, GroupLayout.PREFERRED_SIZE, 485, GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(button,
                    GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
            .addContainerGap(40, 40));
    panelLayout.setHorizontalGroup(panelLayout.createParallelGroup()
            .addComponent(jScrollPane, GroupLayout.Alignment.LEADING, 0, 676, Short.MAX_VALUE)
            .addGroup(GroupLayout.Alignment.LEADING,
                    panelLayout.createSequentialGroup().addGap(0, 493, Short.MAX_VALUE)
                            .addComponent(button, GroupLayout.PREFERRED_SIZE, 143, GroupLayout.PREFERRED_SIZE)
                            .addContainerGap(40, 40)));
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            JFileChooser fc = new JFileChooser();
            int returnVal = fc.showOpenDialog(MotifAnalyzer.this.mainFrame);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                try {
                    //File file = new File(fc.getSelectedFile().getCanonicalPath());
                    //JTableWriteTableModelTask task = new JTableWriteTableModelTask(file, null, null, table);
                    //task.execute();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    return panel;
}

From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java

public JPanel createDetailsView() {
    final VFSJFileChooser chooser = getFileChooser();

    JPanel p = new JPanel(new BorderLayout());

    final JTable detailsTable = new JTable(getDetailsTableModel()) {
        // Handle Escape key events here
        @Override/*from   w w w  .  ja  v  a 2s .co  m*/
        protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
            if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) && (getCellEditor() == null)) {
                // We are not editing, forward to filechooser.
                chooser.dispatchEvent(e);

                return true;
            }

            return super.processKeyBinding(ks, e, condition, pressed);
        }

        @Override
        public void tableChanged(TableModelEvent e) {
            super.tableChanged(e);

            if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
                // update header with possibly changed column set
                updateDetailsColumnModel(this);
            }
        }
    };

    //        detailsTable.setRowSorter(getRowSorter());
    detailsTable.setAutoCreateColumnsFromModel(false);
    detailsTable.setComponentOrientation(chooser.getComponentOrientation());
    //detailsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    detailsTable.setShowGrid(false);
    detailsTable.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);

    //        detailsTable.addKeyListener(detailsKeyListener);
    Font font = list.getFont();
    detailsTable.setFont(font);
    detailsTable.setIntercellSpacing(new Dimension(0, 0));

    TableCellRenderer headerRenderer = new AlignableTableHeaderRenderer(
            detailsTable.getTableHeader().getDefaultRenderer());
    detailsTable.getTableHeader().setDefaultRenderer(headerRenderer);

    TableCellRenderer cellRenderer = new DetailsTableCellRenderer(chooser);
    detailsTable.setDefaultRenderer(Object.class, cellRenderer);

    // So that drag can be started on a mouse press
    detailsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    detailsTable.addMouseListener(getMouseHandler());
    // No need to addListSelectionListener because selections are forwarded
    // to our JList.

    // 4835633 : tell BasicTableUI that this is a file list
    detailsTable.putClientProperty("Table.isFileList", Boolean.TRUE);

    if (listViewWindowsStyle) {
        detailsTable.addFocusListener(repaintListener);
    }

    JTableHeader header = detailsTable.getTableHeader();
    header.setUpdateTableInRealTime(true);
    header.addMouseListener(detailsTableModel.new ColumnListener());
    header.setReorderingAllowed(true);

    // TAB/SHIFT-TAB should transfer focus and ENTER should select an item.
    // We don't want them to navigate within the table
    ActionMap am = SwingUtilities.getUIActionMap(detailsTable);
    am.remove("selectNextRowCell");
    am.remove("selectPreviousRowCell");
    am.remove("selectNextColumnCell");
    am.remove("selectPreviousColumnCell");
    detailsTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    detailsTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);

    JScrollPane scrollpane = new JScrollPane(detailsTable);
    scrollpane.setComponentOrientation(chooser.getComponentOrientation());
    LookAndFeel.installColors(scrollpane.getViewport(), "Table.background", "Table.foreground");

    // Adjust width of first column so the table fills the viewport when
    // first displayed (temporary listener).
    scrollpane.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            JScrollPane sp = (JScrollPane) e.getComponent();
            fixNameColumnWidth(sp.getViewport().getSize().width);
            sp.removeComponentListener(this);
        }
    });

    // 4835633.
    // If the mouse is pressed in the area below the Details view table, the
    // event is not dispatched to the Table MouseListener but to the
    // scrollpane.  Listen for that here so we can clear the selection.
    scrollpane.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            JScrollPane jsp = ((JScrollPane) e.getComponent());
            JTable table = (JTable) jsp.getViewport().getView();

            if (!e.isShiftDown()
                    || (table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)) {
                clearSelection();

                TableCellEditor tce = table.getCellEditor();

                if (tce != null) {
                    tce.stopCellEditing();
                }
            }
        }
    });

    detailsTable.setForeground(list.getForeground());
    detailsTable.setBackground(list.getBackground());

    if (listViewBorder != null) {
        scrollpane.setBorder(listViewBorder);
    }

    p.add(scrollpane, BorderLayout.CENTER);

    detailsTableModel.fireTableStructureChanged();

    return p;
}

From source file:semaforo.Semaforo.java

public synchronized void loadTableWeek(JTable TableWeek, int index) {
    Settings settings = Controller.getSettings();

    //TableWeek.getColumnModel().getColumn(0).setPreferredWidth(350); //150
    TableWeek.setRowHeight(20); //40
    //TableWeek.getColumnModel().getColumn(9).setPreferredWidth(350);//150
    TableWeek.setFont(new Font("Arial", Font.BOLD, 12));//18

    CustomRenderer cr = new CustomRenderer(TableWeek.getDefaultRenderer(Object.class), Color.LIGHT_GRAY,
            Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY);
    TableWeek.setDefaultRenderer(Object.class, cr);
    DefaultTableModel model = (DefaultTableModel) TableWeek.getModel();
    Object[] o = new Object[10];

    JTableHeader header = TableWeek.getTableHeader();
    header.setPreferredSize(new Dimension(10, 30)); //100
    TableWeek.getTableHeader().setFont(new Font("Arial", Font.BOLD, 15));

    /* DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
     centerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
     TableWeek.getColumnModel().getColumn(0).setCellRenderer(centerRenderer);
     TableWeek.getColumnModel().getColumn(9).setCellRenderer(centerRenderer);
     TableWeek.setDefaultRenderer(String.class, centerRenderer);*/
    int num = settings.getTickers().size();

    /*   while(DDBB.loadData) {
     try {//from  w  w w  .j  a va 2s . com
     Thread.sleep(500);
     } catch (InterruptedException ex) {
     Logger.getLogger(Semaforo.class.getName()).log(Level.SEVERE, null, ex);
     }
     }*/
    if (TableWeek.getModel().getRowCount() > 0) {
        num = Math.min(settings.getTickers().size(), TableWeek.getModel().getRowCount());
    }

    for (int i = 0; i < num; i++) {
        o[0] = settings.getTickers().get(i).getMinValue(index);
        o[9] = settings.getTickers().get(i).getMaxValue(index);
        model.addRow(o);
    }
}

From source file:org.hibernate.search.demo.SearchDemo.java

private void initWidgets() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setDefaultLookAndFeelDecorated(true);

    BorderLayout borderLayout = new BorderLayout();
    getContentPane().setLayout(borderLayout);

    // the main table
    model = new DefaultTableModel(headers, 0) {
        public boolean isCellEditable(int row, int column) {
            // at the moment only allows the editing of the title
            return column == 2;
        }/*from w ww.j  a va2s. c o  m*/
    };
    modelListener = new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            int row = e.getFirstRow();
            int column = e.getColumn();
            TableModel model = (TableModel) e.getSource();
            Object data = model.getValueAt(row, column);
            EntityManager em = emf.createEntityManager();
            updateTitle((Long) model.getValueAt(row, 0), (String) data);
            log.info("new value: {}", data);
        }
    };
    model.addTableModelListener(modelListener);
    final JTable table = new JTable(model);

    table.setFont(new Font("Courier New", Font.PLAIN, 14));
    getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);

    // build  the controls
    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new FlowLayout());

    final JTextField searchField = new JTextField(30);
    controlPanel.add(searchField);

    JButton searchButton = new JButton("Search");
    searchButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            List<Product> products;

            try {
                products = search(searchField.getText());
            } catch (ParseException pe) {
                JOptionPane.showMessageDialog(null, pe.getMessage(), "alert", JOptionPane.ERROR_MESSAGE);
                return;
            }

            DefaultTableModel model = (DefaultTableModel) table.getModel();
            model.removeTableModelListener(modelListener);
            model.setRowCount(0);
            for (int i = 0; i < products.size(); i++) {
                Object[] data = new Object[headers.length];
                Product p = products.get(i);
                data[0] = p.getProductId();
                data[1] = p.getASIN();
                data[2] = p.getTitle();
                //data[3] = p.getDescription();
                String actors = "";
                for (Actor actor : p.getActors()) {
                    actors = actors + actor.getName() + ", ";
                }
                data[3] = actors.length() == 0 ? actors : actors.substring(0, actors.length() - 2);
                String categories = "";
                for (Category category : p.getCategories()) {
                    categories = categories + category.getName() + ", ";
                }
                data[4] = categories.length() == 0 ? categories
                        : categories.substring(0, categories.length() - 2);
                model.insertRow(i, data);
            }
            model.addTableModelListener(modelListener);
        }
    });
    controlPanel.add(searchButton);

    JButton indexButton = new JButton("Index");
    indexButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            index();
        }
    });
    controlPanel.add(indexButton);

    JButton purgeButton = new JButton("Purge");
    purgeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            purge();
        }
    });
    controlPanel.add(purgeButton);

    getContentPane().add(controlPanel, BorderLayout.NORTH);
    getRootPane().setDefaultButton(searchButton);

    setSize(800, 200);
    setVisible(true);
}

From source file:org.isatools.isacreator.gui.formelements.SubForm.java

protected void setTableProperties(JTable table, boolean isFieldName) {
    Font font = (!isFieldName) ? UIHelper.VER_12_PLAIN : UIHelper.VER_12_BOLD;
    table.setFont(font);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setColumnSelectionAllowed(true);
    table.setRowSelectionAllowed(true);/*from  w w w  .  jav  a2  s. co  m*/
    table.setGridColor(UIHelper.LIGHT_GREEN_COLOR);
    table.setShowGrid(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;//from w w  w  .ja v a2s  .  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   w ww . java 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;/*from   w  ww  . 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));
}