## SwingOSC – Java-based GUI classes

last mod: 13-jan-08 sciss

# JSCTabbedPane

Note: please use the abstraction layer GUI.tabbedPane if possible! (see GUI)

See also: JSCView

A tabbed pane is a container whose children are again containers. The child containers can be switched through labelled tabs at the top border of the tabbed pane. Every child container created automatically creates the next tab. Typically you will use JSCCompositeView for each child.

Example:

    (
        w = JSCWindow.new;
        t = JSCTabbedPane( w, w.view.bounds );
        4.do({ arg i;
            // since c is a child of t, creating c automatically places
            // it in a new tab of t
            c = JSCCompositeView( t, t.bounds );
            6.do({ arg j;
                JSCButton( c, Rect( rrand( 20, 300 ), rrand( 20, 300 ), 75, 24 ))
                    .states_([[ "Start "++i++"/"++j, Color.black, Color.rand ],
                              [ "Stop " ++i++"/"++j, Color.white, Color.red ]]);
            });
        });
        w.front;
    )

## Customizing the tabs

The properties of each tab-button are modified using the scheme

        <myTabPane>.set<PropertyName>At( <(Integer) tabIndex>, <propertyValue> );

where `<tabIndex>` goes from `0` to `<myTabPane>.numTabs-1`. Properties are:

name | value-class | description
`title` | String or Symbol | text label for the tab button
`enabled` | Boolean | whether the tab is selectable or not
`background` | Color | background colour of the tab button
`foreground` | Color | foreground (text label) colour of the tab button
`toolTip` | String or Symbol | helper text which is shown when mouse rests over tab button

Examples for modifying the tab buttons:

        t.setTitleAt( 0, "First" );       // set the title of tab #0 (i.e. the leftmost tab)
        t.setTitleAt( 1, "Second" );      // set the title of tab #1 (i.e. the second from the left)
        t.setTitleAt( 2, "Third" );
        t.setTitleAt( 3, "Forth" );
        t.numTabs.do({ arg i; t.setBackgroundAt( i, Color.rand( 0.5, 1 ))});
        t.numTabs.do({ arg i; t.setForegroundAt( i, Color.rand( 0, 0.5 ))});
        t.setEnabledAt( 2, false );     // now tab #2 cannot be selected any more
        t.setToolTipAt( 0, "Dem first tab" ); // set info text shown when mouse rests over tab-button

        // tab index -1 is a shortcut for changing all tabs at once
        t.setBackgroundAt( -1, Color.green( 0.5 ));
        t.setForegroundAt( -1, Color.white );

## Customizing the tab pane

Changing the location of the button bar:

        t.tabPlacement = \left;
        t.tabPlacement = \bottom;
        t.tabPlacement = \right;
        t.tabPlacement = \top;

Changing the font of the button labels:

        t.font = JFont( "Monospaced", 14 );

## Invoking and recognizing tab switches

To detect when the user switches the tabs, register with the `action_` method:

        t.action = { arg b; ("Selected tab now: " ++ b.value).postln };

Programmatically setting the currently visible tab:

        fork { t.numTabs.do({ arg i; t.value = i; 1.wait })};

Same but also calling action function:

        fork { t.numTabs.do({ arg i; t.valueAction = i; 1.wait })};