From $ROOTSYS/tutorials/gui/staffTableTest.C

// This TableTest class is a simple example of how to use a TGTable
// with a TTreeTableInterface. TableTest inherits from TGMainFrame to
// create a top level frame to embed the TGTable in. First, the
// staff.root file is opened to obtain a tree. This tree also contains
// strings as data. Then a TTreeTableInterface is created using this
// tree. A table is then created using the interface. In the end, the
// table is added to the TGMainFrame that is the TableTest and the
// necessary calls to correctly draw the window are made. For more
// information about the use of TTreeTableInterface and TGTable, see
// their documentation.

// author: Roel Aaij 13/07/2007

#include <iostream>
#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGWindow.h>
#include <TString.h>
#include <TGTable.h>
#include <TTreeTableInterface.h>
#include <TFile.h>
#include <TNtuple.h>
#include <TSelectorDraw.h>

// A little class to automatically handle the generation of unique
// widget ids.
class IDList {
private:
   Int_t nID ;               // Generates unique widget IDs.
public:
   IDList() : nID(0) {}
   ~IDList() {}
   Int_t GetUnID(void) { return ++nID ; }
} ;

class TableTest : public TGMainFrame {

private:
   IDList   fIDs ;      // Generator for unique widget IDs.
   UInt_t   fNTableRows;
   UInt_t   fNTableColumns;
   TGTable *fTable;
   TFile   *fFile;

   TTreeTableInterface *fInterface;

public:
   TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols,
             UInt_t w = 100, UInt_t h = 100) ;
   virtual ~TableTest() ;

   void DoExit() ;

   TGTable *GetTable() { return fTable; }
   TTreeTableInterface *GetInterface() { return fInterface; }

   ClassDef(TableTest, 0)
};

TableTest::TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols,
                     UInt_t w, UInt_t h)
   : TGMainFrame(p, w, h),  fNTableRows(ntrows), fNTableColumns(ntcols),
     fTable(0)
{
   SetCleanup(kDeepCleanup) ;
   Connect("CloseWindow()", "TableTest", this, "DoExit()") ;
   DontCallClose() ;

   // Open root file for the tree
   fFile = new TFile("cernstaff.root");

   if (!fFile || fFile->IsZombie()) {
      printf("Please run <ROOT location>/tutorials/tree/cernbuild.C first.");
      return;
   }

   // Get the tree from the file.
   TTree *tree = (TTree *)fFile->Get("T");

   // Setup the expressions for the column and selection of the interface.
   TString varexp = "*";
   TString select = "";
   TString options = "";
   fInterface = new TTreeTableInterface(tree, varexp.Data(), select.Data(),
                                        options.Data());

   // Create a table using the interface and add it to the TableTest
   // that is a TGMainFrame.
   fTable = new TGTable(this, fIDs.GetUnID(), fInterface, fNTableRows,
                                fNTableColumns);
   AddFrame(fTable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));

   // Calls to layout and draw the TableTest that is a TGMainFrame.
   SetWindowName("Tree Table Test") ;
   MapSubwindows() ;
   Layout();
   Resize(GetDefaultWidth()+20, 600) ;
   MapWindow() ;

} ;

TableTest::~TableTest()
{
   // Destructor
   delete fInterface;
   fFile->Close();
   Cleanup() ;
}

 void TableTest::DoExit()
{
   // Exit this application via the Exit button or Window Manager.
   // Use one of the both lines according to your needs.
   // Please note to re-run this macro in the same ROOT session,
   // you have to compile it to get signals/slots 'on place'.

   DeleteWindow();            // to stay in the ROOT session
   //   gApplication->Terminate();   // to exit and close the ROOT session
}

TGTable *staffTableTest(UInt_t ntrows = 50, UInt_t ntcols = 10) {
   TableTest *test = new TableTest(0, ntrows, ntcols, 500, 200);
   return test->GetTable();
}
 staffTableTest.C:1
 staffTableTest.C:2
 staffTableTest.C:3
 staffTableTest.C:4
 staffTableTest.C:5
 staffTableTest.C:6
 staffTableTest.C:7
 staffTableTest.C:8
 staffTableTest.C:9
 staffTableTest.C:10
 staffTableTest.C:11
 staffTableTest.C:12
 staffTableTest.C:13
 staffTableTest.C:14
 staffTableTest.C:15
 staffTableTest.C:16
 staffTableTest.C:17
 staffTableTest.C:18
 staffTableTest.C:19
 staffTableTest.C:20
 staffTableTest.C:21
 staffTableTest.C:22
 staffTableTest.C:23
 staffTableTest.C:24
 staffTableTest.C:25
 staffTableTest.C:26
 staffTableTest.C:27
 staffTableTest.C:28
 staffTableTest.C:29
 staffTableTest.C:30
 staffTableTest.C:31
 staffTableTest.C:32
 staffTableTest.C:33
 staffTableTest.C:34
 staffTableTest.C:35
 staffTableTest.C:36
 staffTableTest.C:37
 staffTableTest.C:38
 staffTableTest.C:39
 staffTableTest.C:40
 staffTableTest.C:41
 staffTableTest.C:42
 staffTableTest.C:43
 staffTableTest.C:44
 staffTableTest.C:45
 staffTableTest.C:46
 staffTableTest.C:47
 staffTableTest.C:48
 staffTableTest.C:49
 staffTableTest.C:50
 staffTableTest.C:51
 staffTableTest.C:52
 staffTableTest.C:53
 staffTableTest.C:54
 staffTableTest.C:55
 staffTableTest.C:56
 staffTableTest.C:57
 staffTableTest.C:58
 staffTableTest.C:59
 staffTableTest.C:60
 staffTableTest.C:61
 staffTableTest.C:62
 staffTableTest.C:63
 staffTableTest.C:64
 staffTableTest.C:65
 staffTableTest.C:66
 staffTableTest.C:67
 staffTableTest.C:68
 staffTableTest.C:69
 staffTableTest.C:70
 staffTableTest.C:71
 staffTableTest.C:72
 staffTableTest.C:73
 staffTableTest.C:74
 staffTableTest.C:75
 staffTableTest.C:76
 staffTableTest.C:77
 staffTableTest.C:78
 staffTableTest.C:79
 staffTableTest.C:80
 staffTableTest.C:81
 staffTableTest.C:82
 staffTableTest.C:83
 staffTableTest.C:84
 staffTableTest.C:85
 staffTableTest.C:86
 staffTableTest.C:87
 staffTableTest.C:88
 staffTableTest.C:89
 staffTableTest.C:90
 staffTableTest.C:91
 staffTableTest.C:92
 staffTableTest.C:93
 staffTableTest.C:94
 staffTableTest.C:95
 staffTableTest.C:96
 staffTableTest.C:97
 staffTableTest.C:98
 staffTableTest.C:99
 staffTableTest.C:100
 staffTableTest.C:101
 staffTableTest.C:102
 staffTableTest.C:103
 staffTableTest.C:104
 staffTableTest.C:105
 staffTableTest.C:106
 staffTableTest.C:107
 staffTableTest.C:108
 staffTableTest.C:109
 staffTableTest.C:110
 staffTableTest.C:111
 staffTableTest.C:112
 staffTableTest.C:113
 staffTableTest.C:114
 staffTableTest.C:115
 staffTableTest.C:116
 staffTableTest.C:117
 staffTableTest.C:118
 staffTableTest.C:119
 staffTableTest.C:120
 staffTableTest.C:121
 staffTableTest.C:122
 staffTableTest.C:123
 staffTableTest.C:124
 staffTableTest.C:125
 staffTableTest.C:126
 staffTableTest.C:127