FileDocCategorySizeDatePackage
TestColumnResizer.javaAPI DocExample1756Mon Jan 09 11:01:58 GMT 2006None

TestColumnResizer

public class TestColumnResizer extends Object

Fields Summary
static final Object[]
TABLE_DATA
static final String[]
COLUMN_NAMES
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


          
        // 142 mac l&f has a header bug - force metal for today
        try {
            UIManager.setLookAndFeel (
                  UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (Exception e) { e.printStackTrace();}

        DefaultTableModel mod =
            new DefaultTableModel (TABLE_DATA, COLUMN_NAMES);
        JTable table = new JTable (mod);
        JScrollPane pane =
            new JScrollPane (table,
                             ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                             ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        JFrame frame = new JFrame ("JTable Column Widths");
        frame.getContentPane().add (pane);
        frame.pack();
        frame.setVisible (true);

        try {
            Thread.sleep (5000);
        } catch (Exception e) { e.printStackTrace(); }

        // now get smart about col widths
        final JTable fTable = table;
        SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    ColumnResizer.adjustColumnPreferredWidths (fTable);
                    fTable.revalidate();
                }
            });