Notice: This is a static archive of the Mobile Processing website, as the project is no longer significantly active. All forms and the Discourse boards are no longer functional, and the mobile website at http://wapmp.at/ is no longer available. Please visit the Mobile Processing Google Group for any remaining discussions and the Processing website for the latest news about Processing.
Index
Name

PContainer

Examples
PScrollBar scrollbar;
PContainer screen;

void setup() {
  //// put a scrollbar on the right side of the screen
  scrollbar = new PScrollBar();
  scrollbar.setBounds(width - 4, 0, 4, height);
  
  //// let the container fill the rest of the screen
  screen = new PContainer();
  screen.scrolling = true;
  screen.scrollbar = scrollbar;
  screen.setBounds(0, 0, width - 4, height);
  
  //// create bunch of labels and buttons, using the
  //// PContainer.HEIGHT_UNBOUNDED constant to allow them to size
  //// themselves as tall as they need to be to fit.  the
  //// container will scroll the contents
  int y = 0;
  for (int i = 0; i < 4; i++) {
    PLabel label = new PLabel("The quick brown" +
      " fox jumped over the lazy dogs.");
    label.calculateBounds(4, y, width - 8, PContainer.HEIGHT_UNBOUNDED);
    y = label.y + label.height + 4;
    screen.add(label);
    
    PButton button = new PButton("Button " + i);
    button.calculateBounds(4, y, width - 8, PContainer.HEIGHT_UNBOUNDED);
    y = button.y + button.height + 4;
    screen.add(button);
  }
  
  //// initialize the container (which initializes
  //// all of its children and the scrollbar)
  screen.initialize();
  screen.acceptFocus();
}

void draw() {
  //// draw the container (which draws its children)
  screen.draw();
}

void keyPressed() {
  //// let the container handle the input, it will
  //// pass it down to the focused child
  screen.keyPressed();
}

void keyReleased() {
  //// let the container handle the input, it will
  //// pass it down to the focused child
  screen.keyReleased();
}

Description The PContainer object manages input focus between a collection of vertically stacked components. It can also handle scrolling its children components within its bounds. Note, however, that unlike traditional UI toolkits, the PContainer object does not manage layout of its children. Each child component should have its bounds set before the container is initialized. It is also assumed that each component will be added in top-to-bottom order.
Fields
HEIGHT_UNBOUNDED   Constant value indicating an "unbounded" height, used in calculating bounds for items in a scrolling container.

focusedChild   The index of the currently focused child, or -1 if none.

scrolling   True if this container should scroll its children within its bounds.

scrollY   The current scrolling y-offset within its bounds.

scrollHeight   The total height of the children components

scrollbar   The scrollbar object to show the current scroll state.

Methods
add()   Adds a component to this container.

get()   Gets a component in the container by index.

remove()   Removes the specified component from this container.

clear()   Removes all components from this containers.

initialize()   Initializes each of its children components, calculating the total height of its children and setting up scrolling, if necessary.

keyPressed()   Allows its currently focused child to handle the keypress event.

keyReleased()   Allows its currently focused child to handle the keyrelease event.

Constructors
PContainer()
PContainer(horizontal)
Related PComponent