# Dynamically changing GUI items on command panel

**URL:** https://forum.universal-robots.com/t/dynamically-changing-gui-items-on-command-panel/4215
**Category:** URCap Development
**Created:** [May 2, 2019, 2:07pm UTC](https://forum.universal-robots.com/t/dynamically-changing-gui-items-on-command-panel/4215 "2019-05-02T14:07:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![anon15700319](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@anon15700319](https://forum.universal-robots.com/u/anon15700319)
#### Post date: [May 2, 2019, 2:07pm UTC](https://forum.universal-robots.com/t/dynamically-changing-gui-items-on-command-panel/4215/1 "2019-05-02T14:07:15Z")

</div>

Hi,

I wish to implement a URCap that provides multiple different commands, which each have different parameters. I envision to choose a command from a pull-down menu with different GUI items appearing/hiding based on this choice.

An example of such a behavior is the “Move” command, which allows the user to choose between MoveL, MoveJ, or MoveC, and new fields dynamically appearing.

What is the best way to implement this behavior? I tried to put a switch statement into the BuildUI method of my view, but it does not allow accessing data from the contribution.

Thanks,  
Nikolaus

---

<div class="post-metadata">

### Author: ![sam.verity-hilton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/sam.verity-hilton/32/6046_2.png) [@sam.verity-hilton](https://forum.universal-robots.com/u/sam.verity-hilton)
#### Post date: [May 2, 2019, 2:48pm UTC](https://forum.universal-robots.com/t/dynamically-changing-gui-items-on-command-panel/4215/2 "2019-05-02T14:48:52Z")

</div>

Hi Nikolaus.

Do you mean you would like to display different pages of a GUI upon the selection of item from a drop-down menu? If so you would need to do something like this:

at the top of your code, define the following elements:

```
private JPanel pagesPanel;
private JComboBo<String> dropDown;
private CardLayout pages;

```

the JPanel `pagesPanel` will hold your different pages, and the JComboBox is the drop down meanu that will control which page is shown.

In `buildUI()` defeine your JComboBox however you wish, for more info see [this tutorial](https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html).  
Also set the layout of `pagesPanel` to `pages`, and add both `pagesPanel` and `dropDown` to the panel passed as an argument in `buildUI()`. and add as many new `JPanel`s as you need to `pagesPanel` _these_ will be your different “pages”.

add to your `JComboBox` an `actionListener`, which changes the `pages`, and _here_ put your switch case statement/series of if statements, based on `dropDown.getSelectedIndex()` to control which page the `CardLayout` should make visible.  
For how to use CardLayout see [this tutorial](https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html)

Hope this helps.  
Sam
