# JOptionPane.showOptionDialog trough Callable+Future

**URL:** <https://forum.universal-robots.com/t/joptionpane-showoptiondialog-trough-callable-future/6283>\
**Category:** URCap Development\
**Created:** [February 7, 2020, 12:09am UTC](https://forum.universal-robots.com/t/joptionpane-showoptiondialog-trough-callable-future/6283 "2020-02-07T00:09:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon47761871](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon47761871](https://forum.universal-robots.com/u/anon47761871)\
**Post date:** [February 7, 2020, 12:09am UTC](https://forum.universal-robots.com/t/joptionpane-showoptiondialog-trough-callable-future/6283/1 "2020-02-07T00:09:46Z")

</div>

Hi everyone, I’m developing a very simple URCaps for testing and I’ve been stucked for quite a time by now.

Contibution:

> public void generateScript(ScriptWriter writer) {  
> view.onProgramStart();  
> }

NodeView

> public void buildUI(JPanel jPanel, ContributionProvider provider) {  
> this.jPanel = jPanel;  
> }

> public void onProgramStart() throws InterruptedException, ExecutionException {  
> ExecutorService executorService = null;  
> executorService = Executors.newFixedThreadPool(3);  
> Future future = executorService.submit(new CallablePopup());  
> Integer result = future.get();  
> System.out.println("Result is: " + result);  
> }

> public class CallablePopup implements Callable {  
> @Override  
> public Integer call() throws Exception {  
> int popupIndex = 0;  
> JOptionPane.showOptionDialog(jPanel, aComboBox, "Selection: ", JOptionPane.DEFAULT\_OPTION, JOptionPane.INFORMATION\_MESSAGE, null, null, null);  
> popupIndex = aComboBox.getSelectedIndex();  
> return popupIndex;  
> }

This **works well if I launch the program while standing inside the “URCap instruction”** added to the Robot Program.  
But when I launch the Robot Program, **outside** of that instruction the JOptionPane appears, but I can’t interact with it and everything else freezes.

I can’t figure why it is happening. Certainly it’s something with JPanel but I lack the knowledge to workaround this.

Thanks for your time!

---

<div class="post-metadata">

**Author:** ![m.nagel](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/m.nagel/32/2326_2.png) [@m.nagel](https://forum.universal-robots.com/u/m.nagel)\
**Post date:** [February 7, 2020, 7:34am UTC](https://forum.universal-robots.com/t/joptionpane-showoptiondialog-trough-callable-future/6283/2 "2020-02-07T07:34:14Z")

</div>

Hi Lautaro,

it seems to me you are mixing up urscript and java.  
You could do your selection in the installation and store the selected value in the datamodel. In _generateScript_ you could read your stored value and write it to a urscript variable.

API  
com.ur.urcap.api.domain.data  
DataModel (set/get)

com.ur.urcap.api.domain.script  
ScriptWriter (assign)

---

<div class="post-metadata">

**Author:** ![anon47761871](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon47761871](https://forum.universal-robots.com/u/anon47761871)\
**Post date:** [February 8, 2020, 1:36pm UTC](https://forum.universal-robots.com/t/joptionpane-showoptiondialog-trough-callable-future/6283/3 "2020-02-08T13:36:49Z")

</div>

Hi, thanks for your answer. I could do what you proposed but I’m trying to show a custom popup when program starts. That’s why I’m using urscript to launch a Java function. I tought that was the right way to do that. Is this correct?

Please correct me if I wrong. When I’m in the JPanel of the buildUI the popup appears and works well, but when I’m outside the JPanel the popup appears but freeze everything else. There is a way of calling the popup without JPanel as parent frame? I tried to call the optionPane with NULL parent in the first argument but with no better results.  
There’s a way for the popup to belong to the entire polyscope instead of belonging only to my buildUI JPanel?

Thanks again, I really appreciate your help.

---

<div class="post-metadata">

**Author:** ![m.nagel](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/m.nagel/32/2326_2.png) [@m.nagel](https://forum.universal-robots.com/u/m.nagel)\
**Post date:** [February 8, 2020, 6:11pm UTC](https://forum.universal-robots.com/t/joptionpane-showoptiondialog-trough-callable-future/6283/4 "2020-02-08T18:11:37Z")

</div>

In 2018 I had a similar question - I wanted to offer a java-selection/configuration menu for the user on startup of the robot program …  
I can share my experience but Iam not an expert. UR-Developer please correct me if Iam wrong with the next lines.

If you start your robot-program you will leave the “java-section” and urscript will be triggered on the controller. With _generateScript_ you are able to insert ursript-code from your configuration in installationNode or from your programNodes.  
Iam really not sure about timing and at which point(s) _generateScript_ will be triggered (assuming at start and save)  
But I think at this point (run program) no java-code with user interaction should be implemented.

If you have started your robot-program you should interact with your robot by the offered interfaces.  
eg via daemon, primary, secondary, rtde, profinet …

Are you using the CB-Series or the e-Series?  
In the e-Series you have the possibility to interact with the toolbar.  
eg IO via API or URScript via primary, secondary and realtime interface should also work - maybe this could help you.  
In urscript is also a popup-function but with less possibilities like in java.

What selection could the user do in your JPanel? Maybe there is a workaround.

Edit:  
[UR-Software-architecture](https://plus.universal-robots.com/getting-started/ur-software-architecture/)

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/6/6196566bb443eb29a98c5b6875ed509d3977b7a8.png)

---

<div class="post-metadata">

**Author:** ![anon47761871](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon47761871](https://forum.universal-robots.com/u/anon47761871)\
**Post date:** [February 9, 2020, 11:46am UTC](https://forum.universal-robots.com/t/joptionpane-showoptiondialog-trough-callable-future/6283/5 "2020-02-09T11:46:43Z")

</div>

Mr. Mike, I really appreciate your kindness. I understand what you say and maybe there’s another way to achieve my goal. I want to implement a simple product selection. I’m attaching a photo of Pally software for palletizing. I want something similar but for cb10 robot instead. How do you think it has to be implemented in Java / urscript?

Thanks Mike.

 ![Screenshot_20200209-084004](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/7/7b801c7c48ba1f9e3371d2c845bf2f4d52babf55.jpeg)

---

<div class="post-metadata">

**Author:** ![m.nagel](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/m.nagel/32/2326_2.png) [@m.nagel](https://forum.universal-robots.com/u/m.nagel)\
**Post date:** [February 9, 2020, 5:58pm UTC](https://forum.universal-robots.com/t/joptionpane-showoptiondialog-trough-callable-future/6283/6 "2020-02-09T17:58:36Z")

</div>

Hi Lautaro,

Not knowing about the implemenation of this selection-frame and corresponding to the ur-guidelines.  
It looks like one of the most requested features of the forum: [Runtime Interaction GUI elements](https://forum.universal-robots.com/t/runtime-interaction-gui-elements/809)

You could create a programNode with a comboBox for product selection and add it to program tree. But I think you want to achieve the selection without opening the robot program source-tree.

You could create a urcap with a daemon which is waiting via socket for a value. But in this case the selection is on another device.

Are you working with a PLC (and a HMI) in your environment?  
You could write a value to a register of the robot. In this case you also trigger this event from another device.

With RTDE you could also write to a register - but … from another device.

You could sacrifice your digital inputs ?!

But now Iam running out of ideas - maybe someone has a better simpler idea?

well, all of these suggestions are workarounds

---

<div class="post-metadata">

**Author:** ![anon47761871](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon47761871](https://forum.universal-robots.com/u/anon47761871)\
**Post date:** [February 10, 2020, 10:24am UTC](https://forum.universal-robots.com/t/joptionpane-showoptiondialog-trough-callable-future/6283/7 "2020-02-10T10:24:04Z")

</div>

Thanks again Mike, we are currently using a integer input like “index position” on a couple of vectors who have our working values saved.  
I believe there is a way to do what I’m asking since Pally software has this feature. I also understand there is no easy and standard way to implement it.

Really appreciate your help.

---

<div class="post-metadata">

**Author:** ![m.nagel](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/m.nagel/32/2326_2.png) [@m.nagel](https://forum.universal-robots.com/u/m.nagel)\
**Post date:** [February 11, 2020, 6:23am UTC](https://forum.universal-robots.com/t/joptionpane-showoptiondialog-trough-callable-future/6283/8 "2020-02-11T06:23:55Z")

</div>

you´re welcome - if you have a working soulution please let me know iam also interested
