Can create a scrollbar on a component without viewport?

Hello, I want to create and make a scrollbar appear on the main component
The document says, a viewport can make a scrollbar easily
However, it doesn’t say a viewport is always required
So can I create a scrollbar without using viewports or listbox etc ?
Thanks

Yes sure. Just create one. It is a simple component. You can then listen to the ScrollBar and update your model accordingly.

Hello, Daniel
Thank you
However, the scrollbar does not appear on my MainComponent
So what will be further required? Should I assign a listener to it ?

The same steps as with any Component are required:

class MyComponent : public juce::Component,
                    private juce::ScrollBar::Listener
{
public:
    MyComponent()
    {
        scrollbar.setAutoHide (false);
        addAndMakeVisible (scrollbar);
        scrollbar.addListener (this);
    }

    ~MyComponent() override
    {
        scrollbar.removeListener (this); // just in case
    }

    void resized() override
    {
        auto bounds = getLocalBounds();
        scrollbar.setBounds (bounds.removeFromRight (20);
    }

    void scrollBarMoved (juce::ScrollBar*, double newRangeStart) override
    {
        // do something
    }

private:
    juce::ScrollBar scrollbar { false };
};

and make sure you don’t have another component occlude the scrollbar. Either call addAndMakeVisible last for the scrollbar, or call toFront() at the end of the constructor.

Hello, Daniel, now it works all right !
Thank you so much for your kindness
See you

I’m glad I could help

Good Night, Daniel