{"id":295,"date":"2012-04-10T20:45:14","date_gmt":"2012-04-10T18:45:14","guid":{"rendered":"http:\/\/www.pellissier.co.za\/hermien\/?p=295"},"modified":"2012-04-10T20:45:14","modified_gmt":"2012-04-10T18:45:14","slug":"extending-the-netbeans-platform-status-bar","status":"publish","type":"post","link":"https:\/\/www.pellissier.co.za\/hermien\/?p=295","title":{"rendered":"Extending the NetBeans Platform Status Bar"},"content":{"rendered":"<p>The status bar that appears at the bottom of a NetBeans Platform application can be extended with your own components. When I recently wanted to do this, I searched the Internet for good resources on this topic. And so I found <a href=\"http:\/\/emilian-bold.blogspot.com\/2006\/08\/netbeans-platform-statuslineelementpro.html\">this blog entry by Emilian Bold<\/a>. It is very useful indeed, but it dates back to before the introduction of the <a href=\"http:\/\/bits.netbeans.org\/dev\/javadoc\/org-openide-util-lookup\/org\/openide\/util\/lookup\/ServiceProvider.html\">@ServiceProvider<\/a> annotation. And so I decided to write this article with more up do date information.<\/p>\n<p>Just as Emilian describes, the first step is to create a class that implements <a href=\"http:\/\/bits.netbeans.org\/dev\/javadoc\/org-openide-awt\/org\/openide\/awt\/StatusLineElementProvider.html\">StatusLineElementProvider<\/a>.<\/p>\n<p>[java]import java.awt.Component;<br \/>\nimport javax.swing.JLabel;<br \/>\nimport org.openide.awt.StatusLineElementProvider;<\/p>\n<p>public class NewStatusLineElement implements StatusLineElementProvider<br \/>\n{<br \/>\n    @Override<br \/>\n    public Component getStatusLineElement()<br \/>\n    {<br \/>\n        return new JLabel(&#8220;Shalom&#8221;);<br \/>\n    }<br \/>\n}[\/java]<\/p>\n<p>This requires a module dependency on the UI Utilities API module.<\/p>\n<p>The difference is that instead of adding an entry to a META-INF\/services file, we add the @ServiceProvider annotation to the class:<\/p>\n<p>[java]import java.awt.Component;<br \/>\nimport javax.swing.JLabel;<br \/>\nimport org.openide.awt.StatusLineElementProvider;<br \/>\nimport org.openide.util.lookup.ServiceProvider;<\/p>\n<p>@ServiceProvider(service = StatusLineElementProvider.class, position = 100)<br \/>\npublic class NewStatusLineElement implements StatusLineElementProvider<br \/>\n{<br \/>\n    @Override<br \/>\n    public Component getStatusLineElement()<br \/>\n    {<br \/>\n        return new JLabel(&#8220;Shalom&#8221;);<br \/>\n    }<br \/>\n}[\/java]<\/p>\n<p>This requires a dependency on the Lookup API module.<\/p>\n<p>One more interesting point. I wanted to add a separator between two of my items, but it just would not appear. And then I realised it might need to have a size specified. So here is the getStatusLineElement() method that successfully adds a separator:<\/p>\n<p>[java]@Override<br \/>\npublic Component getStatusLineElement()<br \/>\n{<br \/>\n    JSeparator s = new JSeparator(SwingConstants.VERTICAL);<br \/>\n    s.setPreferredSize(new Dimension(5, 16));<br \/>\n    return s;<br \/>\n}[\/java]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The status bar that appears at the bottom of a NetBeans Platform application can be extended with your own components. When I recently wanted to do this, I searched the Internet for good resources on this topic. And so I found this blog entry by Emilian Bold. It is very useful indeed, but it dates &#8230; <a title=\"Extending the NetBeans Platform Status Bar\" class=\"read-more\" href=\"https:\/\/www.pellissier.co.za\/hermien\/?p=295\" aria-label=\"More on Extending the NetBeans Platform Status Bar\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[3,5],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1v8WL-4L","_links":{"self":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/posts\/295"}],"collection":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=295"}],"version-history":[{"count":0,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/posts\/295\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}