public void populateAllTableColumns(TableColumnModel columnModel) {
   for (int i = 0; i < v.size(); i++) {
     Object obj = v.elementAt(i);
     if (obj instanceof ColumnGroup) {
       ColumnGroup cg = (ColumnGroup) obj;
       cg.populateAllTableColumns(columnModel);
     }
   }
   if (columnIndex == null) {
     return;
   }
   for (int i = 0; i < columnIndex.length; i++) {
     int colIndex = columnIndex[i];
     v.add(columnModel.getColumn(colIndex));
   }
 }
 /**
  * Sets the margin that ColumnGroup instance will use and all held TableColumns and/or
  * ColumnGroups.
  *
  * @param margin the margin
  */
 public void setColumnMargin(int margin) {
   this.margin = margin;
   Iterator iter = v.iterator();
   while (iter.hasNext()) {
     Object obj = iter.next();
     if (obj instanceof ColumnGroup) {
       ((ColumnGroup) obj).setColumnMargin(margin);
     }
   }
 }
Esempio n. 3
0
  GroupableHeaderExample() {
    super("Groupable Header Example");

    DefaultTableModel dm = new DefaultTableModel();
    dm.setDataVector(
        new Object[][] {
          {"119", "foo", "bar", "ja", "ko", "zh"},
          {"911", "bar", "foo", "en", "fr", "pt"}
        },
        new Object[] {"SNo.", "1", "2", "Native", "2", "3"});

    JTable table =
        new JTable(dm) {
          protected JTableHeader createDefaultTableHeader() {
            return new GroupableTableHeader(columnModel);
          }
        };

    TableColumnModel cm = table.getColumnModel();
    ColumnGroup g_name = new ColumnGroup("Name");
    g_name.add(cm.getColumn(1));
    g_name.add(cm.getColumn(2));
    ColumnGroup g_lang = new ColumnGroup("Language");
    g_lang.add(cm.getColumn(3));
    ColumnGroup g_other = new ColumnGroup("Others");
    g_other.add(cm.getColumn(4));
    g_other.add(cm.getColumn(5));
    g_lang.add(g_other);

    GroupableTableHeader header = (GroupableTableHeader) table.getTableHeader();
    header.addColumnGroup(g_name);
    header.addColumnGroup(g_lang);
    JScrollPane scroll = new JScrollPane(table);
    getContentPane().add(scroll);
    setSize(400, 120);
  }