How to manually update AnAction?


So, I have some text in the NavBarToolBar, which I put there by creating an action which extends ToolbarLabelAction. I would like to periodically update the text displayed in that label. 

So far, I've tried to achieve this by:
1) Saving the Presentation variable of the AnActionEvent, which is passed to the update() method. I then use that to update the text with presentation.setText() outside of the update() method. This doesn't work.
2) Creating a new AnAction as follows, and calling e.getPresentation().setText(). This also doesn't work.

AnActionEvent e = new AnActionEvent(null, DataManager.getInstance().getDataContext(), ActionPlaces.NAVIGATION_BAR_TOOLBAR, new Presentation(), ActionManager.getInstance(), 0);

To give more context, the label displays some key information which I want easily visible at all times and would like it on the NavBarToolBar. It also is subject to change, therefore every 5 seconds or so, I would like to update it. 

So is it possible to do such a thing, and if so, how can it be done?



You should be able to get the JBLabel you are trying to edit from AnActionEvent parameter using:

JBLabel label = (JBLabel) anActionEvent.getPresentation().getClientProperty(CustomComponentAction.COMPONENT_KEY);

Then call label.setText() to change it.


Perfect, this works. Thanks a lot


Please sign in to leave a comment.