You firstly need to create a helper file, for example:
administrator/components/com_helloworld/helpers/helloworld.php
and in this file, add the following:
class HelloWorldHelper extends JHelperContent
{
public static function addSubmenu($vName)
{
JHtmlSidebar::addEntry(
'test',
'index.php?option=com_hellowworld&view=VIEWNAME',
$vName == 'banners'
);
}
}
Change VIEWNAME and the value for $vName to the view for your component that you wish to add the sidebar to.
Then, in your view.html.php file, call it using the following:
HelloWorldHelper::addSubmenu('VIEWNAME');
and of course, the following is required to render the sidebar which you can put below the code above:
$this->sidebar = JHtmlSidebar::render();
If you have a look at the Banners component that comes packaged with Joomla, it will provide a good example.
Update:
If forgot to mention, inside your addToolbar() function in the view.html.php file, you will need to call the helper file like so:
require_once JPATH_COMPONENT . '/helpers/hellowworld.php';
Update 2:
Sorry, I'm not on the ball today. You will need to add the following to your default.php in views/VIEWNAME/tmpl:
<div id="j-sidebar-container" class="span2">
<?php echo $this->sidebar; ?>
</div>
<div id="j-main-container" class="span10">
// Main part of the component view
</div>