java – NetBeans平台和StatusLineElementProvider
作者:互联网
我正在使用NetBeans平台和Java来开发应用程序.在应用程序的底部有一个StatusDisplayer,默认情况下总是包含它.对于这个StatusDisplayer,我添加了一个面板(StatusBarJPanel).此StatusBarJPanel有两个图像图标,表示网络活动.
我不知道如何在没有活动时在运行时创建的这个面板上隐藏(setVisible(false))这些图标…如何更新StatusBarJPanel上的两个图标.
以下是将StatusBarJPanel添加到StatusDisplayer的代码:
import java.awt.Component;
import gui.StatusBarJPanel;
import org.openide.awt.StatusLineElementProvider;
import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = StatusLineElementProvider.class)
public class StatusBar implements StatusLineElementProvider {
private StatusBarJPanel statusBarBottomJPanel = new StatusBarJPanel();
@Override
public Component getStatusLineElement() {
return statusBarBottomJPanel;
}
}
解决方法:
如果我正确理解您的要求,您应该能够执行以下操作:
Collection<? extends StatusLineElementProvider> all =
Lookup.getDefault().lookupAll(StatusLineElementProvider.class);
for (StatusLineElementProvider a : all) {
if (a instanceof StatusBar) {
StatusBarJPanel ele = (StatusBarJPanel ) ((StatusBar) a).getStatusLineElement();
ele.doUpdate(); // or whatever method you need to call
}
}
使用此技术将为您提供在启动时向状态行注册的相同StatusLineElementProviders.
标签:java,swing,statusbar,netbeans-7,netbeans-platform 来源: https://codeday.me/bug/20190902/1787356.html