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.
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;
pagesPanel will hold your different pages, and the JComboBox is the drop down meanu that will control which page is shown.
buildUI() defeine your JComboBox however you wish, for more info see this tutorial.
Also set the layout of
pages, and add both
dropDown to the panel passed as an argument in
buildUI(). and add as many new
JPanels as you need to
pagesPanel these will be your different “pages”.
add to your
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
Hope this helps.