|
| 1 | +import java.awt.*; |
| 2 | +import javax.swing.*; |
| 3 | +import javax.swing.border.*; |
| 4 | +import javax.swing.table.*; |
| 5 | + |
| 6 | +public class TableColumnManagerDemo extends JPanel |
| 7 | +{ |
| 8 | + private TableColumnManager marquee; |
| 9 | + private JSpinner scrollFrequency; |
| 10 | + private JSpinner scrollAmount; |
| 11 | + private JSpinner preferredWidth; |
| 12 | + private JSpinner wrapAmount; |
| 13 | + |
| 14 | + TableColumnManagerDemo() |
| 15 | + { |
| 16 | + setLayout( new BorderLayout(10, 10) ); |
| 17 | + setBorder( new EmptyBorder(10, 10, 10, 10) ); |
| 18 | + |
| 19 | + JComponent center = createCenterPanel(); |
| 20 | + add(center, BorderLayout.CENTER); |
| 21 | + } |
| 22 | + |
| 23 | + public JComponent createCenterPanel() |
| 24 | + { |
| 25 | + JTable table = new JTable( new DefaultTableModel(15, 15) ) |
| 26 | + { |
| 27 | + public Class getColumnClass(int column) |
| 28 | + { |
| 29 | + int modelColumn = convertColumnIndexToModel( column ); |
| 30 | + return (modelColumn == 0) ? Integer.class : Object.class; |
| 31 | + } |
| 32 | + }; |
| 33 | + table.setPreferredScrollableViewportSize(table.getPreferredSize()); |
| 34 | + |
| 35 | + TableColumnManager tcm = new TableColumnManager(table); |
| 36 | + tcm.hideColumn(2); |
| 37 | + tcm.hideColumn("E"); |
| 38 | +// tcm.showColumn("C"); |
| 39 | + tcm.showColumn(2); |
| 40 | + |
| 41 | + return new JScrollPane( table ); |
| 42 | + } |
| 43 | + |
| 44 | + public static void main(String[] args) |
| 45 | + { |
| 46 | + SwingUtilities.invokeLater(new Runnable() { |
| 47 | + public void run() { |
| 48 | + createAndShowGUI(); |
| 49 | + } |
| 50 | + }); |
| 51 | + } |
| 52 | + |
| 53 | + public static void createAndShowGUI() |
| 54 | + { |
| 55 | + JFrame frame = new JFrame("Table Column Manager"); |
| 56 | + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 57 | + frame.add( new TableColumnManagerDemo() ); |
| 58 | + frame.pack(); |
| 59 | + frame.setLocationRelativeTo(null); |
| 60 | + frame.setVisible(true); |
| 61 | + } |
| 62 | +} |
0 commit comments