This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes TabFolder / TabItem Code Organsiation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "TabFolder / TabItem Code Organsiation" Watch "TabFolder / TabItem Code Organsiation" New topic
Author

TabFolder / TabItem Code Organsiation

Mark Rowe
Greenhorn

Joined: Jan 16, 2012
Posts: 3
I am trying to port a legacy application from Qt to Java. This is my first time with Java so please bear with me. I have also tried googling with every combination of words I can think of without success.

In the application the user selects a "work page" from a list (on the left of the screen) in a similar fashion to selecting a file in the Package Explorer in Eclipse. At startup only a "Welcome" type page is shown.

As each page is "opened" from the page list a new tab (TabItem) opens showing that page in the main part of the screen (again like Eclipse). The pages are quite different however, some containing text, some a few controls, some with tables others with further TabFolders in them.

I would like to:
  • Construct each "page" design using WindowBuilder
  • Have each page in a separate file (class)
  • Separate the code for the page business logic from the code for the UI
  • Add / delete / switch to the pages to the TabFolder at run time.

  • Any hints and tips on how to do this would be great.

    Mark
    Michael Dunn
    Ranch Hand

    Joined: Jun 09, 2003
    Posts: 4632
    TabFolder / TabItem - are these part of SWT?

    If so, there's not a lot of SWT traffic here and many SWT questions remain unanswered.
    Don't know the best place for SWT.

    If it's Swing, it sounds like a JTabbedPane, and your 'component' questions would have simple answers.
    Mark Rowe
    Greenhorn

    Joined: Jan 16, 2012
    Posts: 3
    Michael, thank you for taking the time to respond to my post and I am sorry I have been slow to reply.

    Yes, these controls are part of SWT and are provided byorg.eclipse.swt.widgets.TabFolder and org.eclipse.swt.widgets.TabItem respectively.

    TabFolder is basically a container for TabItems, which in turn can contain any number of other layouts and controls.

    I haven't looked at Swing much, but from what I have just read it seems a similar concept except in Swing you add JComponents to the JTabbedPane whereas in SWT you add TabItems to the TabFolder.

    I am interested in how you can solve this in Swing because it might be possible to use a similar method in SWT.

    The approaches I have considered (but not tested) so far are:

  • Creating the tab page as a Dialog (or maybe Shell or Composite), adding layouts components etc. then adding it to the TabFolder by casting the Dialog to a TabItem (this is how Qt works)
  • Creating a Dialog (or Shell or Composite), adding a TabFolder and TabItem and then somehow referencing that TabItem in the main code


  • Out of interest, why isn't their much SWT traffic on this list?

    Mark





    Michael Dunn
    Ranch Hand

    Joined: Jun 09, 2003
    Posts: 4632
    A JTabbedPane sounds a lot like your TabFolder.
    it looks like MS's Excel (tabs are at top), but each tab is (generally) a JPanel 'page',
    with each 'page' containing one or more components.

    here's a link to the 'How to use TabbedPanes' tutorial
    http://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html
    there are a number of demo programs there that you can run and see its functionality.

    > Out of interest, why isn't their much SWT traffic on this list?

    it seems none of the regular readers/helpers/contributors here uses SWT.
    Possibly because it's tied in with Eclipse (I think) - I don't use Eclipse, and
    that might be the same for the other regulars.
    Mark Rowe
    Greenhorn

    Joined: Jan 16, 2012
    Posts: 3
    Thanks for the explanations!
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: TabFolder / TabItem Code Organsiation