Help with scrollable component /viewport please


#1

i have a class defined like this. 

class BlockField  : public Component  public Timer, public ButtonListener

 

I wanted this component to be scrolabble if needed so, assuming that i can do this not in a component but in ViewPort which  is a subclass i changed this class to:

class BlockField  : public Viewport,  public Timer, public ButtonListener

 

in constructor i added: addAndMakeVisible (component = new BlockField()); 

component->setScrollBarsShown(true, true);

component->setScrollBarThickness(10);

component->setVisible(true);

but the scrolling is not happenning? any thoughts what am i doing wrong or what i should do?

 

Thank you

Dee


#2

BlockField should derive from Component, and ViewPort typically does not need to be subclassed.

Your parent compponent class should do something like:

SomeComp : public Component
{
public:

  SomeComp
  {
    blockField.setSize(1000,1000);
    viewPort.setViewedComponent(&blockField, false);
    addAndMakeVisible(&viewPort);
  }


  void resized()
  {
    viewPort.setBoundsRelative(0.0f, 0.0f, 1.0f, 1.0f);
  }

private:

  ViewPort viewPort;
  BlockField blockField;
};

 


#3

nice Thank you helped me  a lot! 

dee