You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

components-features.asciidoc 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. ---
  2. title: Common Component Features
  3. order: 3
  4. layout: page
  5. ---
  6. [[components.features]]
  7. = Common Component Features
  8. The component base classes and interfaces provide a large number of features.
  9. Let us look at some of the most commonly needed features. Features not
  10. documented here can be found from the Java API Reference.
  11. The interface defines a number of properties, which you can retrieve or
  12. manipulate with the corresponding setters and getters.
  13. [[components.features.caption]]
  14. == Caption
  15. ((("caption property")))
  16. ((("Component interface", "caption")))
  17. A caption is an explanatory textual label accompanying a user interface
  18. component, usually shown above, left of, or inside the component. The contents
  19. of a caption are automatically quoted, so no raw HTML can be rendered in a
  20. caption.
  21. The caption text can usually be given as the first parameter of a constructor of
  22. a component or with [methodname]#setCaption()#.
  23. [source, java]
  24. ----
  25. // New text field with caption "Name"
  26. TextField name = new TextField("Name");
  27. layout.addComponent(name);
  28. ----
  29. The caption of a component is, by default, managed and displayed by the layout
  30. component or component container inside which the component is placed. For
  31. example, the [classname]#VerticalLayout# component shows the captions
  32. left-aligned above the contained components, while the [classname]#FormLayout#
  33. component shows the captions on the left side of the vertically laid components,
  34. with the captions and their associated components left-aligned in their own
  35. columns. The [classname]#CustomComponent# does not manage the caption of its
  36. composition root, so if the root component has a caption, it will not be
  37. rendered.
  38. [[figure.components.features.caption.layoutmanaged]]
  39. .Caption Management by [classname]#VerticalLayout# and [classname]#FormLayout#.
  40. image::img/features-caption-layoutmanaged.png[width=50%,scaledwidth=65%]
  41. Some components, such as [classname]#Button# and [classname]#Panel#, manage the
  42. caption themselves and display it inside the component.
  43. Icon (see <<components.features.icon>>) is closely related to caption and is
  44. usually displayed horizontally before or after it, depending on the component
  45. and the containing layout. Also the required indicator in field components is
  46. usually shown before or after the caption.
  47. An alternative way to implement a caption is to use another component as the
  48. caption, typically a [classname]#Label#, a [classname]#TextField#, or a
  49. [classname]#Panel#. A [classname]#Label#, for example, allows highlighting a
  50. shortcut key with HTML markup or to bind the caption to a data source. The
  51. [classname]#Panel# provides an easy way to add both a caption and a border
  52. around a component.
  53. === CSS Style Rules
  54. [source, css]
  55. ----
  56. .v-caption {}
  57. .v-captiontext {}
  58. .v-caption-clearelem {}
  59. .v-required-field-indicator {}
  60. ----
  61. A caption is be rendered inside an HTML element that has the
  62. [literal]#++v-caption++# CSS style class. The containing layout may enclose a
  63. caption inside other caption-related elements.
  64. Some layouts put the caption text in a [literal]#++v-captiontext++# element. A
  65. [literal]#++v-caption-clearelem++# is used in some layouts to clear a CSS
  66. [literal]#++float++# property in captions. An optional required indicator in
  67. field components is contained in a separate element with
  68. [literal]#++v-required-field-indicator++# style.
  69. [[components.features.description]]
  70. == Description and Tooltips
  71. ((("description property")))
  72. ((("Component interface", "description")))
  73. ((("tooltips")))
  74. All components (that inherit [classname]#AbstractComponent#) have a description
  75. separate from their caption. The description is usually shown as a tooltip that
  76. appears when the mouse pointer hovers over the component for a short time.
  77. You can set the description with [methodname]#setDescription()# and retrieve
  78. with [methodname]#getDescription()#.
  79. [source, java]
  80. ----
  81. Button button = new Button("A Button");
  82. button.setDescription("This is the tooltip");
  83. ----
  84. The tooltip is shown in <<figure.components.tooltip.plain>>.
  85. [[figure.components.tooltip.plain]]
  86. .Component Description as a Tooltip
  87. image::img/tooltip-plain-withpointer-hi.png[width=30%, scaledwidth=100%]
  88. A description is rendered as a tooltip in most components.
  89. When a component error has been set with [methodname]#setComponentError()#, the
  90. error is usually also displayed in the tooltip, below the description.
  91. Components that are in error state will also display the error indicator. See
  92. <<dummy/../../../framework/application/application-errors#application.errors.error-indicator, "Error Indicator and Message">>.
  93. The description is actually not plain text, but you can use HTML tags to format
  94. it. Such a rich text description can contain any HTML elements, including
  95. images.
  96. [source, java]
  97. ----
  98. button.setDescription(
  99. "<h2><img src=\"../VAADIN/themes/sampler/"+
  100. "icons/comment_yellow.gif\"/>"+
  101. "A richtext tooltip</h2>"+
  102. "<ul>"+
  103. " <li>Use rich formatting with HTML</li>"+
  104. " <li>Include images from themes</li>"+
  105. " <li>etc.</li>"+
  106. "</ul>");
  107. ----
  108. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.features.description.richtext[on-line example, window="_blank"].
  109. The result is shown in <<figure.components.tooltip.richtext>>.
  110. [[figure.components.tooltip.richtext]]
  111. .A Rich Text Tooltip
  112. image::img/tooltip-richtext-withpointer-hi.png[width=40%, scaledwidth=75%]
  113. Notice that the setter and getter are defined for all fields in the
  114. [classname]#Field# interface, not for all components in the
  115. [classname]#Component# interface.
  116. [[components.features.enabled]]
  117. == Enabled
  118. ((("enabled property")))
  119. ((("Component interface", "enabled")))
  120. The __enabled__ property controls whether the user can actually use the
  121. component. A disabled component is visible, but grayed to indicate the disabled
  122. state.
  123. Components are always enabled by default. You can disable a component with
  124. [methodname]#setEnabled(false)#.
  125. [source, java]
  126. ----
  127. Button enabled = new Button("Enabled");
  128. enabled.setEnabled(true); // The default
  129. layout.addComponent(enabled);
  130. Button disabled = new Button("Disabled");
  131. disabled.setEnabled(false);
  132. layout.addComponent(disabled);
  133. ----
  134. <<figure.components.features.enabled.simple>> shows the enabled and disabled
  135. buttons.
  136. [[figure.components.features.enabled.simple]]
  137. .An Enabled and Disabled [classname]#Button#
  138. image::img/features-enabled-simple.png[width=30%, scaledwidth=50%]
  139. A disabled component is automatically put in read-only state. No client
  140. interaction with such a component is sent to the server and, as an important
  141. security feature, the server-side components do not receive state updates from
  142. the client in the read-only state. This feature exists in all built-in
  143. components in Vaadin and is automatically handled for all [classname]#Field#
  144. components for the field property value. For custom widgets, you need to make
  145. sure that the read-only state is checked on the server-side for all
  146. safety-critical variables.
  147. === CSS Style Rules
  148. Disabled components have the [literal]#++v-disabled++# CSS style in addition to
  149. the component-specific style. To match a component with both the styles, you
  150. have to join the style class names with a dot as done in the example below.
  151. [source, css]
  152. ----
  153. .v-textfield.v-disabled {
  154. border: dotted;
  155. }
  156. ----
  157. This would make the border of all disabled text fields dotted.
  158. // TODO This may change to $v-button-disabled-opacity
  159. In the Valo theme, the opacity of disabled components is specified with the
  160. `$v-disabled-opacity`
  161. ifndef::web[parameter.]
  162. ifdef::web[parameter, as described in <<dummy/../../../framework/themes/themes-valo#themes.valo.variables,"Common Settings">>]
  163. [[components.features.icon]]
  164. == Icon
  165. ((("icon property")))
  166. ((("Component interface", "icon")))
  167. An icon is an explanatory graphical label accompanying a user interface
  168. component, usually shown above, left of, or inside the component. Icon is
  169. closely related to caption (see <<components.features.caption>>) and is usually
  170. displayed horizontally before or after it, depending on the component and the
  171. containing layout.
  172. The icon of a component can be set with the [methodname]#setIcon()# method. The
  173. image is provided as a resource, perhaps most typically a
  174. [classname]#ThemeResource#.
  175. [source, java]
  176. ----
  177. // Component with an icon from a custom theme
  178. TextField name = new TextField("Name");
  179. name.setIcon(new ThemeResource("icons/user.png"));
  180. layout.addComponent(name);
  181. // Component with an icon from another theme ('runo')
  182. Button ok = new Button("OK");
  183. ok.setIcon(new ThemeResource("../runo/icons/16/ok.png"));
  184. layout.addComponent(ok);
  185. ----
  186. The icon of a component is, by default, managed and displayed by the layout
  187. component or component container in which the component is placed. For example,
  188. the [classname]#VerticalLayout# component shows the icons left-aligned above the
  189. contained components, while the [classname]#FormLayout# component shows the
  190. icons on the left side of the vertically laid components, with the icons and
  191. their associated components left-aligned in their own columns. The
  192. [classname]#CustomComponent# does not manage the icon of its composition root,
  193. so if the root component has an icon, it will not be rendered.
  194. [[figure.components.features.icon]]
  195. .Displaying an Icon from a Theme Resource.
  196. image::img/features-icon.png[width=40%, scaledwidth=60%]
  197. Some components, such as [classname]#Button# and [classname]#Panel#, manage the
  198. icon themselves and display it inside the component.
  199. In addition to image resources, you can use __font icons__, which are icons
  200. included in special fonts, but which are handled as special resources. See
  201. <<dummy/../../../framework/themes/themes-fonticon#themes.fonticon,"Font Icons">>
  202. for more details.
  203. === CSS Style Rules
  204. An icon will be rendered inside an HTML element that has the
  205. [literal]#++v-icon++# CSS style class. The containing layout may enclose an icon
  206. and a caption inside elements related to the caption, such as
  207. [literal]#++v-caption++#.
  208. [[components.features.locale]]
  209. == Locale
  210. ((("locale property", "in [classname]#Component#")))
  211. ((("Component interface", "locale")))
  212. The locale property defines the country and language used in a component. You
  213. can use the locale information in conjunction with an internationalization
  214. scheme to acquire localized resources. Some components, such as
  215. [classname]#DateField#, use the locale for component localization.
  216. You can set the locale of a component (or the application) with
  217. [methodname]#setLocale()# as follows:
  218. [source, java]
  219. ----
  220. // Component for which the locale is meaningful
  221. InlineDateField date = new InlineDateField("Datum");
  222. // German language specified with ISO 639-1 language
  223. // code and ISO 3166-1 alpha-2 country code.
  224. date.setLocale(new Locale("de", "DE"));
  225. date.setResolution(Resolution.DAY);
  226. layout.addComponent(date);
  227. ----
  228. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.features.locale.simple[on-line example, window="_blank"].
  229. The resulting date field is shown in <<figure.components.features.locale.simple>>.
  230. [[figure.components.features.locale.simple]]
  231. .Set locale for [classname]#InlineDateField#
  232. image::img/features-locale-simple.png[width=40%, scaledwidth=60%]
  233. ifdef::web[]
  234. [[components.features.locale.get]]
  235. === Getting the Locale
  236. ((("[methodname]#getLocale()#")))
  237. You can get the locale of a component with [methodname]#getLocale()#. If the
  238. locale is undefined for a component, that is, not explicitly set, the locale of
  239. the parent component is used. If none of the parent components have a locale
  240. set, the locale of the UI is used, and if that is not set, the default system
  241. locale is set, as given by [methodname]#Locale.getDefault()#.
  242. The [methodname]#getLocale()# returns null if the component is not yet attached
  243. to the UI, which is usually the case in most constructors, so it is a bit
  244. awkward to use it for internationalization. You can get the locale in
  245. [methodname]#attach()#, as shown in the following example:
  246. [source, java]
  247. ----
  248. Button cancel = new Button() {
  249. @Override
  250. public void attach() {
  251. super.attach();
  252. ResourceBundle bundle = ResourceBundle.getBundle(
  253. MyAppCaptions.class.getName(), getLocale());
  254. setCaption(bundle.getString(MyAppCaptions.CancelKey));
  255. }
  256. };
  257. layout.addComponent(cancel);
  258. ----
  259. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.features.locale.get-attach[on-line example, window="_blank"].
  260. However, it is normally a better practice to use the locale of the current UI to
  261. get the localized resource right when the component is created.
  262. [source, java]
  263. ----
  264. // Captions are stored in MyAppCaptions resource bundle
  265. // and the UI object is known in this context.
  266. ResourceBundle bundle =
  267. ResourceBundle.getBundle(MyAppCaptions.class.getName(),
  268. UI.getCurrent().getLocale());
  269. // Get a localized resource from the bundle
  270. Button cancel =
  271. new Button(bundle.getString(MyAppCaptions.CancelKey));
  272. layout.addComponent(cancel);
  273. ----
  274. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.features.locale.get-ui[on-line example, window="_blank"].
  275. endif::web[]
  276. ifdef::web[]
  277. [[component.features.locale.selecting]]
  278. === Selecting a Locale
  279. A common task in many applications is selecting a locale. This is done in the
  280. following example with a [classname]#ComboBox#, which gets the available locales
  281. in Java.
  282. [source, java]
  283. ----
  284. // The locale in which we want to have the language
  285. // selection list
  286. Locale displayLocale = Locale.ENGLISH;
  287. // All known locales
  288. final Locale[] locales = Locale.getAvailableLocales();
  289. // Allow selecting a language. We are in a constructor of a
  290. // CustomComponent, so preselecting the current
  291. // language of the application can not be done before
  292. // this (and the selection) component are attached to
  293. // the application.
  294. final ComboBox select = new ComboBox("Select a language") {
  295. @Override
  296. public void attach() {
  297. super.attach();
  298. setValue(getLocale());
  299. }
  300. };
  301. for (int i=0; i<locales.length; i++) {
  302. select.addItem(locales[i]);
  303. select.setItemCaption(locales[i],
  304. locales[i].getDisplayName(displayLocale));
  305. // Automatically select the current locale
  306. if (locales[i].equals(getLocale()))
  307. select.setValue(locales[i]);
  308. }
  309. layout.addComponent(select);
  310. // Locale code of the selected locale
  311. final Label localeCode = new Label("");
  312. layout.addComponent(localeCode);
  313. // A date field which language the selection will change
  314. final InlineDateField date =
  315. new InlineDateField("Calendar in the selected language");
  316. date.setResolution(Resolution.DAY);
  317. layout.addComponent(date);
  318. // Handle language selection
  319. select.addValueChangeListener(new Property.ValueChangeListener() {
  320. public void valueChange(ValueChangeEvent event) {
  321. Locale locale = (Locale) select.getValue();
  322. date.setLocale(locale);
  323. localeCode.setValue("Locale code: " +
  324. locale.getLanguage() + "_" +
  325. locale.getCountry());
  326. }
  327. });
  328. select.setImmediate(true);
  329. ----
  330. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.features.locale.selection[on-line example, window="_blank"].
  331. The user interface is shown in <<figure.components.features.locale.selection>>.
  332. [[figure.components.features.locale.selection]]
  333. .Selecting a locale
  334. image::img/features-locale-selection.png[]
  335. endif::web[]
  336. [[components.features.readonly]]
  337. == Read-Only
  338. ((("read-only property")))
  339. ((("Component interface", "read-only")))
  340. The property defines whether the value of a component can be changed. The
  341. property is mainly applicable to [classname]#Field# components, as they have a
  342. value that can be edited by the user.
  343. [source, java]
  344. ----
  345. TextField readwrite = new TextField("Read-Write");
  346. readwrite.setValue("You can change this");
  347. readwrite.setReadOnly(false); // The default
  348. layout.addComponent(readwrite);
  349. TextField readonly = new TextField("Read-Only");
  350. readonly.setValue("You can't touch this!");
  351. readonly.setReadOnly(true);
  352. layout.addComponent(readonly);
  353. ----
  354. The resulting read-only text field is shown in
  355. <<figure.components.features.readonly.simple>>.
  356. [[figure.components.features.readonly.simple]]
  357. .A read-only component
  358. image::img/features-readonly-simple.png[width=50%, scaledwidth=80%]
  359. Setting a layout or some other component container as read-only does not usually
  360. make the contained components read-only recursively. This is different from, for
  361. example, the disabled state, which is usually applied recursively.
  362. Notice that the value of a selection component is the selection, not its items.
  363. A read-only selection component doesn't therefore allow its selection to be
  364. changed, but other changes are possible. For example, if you have a read-only
  365. [classname]#Table# in editable mode, its contained fields and the underlying
  366. data model can still be edited, and the user could sort it or reorder the
  367. columns.
  368. Client-side state modifications will not be communicated to the server-side and,
  369. more importantly, server-side field components will not accept changes to the
  370. value of a read-only [classname]#Field# component. The latter is an important
  371. security feature, because a malicious user can not fabricate state changes in a
  372. read-only field. This is handled at the level of [classname]#AbstractField# in
  373. [methodname]#setValue()#, so you can not change the value programmatically
  374. either. Calling [methodname]#setValue()# on a read-only field results in
  375. [classname]#Property.ReadOnlyException#.
  376. Also notice that while the read-only status applies automatically to the
  377. property value of a field, it does not apply to other component variables. A
  378. read-only component can accept some other variable changes from the client-side
  379. and some of such changes could be acceptable, such as change in the scroll bar
  380. position of a [classname]#Table#. Custom widgets should check the read-only
  381. state for variables bound to business
  382. data.
  383. ////
  384. TODO: Note this also in the Advanced: Security section.
  385. Possibly also in the GWT chapter.
  386. ////
  387. === CSS Style Rules
  388. Setting a normally editable component to read-only state can change its
  389. appearance to disallow editing the value. In addition to CSS styling, also the
  390. HTML structure can change. For example, [classname]#TextField# loses the edit
  391. box and appears much like a [classname]#Label#.
  392. A read-only component will have the [literal]#++v-readonly++# style. The
  393. following CSS rule would make the text in all read-only [classname]#TextField#
  394. components appear in italic.
  395. [source, css]
  396. ----
  397. .v-textfield.v-readonly {
  398. font-style: italic;
  399. }
  400. ----
  401. [[components.features.stylename]]
  402. == Style Name
  403. ((("style name property")))
  404. ((("Component interface", "style name")))
  405. The __style name__ property defines one or more custom CSS style class names for
  406. the component. The [methodname]#getStyleName()# returns the current style names
  407. as a space-separated list. The [methodname]#setStyleName()# replaces all the
  408. styles with the given style name or a space-separated list of style names. You
  409. can also add and remove individual style names with [methodname]#addStylename()#
  410. and [methodname]#removeStyleName()#. A style name must be a valid CSS style
  411. name.
  412. [source, java]
  413. ----
  414. Label label = new Label("This text has a lot of style");
  415. label.addStyleName("mystyle");
  416. layout.addComponent(label);
  417. ----
  418. The style name will appear in the component's HTML element in two forms:
  419. literally as given and prefixed with the component-specific style name. For
  420. example, if you add a style name [literal]#++mystyle++# to a
  421. [classname]#Button#, the component would get both [literal]#++mystyle++# and
  422. [literal]#++v-button-mystyle++# styles. Neither form may conflict with built-in
  423. style names of Vaadin. For example, [literal]#++focus++# style would conflict
  424. with a built-in style of the same name, and an [literal]#++content++# style for
  425. a [classname]#Panel# component would conflict with the built-in
  426. [literal]#++v-panel-content++# style.
  427. The following CSS rule would apply the style to any component that has the
  428. [literal]#++mystyle++# style.
  429. [source, css]
  430. ----
  431. .mystyle {
  432. font-family: fantasy;
  433. font-style: italic;
  434. font-size: 25px;
  435. font-weight: bolder;
  436. line-height: 30px;
  437. }
  438. ----
  439. The resulting styled component is shown in <<figure.components.features.stylename>>
  440. [[figure.components.features.stylename]]
  441. .Component with a custom style
  442. image::img/features-stylename-simple.png[width=50%, scaledwidth=75%]
  443. [[components.features.visible]]
  444. == Visible
  445. ((("visible property")))
  446. ((("Component interface", "visible")))
  447. Components can be hidden by setting the __visible__ property to __false__. Also
  448. the caption, icon and any other component features are made hidden. Hidden
  449. components are not just invisible, but their content is not communicated to the
  450. browser at all. That is, they are not made invisible cosmetically with only CSS
  451. rules. This feature is important for security if you have components that
  452. contain security-critical information that must only be shown in specific
  453. application states.
  454. [source, java]
  455. ----
  456. TextField invisible = new TextField("No-see-um");
  457. invisible.setValue("You can't see this!");
  458. invisible.setVisible(false);
  459. layout.addComponent(invisible);
  460. ----
  461. The resulting invisible component is shown in
  462. <<figure.components.features.visible.simple>>.
  463. [[figure.components.features.visible.simple]]
  464. .An invisible component
  465. image::img/features-visible-simple.png[]
  466. Beware that invisible beings can leave footprints. The containing layout cell
  467. that holds the invisible component will not go away, but will show in the layout
  468. as extra empty space. Also expand ratios work just like if the component was
  469. visible - it is the layout cell that expands, not the component.
  470. If you need to make a component only cosmetically invisible, you should use a
  471. custom theme to set it [literal]#++display: none++# style. This is mainly useful
  472. for some special components that have effects even when made invisible in CSS.
  473. If the hidden component has undefined size and is enclosed in a layout that also
  474. has undefined size, the containing layout will collapse when the component
  475. disappears. If you want to have the component keep its size, you have to make it
  476. invisible by setting all its font and other attributes to be transparent. In
  477. such cases, the invisible content of the component can be made visible easily in
  478. the browser.
  479. A component made invisible with the __visible__ property has no particular CSS
  480. style class to indicate that it is hidden. The element does exist though, but
  481. has [literal]#++display: none++# style, which overrides any CSS styling.
  482. [[components.features.sizeable]]
  483. == Sizing Components
  484. ((("[classname]#Sizeable# interface")))
  485. Vaadin components are sizeable; not in the sense that they were fairly large or
  486. that the number of the components and their features are sizeable, but in the
  487. sense that you can make them fairly large on the screen if you like, or small or
  488. whatever size.
  489. The [classname]#Sizeable# interface, shared by all components, provides a number
  490. of manipulation methods and constants for setting the height and width of a
  491. component in absolute or relative units, or for leaving the size undefined.
  492. The size of a component can be set with [methodname]#setWidth()# and
  493. [methodname]#setHeight()# methods. The methods take the size as a floating-point
  494. value. You need to give the unit of the measure as the second parameter for the
  495. above methods. The available units are listed in
  496. <<components.features.sizeable.units.table>> below.
  497. [source, java]
  498. ----
  499. mycomponent.setWidth(100, Sizeable.UNITS_PERCENTAGE);
  500. mycomponent.setWidth(400, Sizeable.UNITS_PIXELS);
  501. ----
  502. Alternatively, you can speficy the size as a string. The format of such a string
  503. must follow the HTML/CSS standards for specifying measures.
  504. [source, java]
  505. ----
  506. mycomponent.setWidth("100%");
  507. mycomponent.setHeight("400px");
  508. ----
  509. The "[literal]#++100%++#" percentage value makes the component take all
  510. available size in the particular direction (see the description of
  511. [parameter]#Sizeable.UNITS_PERCENTAGE# in the table below). You can also use the
  512. shorthand method [methodname]#setSizeFull()# to set the size to 100% in both
  513. directions.
  514. The size can be __undefined__ in either or both dimensions, which means that the
  515. component will take the minimum necessary space. Most components have undefined
  516. size by default, but some layouts have full size in horizontal direction. You
  517. can set the height or width as undefined with
  518. [parameter]#Sizeable.SIZE_UNDEFINED# parameter for [methodname]#setWidth()# and
  519. [methodname]#setHeight()#.
  520. Always keep in mind that _a layout with undefined size may not contain components with defined relative size_, such as "full size", except in some special cases.
  521. See <<dummy/../../../framework/layout/layout-settings#layout.settings.size,"Layout Size">> for details.
  522. The <<components.features.sizeable.units.table>> table lists the available units and their codes defined in the [interfacename]#Sizeable# interface.
  523. [[components.features.sizeable.units.table]]
  524. .Size units
  525. [cols="5,2,10", options="header"]
  526. |===============
  527. |Constant|Unit|Description
  528. |[parameter]#Unit.PIXELS#|px|The _pixel_ is the basic hardware-specific measure of one physical display pixel.
  529. |[parameter]#Unit.POINTS#|pt|The _point_ is a typographical unit, which is usually defined as 1/72 inches or about 0.35 mm. However, on displays the size can vary significantly depending on display metrics.
  530. |[parameter]#Unit.PICAS#|pc|The _pica_ is a typographical unit, defined as 12 points, or 1/7 inches or about 4.233 mm. On displays, the size can vary depending on display metrics.
  531. |[parameter]#Unit.EM#|em|A unit relative to the used font, the width of the upper-case "M" letter.
  532. |[parameter]#Unit.EX#|ex|A unit relative to the used font, the height of the lower-case "x" letter.
  533. |[parameter]#Unit.MM#|mm|A physical length unit, millimeters on the surface of a display device. However, the actual size depends on the display, its metrics in the operating system, and the browser.
  534. |[parameter]#Unit.CM#|cm|A physical length unit, _centimeters_ on the surface of a display device. However, the actual size depends on the display, its metrics in the operating system, and the browser.
  535. |[parameter]#Unit.INCH#|in|A physical length unit, _inches_ on the surface of a display device. However, the actual size depends on the display, its metrics in the operating system, and the browser.
  536. |[parameter]#Unit.PERCENTAGE#|%|A relative percentage of the available size. For example, for the top-level layout [parameter]#100%# would be the full width or height of the browser window. The percentage value must be between 0 and 100.
  537. |===============
  538. If a component inside [classname]#HorizontalLayout# or [classname]#VerticalLayout# has full size in the namesake direction of the layout, the component will expand to take all available space not needed by the other components.
  539. See <<dummy/../../../framework/layout/layout-settings#layout.settings.size,"Layout Size">> for details.
  540. == Managing Input Focus
  541. When the user clicks on a component, the component gets the __input focus__,
  542. which is indicated by highlighting according to style definitions. If the
  543. component allows inputting text, the focus and insertion point are indicated by
  544. a cursor. Pressing the Tab key moves the focus to the component next in the
  545. __focus order__.
  546. Focusing is supported by all [classname]#Field# components and also by the [classname]#Upload# component.
  547. The focus order or __tab index__ of a component is defined as a positive integer
  548. value, which you can set with [methodname]#setTabIndex()# and get with
  549. [methodname]#getTabIndex()#. The tab index is managed in the context of the page
  550. in which the components are contained. The focus order can therefore jump
  551. between two any lower-level component containers, such as sub-windows or panels.
  552. The default focus order is determined by the natural hierarchical order of
  553. components in the order in which they were added under their parents. The
  554. default tab index is 0 (zero).
  555. Giving a negative integer as the tab index removes the component from the focus
  556. order entirely.
  557. === CSS Style Rules
  558. The component having the focus will have an additional style class with the
  559. [literal]#++-focus++# suffix. For example, a [classname]#TextField#, which
  560. normally has the [literal]#++v-textfield++# style, would additionally have the
  561. [literal]#++v-textfield-focus++# style.
  562. For example, the following would make a text field blue when it has focus.
  563. [source, css]
  564. ----
  565. .v-textfield-focus {
  566. background: lightblue;
  567. }
  568. ----