Extending the NetBeans Platform Status Bar

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 back to before the introduction of the @ServiceProvider annotation. And so I decided to write this article with more up do date information.

Just as Emilian describes, the first step is to create a class that implements StatusLineElementProvider.

[java]import java.awt.Component;
import javax.swing.JLabel;
import org.openide.awt.StatusLineElementProvider;

public class NewStatusLineElement implements StatusLineElementProvider
{
@Override
public Component getStatusLineElement()
{
return new JLabel(“Shalom”);
}
}[/java]

This requires a module dependency on the UI Utilities API module.

The difference is that instead of adding an entry to a META-INF/services file, we add the @ServiceProvider annotation to the class:

[java]import java.awt.Component;
import javax.swing.JLabel;
import org.openide.awt.StatusLineElementProvider;
import org.openide.util.lookup.ServiceProvider;

@ServiceProvider(service = StatusLineElementProvider.class, position = 100)
public class NewStatusLineElement implements StatusLineElementProvider
{
@Override
public Component getStatusLineElement()
{
return new JLabel(“Shalom”);
}
}[/java]

This requires a dependency on the Lookup API module.

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:

[java]@Override
public Component getStatusLineElement()
{
JSeparator s = new JSeparator(SwingConstants.VERTICAL);
s.setPreferredSize(new Dimension(5, 16));
return s;
}[/java]

Instructional designer, educational technologist and occasional lecturer who loves travel and photography

1 thought on “Extending the NetBeans Platform Status Bar”

Leave a Comment