Form Object
The FormObject class has the following methods:
For a CardStack form object, returns the list of local cards.
For a CardStack form object, returns the local card with the specified name.
Returns the current value of a FormObject when applicable. The method is supported by the following types of FormObjects: input field, toggle button, checkbox, combo box, file import, array input, radio button, selection input, text, list box, table, slider, knob.
Most form objects have one or more of the properties listed in . A form object has a certain property if the corresponding setting is available in the Form Editor. Additional properties are supported for several types of form objects. The general properties that are supported and any additional properties for form objects are listed in the following sections.
Example Code
The following code loops over all buttons and disables them:
for (FormObject formObject : app.form("form1").formObject()) {
  if ("Button".equals(formObject.getType())) {
    formObject.set("enabled", false);
  }
}
The getType method retrieves the type of form object. In the above example the type of form object is Button and the statement "Button".equals(formObject.getType()) represents a string comparison between the output of the getType method and the string "Button".
For an example of using getValue, see Data Validation.
The following table lists all form object types that can be returned by getType:
Array Input
Example Code
app.form("form1").formObject("arrayinput1").set("enabled", false);
Button
In the Form Editor, if a button has its Size setting set to Large, it always displays its text property. If the button is Small, it either displays the icon or the text according to the following rule: if the icon property is empty, the text is displayed, if the icon property is not empty, the icon is displayed.
Example Code
app.form("form1").formObject("button1").set("enabled", false);
Card Stack
Example Code
app.form("form1").formObject("cardstack1").set("visible", false);
To access objects in a local card, either use shortcuts or use the form method:
app.form("form1").formObject("cardstack1").form("card1")
   .formObject("button1").set("enabled", false);
Checkbox
Example Code
app.form("form1").formObject("checkbox1").set("tooltip", "tooltip text");
Combo Box
Example Code
app.form("form1").formObject("combobox1").set("foreground", "blue");
Data Display
When set to superscript, exponents are displayed using superscript font. When set to E, exponents are displayed using the character E followed by the exponent value.
auto | scientific | decimal
When the value is scientific, numbers are always displayed using scientific notation. When the value is decimal, numbers are never displayed using scientific notation. When the value is auto, the notation depends on the size of the number.
true | false
Example Code
app.form("form1").formObject("datadisplay1")
   .setColor("background", 192, 192, 192);
Equation
Example Code
app.form("form1").formObject("equation1").set("visible", false);
File Import
Example Code
app.form("form1").formObject("fileimport1")
   .set("filetypes", new String[]{"ALL2DCAD"});
Form
A form used as a subform does not have any modifiable properties.
Form Collection
To modify the active pane, change the corresponding declaration variable.
Example Code
This line of code changes the font:
app.form("form1").formObject("collection1").set("font", "Arial");
The expanded state of sections in form collections can be controlled by:
app.form("form1").formObject("formcollection1").expanded("form2", false);
The expanded method is only supported by form collections which use sections. The first argument is the tag of the form which is represented by the section. The second argument determines if the sections should be expanded or collapsed.
Graphics
true | false
If true, data picking is enabled in the graphics form object.
ProbeFeature | GraphicsData
Example Code
This line of code displays plot group 5 (pg5) in the graphics object graphics1 in the form with the name Temperature:
app.form("Temperature").formObject("graphics1")
   .set("source", model.result("pg5"));
The following line of code using useGraphics is equivalent to the above example:
useGraphics(model.result("pg5"), "Temperature/graphics1");
Either method changes the source of the graphics form object and then plots the contents.
To clear the contents of a graphics object, use:
app.form("Temperature").formObject("graphics1")
   .set("source", (ModelEntity) null);
or equivalently
useGraphics(null, "Temperature/graphics1");
The code below displays the mesh in the model tree node mesh1 in the graphics object graphics1 contained in the card of a card stack:
app.form("mesh").formObject("cardstack1").form("card1")
   .formObject("graphics1").set("source", model.mesh("mesh1"));
The code below enables data picking for a graphics object and sets the data picking target to a domain point probe:
app.form("form1").formObject("graphics1").set("datapick", true);
app.form("form1").formObject("graphics1").set("datapicktarget",
    model.component("comp1").probe("pdom1"));
If a shortcut graphics1 has been created for the graphics object and a shortcut pdom1 has been created for the probe object, the above can be shortened to:
graphics1.set("datapick", true);
graphics1.set("datapicktarget", pdom1);
It is possible to change the color, top color, bottom color, and icon of a Graphics form object while the app is running. The syntax for changing these properties is the same as for other color and icon options.
The color properties are named background2d, topBackground, and bottomBackground. Each property can be set either by using a color name string (for example, blue, black) or by specifying RGB values in the range 0-255.
The icon property is named icon. Valid values are images defined in the Libraries > Images node in the application tree, or an empty string ("") to indicate no icon. The default icon is logo_graphics.png. The code below illustrates this:
app.form("form1").formObject("graphics1").set("background2d", "blue");
app.form("form1").formObject("graphics1").set("topBackground", "black");
app.form("form1").formObject("graphics1").set("bottomBackground", "red");
 
app.form("form1").formObject("graphics1").setColor("background2d", 230, 236, 232);
 
app.form("form1").formObject("graphics1").set("icon", "compute_32.png");
Hyperlink
The text to display on the HyperLink form object.
The URL to open when the HyperLink is activated.
Example Code
with (app.form("form1").formObject("hyperlink1"));
  set("text", "COMSOL");
  set("url", "www.comsol.com");
