Tutorial: Using the standard components

In this tutorial you will learn how to use the recorders/replayers available for many of the Java Swing standard components, listed in the Basics tutorial.

Standard components

In the JUseCase release there are recorder/replayer objects for many of the standard components in Java Swing, such as JButton, JList, JTable etc. To set them up you have to supply a unique usecase command name, and if the given component type has many type of events you normally also have to specify which event to connect the command name to. When the event is detected, the command name and possibly some parameters will be recorded to the usecase script. Below is a description of the events you can record for the different components, and what parameters will be recorded if the event is detected.


The ScriptedButton will record/replay clicks on AbstractButtons, e.g. JButton and JMenuItem. The only event we're interested in here is the action event, so we don't have to specify an event in the setup. The following code will have "quit application" recorded to the script whenever the button is clicked.

AbstractButton quitButton = <...>; ScriptedButton.connect("quit application", quitButton);


This class is used for JComboBox selection events (item event). If the combo box is editable and the user types something in the text field, this will also be recorded as a selection event. The parameter for these events is the selected item, so the following code will record "select the following item: <some item>" when the combo box selection changes.

JComboBox comboBox = <...>; ScriptedComboBox.connect("select the following item:", comboBox);


The JFileChooser is a bit special since is a rather complex "component". It has tree interaction events that can be recorded/simulated - file selection, dialog accept and dialog cancel - and all of them have to have unique usecase command names. In the case of the file selection command, the selected file will be the parameter recorded to the usecase. The other events don't have any parameters.

JFileChooser fileChooser = <...>; String fileCmd = "select this file:"; String acceptCmd = "accept file selection dialog"; String cancelCmd = "cancel file selection dialog"; ScriptedFileChooser.connect(fileCmd, acceptCmd, cancelCmd, fileChooser);


JList is another component for which (currently) only one type of event is recordable - the item selection. The parameter recorded with this event is the selected item or the list of selected items (comma separated).

JList list = <...>; ScriptedList.connect("select the following item(s):", list);


There are two ways to set up recorders/simulators for JSlider change events. The basic one records the standard slider value - an integer in some specified range. The other one takes a list of strings and will instead record the corresponding string value.

JSlider slider = new JSlider(1,2); // will record "change to: 1" or "change to: 2" ScriptedSlider.connect("change to:", slider); String[] strings = {"one", "two"}; // will record "slide to: one" or "slide to: two" ScriptedSlider.connect("slide to:", slider, strings);


This class records tab flip events, and the parameter for such events is the title of the tab to flip to, or if it's empty, the index of the tab.

JTabbedPane tabs = <...>; ScriptedTabbedPane.connect("flip to:", tabs);


The JTable is the most complex standard component since you can do so much with it. It also has a quite complex event mechanism. Because of this, there are a couple of different ways to set up recorders/replayers for it.

// just to get shorter names int rowEvent = ScriptedTable.SELECT_ROW; int colEvent = ScriptedTable.SELECT_COLUMN; int editEvent = ScriptedTable.EDIT_CELL; int clickEvent = ScriptedTable.DOUBLE_CLICK_CELL; JTable table = <...>; // records "select row <row index>" ScriptedTable.connect("select row", table, rowEvent); // records "select column <title of column>" ScriptedTable.connect("select column", table, colEvent); // records "edit [<column title>] [<row index>] <new value> ScriptedTable.connect("edit", table, editEvent); // records "double-click <row index>" ScriptedTable.connect("double-click", table, clickEvent); // the title of a column with values that uniquely points out a row String index = "Item name"; // "select item <name of item>" ScriptedTable.connect("select item", table, rowEvent, index); // "set new value [<column title>] [<item name>] <new value> ScriptedTable.connect("set new value", table, editEvent, index); // records "double-click item <item name>" ScriptedTable.connect("double-click item", table, clickEvent, index);