Button
The Button () form object represents a push button. When a user presses the button, the program runs a list of commands.
Enter the name of the Button object in the Name field.
In the Text field, enter the text that appears on the button.
To add an icon (image) to appear on the button, specify an image file to use from the Icon list, which includes all images in the Images library, or click the Add Image to Library and Use Here button () to locate an image to use on the file system. That image then becomes a part of the Images library and selected as the icon to use on the button. The icon replaces the text on the button if the button’s size is normal. For large buttons, both the text and the icon appear, unless they are empty. To display only the text, select None from the Icon list. Click the Export button () to export the image to the file system (for use in another application, for example).
From the Size list, choose Large for a large square button or Small (the default).
If you have selected Large from the Size list, a Style list appears where you can choose Flat (the default) or Raised. The Flat style has no border and, as the default, a transparent button background. This look appears on Windows and in the web client. On macOS and Linux, the Flat and Raised styles look the same.
The text you enter in the Tooltip field becomes the tooltip of the button.
You can also define a shortcut for the button action that you enter in the Keyboard shortcut field. To add a keyboard shortcut, make the Keyboard shortcut field active, and then type a keyboard shortcut on the keyboard:
You must use a modifier in the keyboard shortcut, not just a plain letter (for example, CTRL+SHIFT+D). The shortcut can include the Ctrl key (CTRL), Alt key (ALT), and Shift key (SHIFT). Note that the Ctrl key is interpreted as Command on OS X. Avoid using the following keys in your shortcut:
In addition, the Settings window contains the following sections.
Choose Commands to Run
This section contains a tree with a filtered view of the trees in the Application Builder and Model Builder windows. The nodes either support a command or have children that do. When you select a node that supports one or more commands, the corresponding command toolbar buttons become enabled in the toolbar below the tree. You can also right-click a node to get a list of available commands for that particular node. Once you click a command with a node selected (or press Enter or double-click to add a command with its default command such as Run, Plot, or Set Value), the command and node appear in the last row of the table below the tree. This table contains all nodes that run. You can delete and move commands using the toolbar below the table.
In the Model branch, all nodes that represent some sort of data value, such as a parameter under the Parameters node, support the Set Value command. When adding a Set Value command to the table, the third column, Arguments, becomes enabled. In this column, you type the value to set. For data that represents arrays, use curly braces and commas to enter the array elements. For example, enter {1, 2, 3} to set a three-element array with the values 1, 2, and 3. See The Array 1D String Node for more details on how to enter arrays and matrices. For nodes that represent a file import, such as a Filename node under an Interpolation function node, an Import File command is available. You can also add a Plot command for all View nodes and plots, providing the name of a Graphics object as the argument. For nodes under Export, you can add a Run command. In the case of an Animation node under Export, where the animation is done using a player as the target, you can provide the name of a Graphics object as the argument.
The tree includes a number of branches from the application tree in addition to the Model branch:
The Forms branch: Form nodes support the commands Show, which sets the form as the main form of the application (that is, the content of the application window will be this form), and Show as Dialog, which brings up the form as a separate dialog window.
The GUI Commands branch: The commands under this branch are grouped in three subcategories:
-
File Commands: These include Save Application (to save the application under its current name); Save Application As (to open a file browser dialog allowing the user to save the application in a suitable location); Save Application on Server; Save Application on Server As; Open File (to open an application file resource specified using a valid URI path in the Arguments column); Save File As (similarly, to allow the user to save the file under a name specified in the Arguments column); and Exit Application (to close the running application). If the application is run on COMSOL Server, the Save Application on Server and Save Application on Server As commands save the current state as a new application in the COMSOL Server Application Library.
-
Graphics Commands: Here you find the commands Zoom Extents, Zoom to Selection, Reset Current View, Scene Light, Environment Reflections, Show Skybox, Rotate Environment, Transparency, Print, Select All, Clear Selection, Show Selection Colors, and Show Material Color and Texture. For all graphics commands, add the name of the Graphics object that you want to apply the command to as an argument.
-
Model Commands: Here you find the commands Clear All Solutions and Clear All Meshes.
Double-click or right-click any of the nodes above to add a Run command.
The Declarations branch: This branch contains any variable declarations you have added under the Application Builder window’s Declarations branch grouped by type. Like parameters, they support the Set Value command.
The Form Declarations branch: This branch contains any variable declarations you have added under a Declarations branch under the current Form node. Like parameters, they support the Set Value command.
The Methods branch: Method nodes support the Run command.
The Form Methods branch: Method nodes under the current Form node support the Run command.
The Libraries branch: Under Sounds, you can choose between sound files to play in a command sequence.
When you click one of the buttons underneath the tree, the currently selected command appears in the Command column in the table below. There is also an Icon column and an Arguments column, where you can enter any applicable arguments that the command uses.
Click the Convert to Method toolbar button () and choose Convert to Method, Convert to Form Method, or Convert to Local Method to convert the entire list of commands in the table to a global, form, or local method that contains the equivalent code. After this operation, the list of commands only contains a single Run operation on the created method. You can also Ctrl+Alt-click the button object or right-click it to create a local method or (by choosing Edit Method, Edit Methods, or Edit Local Method) to open the methods associated with the commands. When you select a method under Command, or there is exactly one method in the list, you can go to the editor window for that method by clicking the Go to Method button (). For information about the Edit Argument button (), see Editing Initial Values and Arguments in Declarations and Command Sequences. Use the Move Up (), Move Down (), and Delete () toolbar buttons to organize and remove commands from the list (and also remove the local method, if deleted).
Dialog Actions
When you use the button in a dialog window, the button can control the dialog. Select the Close dialog check box to close the dialog window when the user clicks the button. All forms and form objects in a dialog window store their values temporarily. This is because the user might want to cancel the dialog window and close it without storing any data to the real data backing the forms and form objects. Select the Store changes check box to store the data when the user clicks the button.
Position And Size
This section contains all of the layout settings for a button in the grid of the parent form.
In the grid mode, you can control the horizontal and vertical alignment of the button using the following lists:
From the Horizontal alignment list, choose Left, Center, Right, or Fill, which automatically expands the form object to fill the cell in the horizontal or vertical direction (where applicable).
From the Vertical alignment list, choose Middle, Top, Bottom, or Fill, which automatically expands the form object to fill the cell in the horizontal or vertical direction (where applicable).
The need to specify the alignment is most obvious when working in the grid mode, as it controls how the form object is aligned in its grid cell. Aligning the form object can be useful in the sketch mode too, and you can then use the alignment tools on the Arrange menu in the Form toolbar’s Sketch section. When running the application in any client other than the Windows client, the form objects may not be positioned exactly as seen in the Application Builder. This is because the form objects may have a different size in other clients, giving them a slightly different positioning. Specifying the alignment ensures that the form objects are aligned as you want them to be in all clients.
If you want to specify the width of the button, first select Manual from the Width list. Then enter the width (in points) in the associated field. If you have chosen Fill from the Horizontal alignment list, you can instead specify a Minimum width. Choose Automatic to compute the minimum width automatically (typically, this means a minimum size of 0), or choose Manual to specify a minimum width in the text field underneath.
If you want to specify the height of the button, first select Manual from the Height list. Then enter the height (in points) in the associated field. If you have chosen Fill from the Vertical alignment list, you can instead specify a Minimum height. Choose Automatic to compute the minimum height automatically (typically this means a minimum size of 0) or choose Manual to specify a minimum height in the text field underneath.
Additionally, in the sketch mode, you can specify the absolute position of the button using the Position x and Position y fields. In the grid mode, you can position the object in the grid and see the grid position as the Row, Column, Row span, and Column span values.
Cell Margin
Under Cell margin (in grid mode only), you can control the margins around the form object. By default, the margins are taken from the parent form. From the Cell margin list, choose:
None, for no margin around the form object
From parent form (the default), to use the margins set for the parent form
Custom, to specify the margins for the form object in the Horizontal and Vertical text fields
Appearance
In this section, you can control the appearance of the text on the button:
From the Text color list, select a color to use for the text: Inherit (the default; the form object then uses the setting from the Form it is located in), any of the predefined basic colors, or Custom, which makes it possible to select a custom color from a color palette.
From the Background color list, select a color to use as the background color for the button: Choose Default (the platform then controls the background color), Transparent, any available color, or Custom, to choose the color from a color palette.
The font and the font size for the button label use the font settings from the Forms node by default. Select a font from the Font list: Default font or any of the available fonts. If needed, choose or enter a font size (in points) in the Font size combo box. The default is to use the Default size for the font.
Select the Bold check box to use a boldface font and the Italic check box to use italics (an italic font).
Under State, you can control the initial state of the button when users run the application. By default, the button is visible and enabled. Clear the Visible or Enabled check box if you want to make the initial state so that the button is hidden or unavailable. You can then make it visible or enable it using a method. In the Form Editor, the state of the form object is indicated by a change in its appearance. Objects that are hidden become visible when selected in the Form Editor.