endwith();
Image
Example Code
app.form("form1").formObject("image1").set("icon", "compute.png");
Information Card Stack
Example Code
app.form("form1").formObject("infocard1").set("fontunderline", true);
Input Field
true | false
When set to superscript, exponents are displayed using superscript font. When set to E, exponents are displayed using the character E followed by the exponent value.
on | off
If the value is on, then numerical values in the input field are formatted according to the exponent, notation, and precision properties. When the user is editing the text in the input field, the formatting is temporarily disabled so that the original text can be edited.
auto | scientific | decimal
When the value is scientific, numbers are always displayed using scientific notation. When the value is decimal, numbers are never displayed using scientific notation. When the value is auto, the notation depends on the size of the number.
Example Code
app.form("form1").formObject("inputfield1").set("precision", 6);
Line
Example Code
app.form("form1").formObject("line1").set("text", "divider text");
app.form("form1").formObject("line1").set("thickness", 10);
app.form("form1").formObject("line1").set("linecolor", blue);
List Box
Example Code
app.form("form1").formObject("listbox1").set("foreground", "red");
To change the list box contents, modify the corresponding choice list:
app.declaration("choicelist1").appendListRow("new value", "new name");
Log
Example Code
app.form("form1").formObject("log1").set("fontsize", "20");
Message Log
Example Code
app.form("form1").formObject("messages1").set("background", "gray");
Progress Bar
To create and update progress information see Progress Methods.
Example Code
app.form("form1").formObject("progressbar1").set("visible", false);
Radio Button
To change the display name for a radio button, modify the value in the corresponding choice list.
For a choice list that is used by a radio button, it is not possible to change the value of any row, or to add or remove rows. Only the display name can be changed.
Example Code
app.form("form1").formObject("radiobutton1").set("fontitalic", true);
app.declaration("choicelist1").setDisplayName("new name", 0);
Results Table
To change the contents of the results table use the method useResultsTable or evaluateToResultsTable. See also GUI-Related Methods.
Example Code
app.form("form1").formObject("resultstable1").set("visible", true);
app.form("form1").formObject("resultstable1").set("source",
    model.result().table("tbl2"));
useResultsTable(model.result().table("tbl2"), "/form1/resultstable1");
Selection Input
true | false
The active property controls whether the Selection Input is active. Changing the property value selects or deselects the Activate Selection button in the Selection Input.
Example Code
app.form("form1").formObject("selectioninput1").set("graphics",     "graphics1");
Alternatively, if there are shortcuts sel1 and g1 to the selectioninput1 and graphics1 form objects:
sel1.set("graphics", g1);
To change the model selection, assuming sel1 is a shortcut to the selection input form object:
sel1.set("source", model.selection("sel2"));
Slider
The number of steps between the min and max values. The number of tick marks is one more than the number of steps.
The min value is allowed to be larger than the max value, in which case the slider behaves as if the values were swapped. The smallest value always corresponds to the left side of the slider.
Example Code
app.form("form1").formObject("slider1").set("min", 1);
app.form("form1").formObject("slider1").set("max", 12);
app.form("form1").formObject("slider1").set("steps", 11);
Knob
When set to superscript, exponents are displayed using superscript font. When set to E, exponents are displayed using the character E followed by the exponent value.
When knobradiusmanual has the value on, this is the value of the knob. The tick marks appear outside this radius.
on | off
When the value is off the radius is calculated automatically. When the value is on, the radius is given by the knobradius property.
true | false
When true this setting enables custom label formatting.
distance | vertical | circular
The kind of mouse movement to change the knob value. When set to distance, the distance the mouse is moved, either horizontally or vertically, controls the value. When set to vertical, only the vertical distance the mouse is moved controls the value. When set to circular, the value is changed using a circular motion.
auto | scientific | decimal
When the value is scientific, numbers are always displayed using scientific notation. When the value is decimal, numbers are never displayed using scientific notation. When the value is auto, the notation depends on the size of the number.
none | marks | markslabels | marksalllabels
To control whether the scale should have tick marks or labels. When set to none, the knob has no tick marks or labels. When set to marks, the knob has tick marks but no labels. When set to markslabels, the knob has tick marks and labels for the minimum and maximum values. When set to marksalllabels, the knob has ticks marks and all major ticks has a label.
The number of steps between the min and max values. The number of tick marks is one more than the number of steps.
Example Code
app.form("form1").formObject("knob1").set("min", 1);
app.form("form1").formObject("knob1").set("max", 12);
app.form("form1").formObject("knob1").set("steps", 11);
Spacer
A spacer object does not have any modifiable properties.
Table
To change the contents of the table, change the declaration variables or model entities the table is displaying.
Example Code
app.form("form1").formObject("table1").set("enabled", false);
Text
on | off
If the value is on, the text can be edited by the user of the application. If the value is off, the text can only be changed programmatically.
left | center | right
on | off
If the value is on, word wrapping is used to break lines that are too long to fit within the text area. If the value is off, long lines may not be completely visible.
Example Code
app.form("form1").formObject("text1").set("textalign", "center");
Text Label
Example Code
app.form("form1").formObject("textlabel1").set("text", "custom text");
Toggle Button
A button with size large always displays the text, a button with size small displays either the icon or the text. If the icon property is empty, the text is displayed. If the icon property is not empty, the icon is displayed.
Example Code
app.form("form1").formObject("togglebutton1").set("icon",     "about_information.png");
Toolbar
Example Code
app.form("form1").formObject("toolbar1").set("background", "gray");
Unit
Example Code
app.form("form1").formObject("unit1").set("visible", false);
Video
Example Code
app.form("form1").formObject("video1").set("visible", false);
Web Page
page | url | type | report
Example Code
app.form("form1").formObject("webpage1").set("type", "report");
app.form("form1").formObject("webpage1").set("report", "rpt1");
model.result().report("rpt1");
model.result().report("rpt1").run();