Yes you can do that. You can give a max-height to your ScrollPanel.
ScrollPanel p = new ScrollPanel();
p.getElement().getStyle().setProperty( "maxHeight", "500px" );
So when your HTML panel is 300px , the height of your scrollpanel will be 300px. When the HTML panel height is > 500px then ScrollPanel will show the scroll bar
Another way :
suppose you have a class added to ScrollPanel called .scp then the css will be
.scp
{
max-height: 500px
}
Then Add that class to your scrollpanel
ScrollPanel p = new ScrollPanel();
p.addStyleName( "scp" );