A question on TabFolder and TabItem

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

A question on TabFolder and TabItem

Postby avier5 » Wed Aug 11, 2004 5:08 am

Hi All,

In my application I have few Tabfolders. When I start the application I need that a specific tabItem in each of the tabFolders will be open and show its content.

How can I achive that operation?
bab086
Thanks,

HBC. :wink:
avier5
 
Posts: 41
Joined: Thu Jul 22, 2004 12:12 am

Postby admin » Wed Aug 11, 2004 9:59 pm

Something like this:

Code: Select all
      final Display display = new Display();
      final Shell shell = new Shell();
      final GridLayout gridLayout = new GridLayout();
      gridLayout.numColumns = 1;
      shell.setLayout(gridLayout);
      shell.setText("SWT Application");
      {
         m_TabFolder = new TabFolder(shell, SWT.NONE);
         m_TabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
         {
            final TabItem tabItem = new TabItem(m_TabFolder, SWT.NONE);
            tabItem.setText("item1");
            {
               final Button button = new Button(m_TabFolder, SWT.NONE);
               tabItem.setControl(button);
               button.setText("button1");
            }
         }
         {
            final TabItem tabItem = new TabItem(m_TabFolder, SWT.NONE);
            tabItem.setText("item2");
            {
               final Button button = new Button(m_TabFolder, SWT.NONE);
               tabItem.setControl(button);
               button.setText("button2");
            }
         }
      }
      m_TabFolder.setSelection(1);
      shell.open();
      while (!shell.isDisposed()) {
         if (!display.readAndDispatch())
            display.sleep();
      }
admin
Moderator
 
Posts: 166
Joined: Thu Jul 24, 2003 12:25 am

Postby avier5 » Thu Aug 12, 2004 1:29 am

Once more Thanks a lot.....

HBC :lol: 8) :D :) :wink: :wink: :wink:
avier5
 
Posts: 41
Joined: Thu Jul 22, 2004 12:12 am

Postby jleotta » Fri Aug 13, 2004 6:39 am

I put this method at the end of the composite that creates the TabFolder:

private void makeTabVisible(TabFolder tabFolder, String folder){
if (currentTab !=null){
currentTab.dispose();
}
TabItemFactory TF = new TabItemFactory();
Composite tabContainer = TF.getTabContainer(tabFolder, folder);
(tabFolder.getItem(tabFolder.getSelectionIndex())).setControl(tabContainer);
}

I add the word "Tab" to the tabitem text label and call the tabItems Factory which returns the proper Tab to place on the TabFolder.

The code for the factory is :

public Composite getTabContainer(Composite tabFolder, String className){
Composite newtabitem = null;
try{
Class cls = Class.forName(className);

Class parTypes[] = new Class[2];
parTypes[0] = Composite.class;
parTypes[1] = Integer.TYPE;
Constructor ct = cls.getConstructor(parTypes);
Object argList[] = new Object[2];
argList[0] = tabFolder;
argList[1] = new Integer(0);
newtabitem = (Composite) ct.newInstance(argList);
}catch(Throwable e){
System.err.println(e);
}
return newtabitem;
}
jleotta
 
Posts: 31
Joined: Tue Aug 03, 2004 9:46 am


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest