Universal Robots Forum

GUI performance

Hi,

i am developing a Plug-in, which contains 5 JSliders. All of them are updating the ProgramNode-Title individually.
Unfortunately, the performance of my gui is suffering from that. The slider motion is really laggy.

The part draining on the performance is mainly this one (and getTitle()):

public void onSliderSelection(final int[] newValue)
{
undoRedoManager.recordChanges(new UndoableChanges() {

		@Override
		public void executeChanges() {
			
			for(int j=0; j<5; j++)
			{
				model.set(Motion_Key[j], newValue[j]);
			}
			
		}
	});
}

Here i am “saving” the value for each slider. What can i do differently to have fluent slider motion and updated title?

Thank you in advance!

I got the problem.
I wrote my functions really poorly, each slider was triggering two for-loops(one in view and one in the contribution) resulting into this performance loss. The dataModel was invoked way to often.

Sorry for bothering with those rookie problems.

1 Like

A suggestion could be:

View.class: Have a changelistener on all of the sliders…

slider.addChangeListener(new ChangeListener() {

		@Override
		public void stateChanged(ChangeEvent arg0) {

                        provider.get().onSliderSelection("nameOfSlider", valueOfTheSlider)

		}
	});

Contribution.class: make a switch case to decided which slider value to set as the title.

public void onSliderSelection(final String nameOfSlider ,final int newValue)
{
undoRedoManager.recordChanges(new UndoableChanges() {

		@Override
		public void executeChanges() {
			
                  setMyModelBasedOnSliderValue(nameOfSlider, newValue)
			
		}
	});
}

Private setMyModelBasedOnSliderValue(String nameOfSlider, int inputValue) {

switchCase(nameOfSlider):

case(slider1) 

      model.setValue(inputValue)

case(slider2)

      model.setValue(inputValue)

....etc...
}


By using switch case, it could be something like that. It would avoid looping. Hope it helped!
1 Like

Thank you for the reply,

I tried it with switchcase but my jre version wouldnt allow strings as case values.
So i just gave every slider a key value on the view side. For the contribution, i left it as it is but without a for-loop.
Now it works bug- and lagfree.

2 Likes

In general, if there is a need for how to incorporate Swing GUI, then have a look at this article. on our getting started site. It contains example for swing components that are often use in developing a URCap. :blush:

1 Like