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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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[]
  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[]
  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
  93. Indicator and Message">>.
  94. The description is actually not plain text, but you can use HTML tags to format
  95. it. Such a rich text description can contain any HTML elements, including
  96. images.
  97. [source, java]
  98. ----
  99. button.setDescription(
  100. "<h2><img src=\"../VAADIN/themes/sampler/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[]
  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[]
  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
  159. $v-button-disabled-opacity
  160. In Valo theme, the opacity of disabled components is specified with the
  161. $v-disabled-opacity parameter
  162. ifdef::web[]
  163. , as described in
  164. <<dummy/../../../framework/themes/themes-valo#themes.valo.variables,"Common
  165. Settings">>
  166. endif::web[]
  167. .
  168. [[components.features.icon]]
  169. == Icon
  170. ((("icon property")))
  171. ((("Component interface", "icon")))
  172. An icon is an explanatory graphical label accompanying a user interface
  173. component, usually shown above, left of, or inside the component. Icon is
  174. closely related to caption (see <<components.features.caption>>) and is usually
  175. displayed horizontally before or after it, depending on the component and the
  176. containing layout.
  177. The icon of a component can be set with the [methodname]#setIcon()# method. The
  178. image is provided as a resource, perhaps most typically a
  179. [classname]#ThemeResource#.
  180. [source, java]
  181. ----
  182. // Component with an icon from a custom theme
  183. TextField name = new TextField("Name");
  184. name.setIcon(new ThemeResource("icons/user.png"));
  185. layout.addComponent(name);
  186. // Component with an icon from another theme ('runo')
  187. Button ok = new Button("OK");
  188. ok.setIcon(new ThemeResource("../runo/icons/16/ok.png"));
  189. layout.addComponent(ok);
  190. ----
  191. The icon of a component is, by default, managed and displayed by the layout
  192. component or component container in which the component is placed. For example,
  193. the [classname]#VerticalLayout# component shows the icons left-aligned above the
  194. contained components, while the [classname]#FormLayout# component shows the
  195. icons on the left side of the vertically laid components, with the icons and
  196. their associated components left-aligned in their own columns. The
  197. [classname]#CustomComponent# does not manage the icon of its composition root,
  198. so if the root component has an icon, it will not be rendered.
  199. [[figure.components.features.icon]]
  200. .Displaying an Icon from a Theme Resource.
  201. image::img/features-icon.png[]
  202. Some components, such as [classname]#Button# and [classname]#Panel#, manage the
  203. icon themselves and display it inside the component.
  204. In addition to image resources, you can use __font icons__, which are icons
  205. included in special fonts, but which are handled as special resources. See
  206. <<dummy/../../../framework/themes/themes-fonticon#themes.fonticon,"Font Icons">>
  207. for more details.
  208. === CSS Style Rules
  209. An icon will be rendered inside an HTML element that has the
  210. [literal]#++v-icon++# CSS style class. The containing layout may enclose an icon
  211. and a caption inside elements related to the caption, such as
  212. [literal]#++v-caption++#.
  213. [[components.features.locale]]
  214. == Locale
  215. ((("locale property", "in [classname]#Component#")))
  216. ((("Component interface", "locale")))
  217. The locale property defines the country and language used in a component. You
  218. can use the locale information in conjunction with an internationalization
  219. scheme to acquire localized resources. Some components, such as
  220. [classname]#DateField#, use the locale for component localization.
  221. You can set the locale of a component (or the application) with
  222. [methodname]#setLocale()# as follows:
  223. [source, java]
  224. ----
  225. // Component for which the locale is meaningful
  226. InlineDateField date = new InlineDateField("Datum");
  227. // German language specified with ISO 639-1 language
  228. // code and ISO 3166-1 alpha-2 country code.
  229. date.setLocale(new Locale("de", "DE"));
  230. date.setResolution(Resolution.DAY);
  231. layout.addComponent(date);
  232. ----
  233. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.features.locale.simple[on-line example, window="_blank"].
  234. The resulting date field is shown in
  235. <<figure.components.features.locale.simple>>.
  236. [[figure.components.features.locale.simple]]
  237. .Set Locale for [classname]#InlineDateField#
  238. image::img/features-locale-simple.png[]
  239. ifdef::web[]
  240. [[components.features.locale.get]]
  241. === Getting the Locale
  242. ((("[methodname]#getLocale()#")))
  243. You can get the locale of a component with [methodname]#getLocale()#. If the
  244. locale is undefined for a component, that is, not explicitly set, the locale of
  245. the parent component is used. If none of the parent components have a locale
  246. set, the locale of the UI is used, and if that is not set, the default system
  247. locale is set, as given by [methodname]#Locale.getDefault()#.
  248. The [methodname]#getLocale()# returns null if the component is not yet attached
  249. to the UI, which is usually the case in most constructors, so it is a bit
  250. awkward to use it for internationalization. You can get the locale in
  251. [methodname]#attach()#, as shown in the following example:
  252. [source, java]
  253. ----
  254. Button cancel = new Button() {
  255. @Override
  256. public void attach() {
  257. super.attach();
  258. ResourceBundle bundle = ResourceBundle.getBundle(
  259. MyAppCaptions.class.getName(), getLocale());
  260. setCaption(bundle.getString(MyAppCaptions.CancelKey));
  261. }
  262. };
  263. layout.addComponent(cancel);
  264. ----
  265. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.features.locale.get-attach[on-line example, window="_blank"].
  266. However, it is normally a better practice to use the locale of the current UI to
  267. get the localized resource right when the component is created.
  268. [source, java]
  269. ----
  270. // Captions are stored in MyAppCaptions resource bundle
  271. // and the UI object is known in this context.
  272. ResourceBundle bundle =
  273. ResourceBundle.getBundle(MyAppCaptions.class.getName(),
  274. UI.getCurrent().getLocale());
  275. // Get a localized resource from the bundle
  276. Button cancel =
  277. new Button(bundle.getString(MyAppCaptions.CancelKey));
  278. layout.addComponent(cancel);
  279. ----
  280. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.features.locale.get-ui[on-line example, window="_blank"].
  281. endif::web[]
  282. ifdef::web[]
  283. [[component.features.locale.selecting]]
  284. === Selecting a Locale
  285. A common task in many applications is selecting a locale. This is done in the
  286. following example with a [classname]#ComboBox#, which gets the available locales
  287. in Java.
  288. [source, java]
  289. ----
  290. // The locale in which we want to have the language
  291. // selection list
  292. Locale displayLocale = Locale.ENGLISH;
  293. // All known locales
  294. final Locale[] locales = Locale.getAvailableLocales();
  295. // Allow selecting a language. We are in a constructor of a
  296. // CustomComponent, so preselecting the current
  297. // language of the application can not be done before
  298. // this (and the selection) component are attached to
  299. // the application.
  300. final ComboBox select = new ComboBox("Select a language") {
  301. @Override
  302. public void attach() {
  303. super.attach();
  304. setValue(getLocale());
  305. }
  306. };
  307. for (int i=0; i<locales.length; i++) {
  308. select.addItem(locales[i]);
  309. select.setItemCaption(locales[i],
  310. locales[i].getDisplayName(displayLocale));
  311. // Automatically select the current locale
  312. if (locales[i].equals(getLocale()))
  313. select.setValue(locales[i]);
  314. }
  315. layout.addComponent(select);
  316. // Locale code of the selected locale
  317. final Label localeCode = new Label("");
  318. layout.addComponent(localeCode);
  319. // A date field which language the selection will change
  320. final InlineDateField date =
  321. new InlineDateField("Calendar in the selected language");
  322. date.setResolution(Resolution.DAY);
  323. layout.addComponent(date);
  324. // Handle language selection
  325. select.addValueChangeListener(new Property.ValueChangeListener() {
  326. public void valueChange(ValueChangeEvent event) {
  327. Locale locale = (Locale) select.getValue();
  328. date.setLocale(locale);
  329. localeCode.setValue("Locale code: " +
  330. locale.getLanguage() + "_" +
  331. locale.getCountry());
  332. }
  333. });
  334. select.setImmediate(true);
  335. ----
  336. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.features.locale.selection[on-line example, window="_blank"].
  337. The user interface is shown in <<figure.components.features.locale.selection>>.
  338. [[figure.components.features.locale.selection]]
  339. .Selecting a Locale
  340. image::img/features-locale-selection.png[]
  341. endif::web[]
  342. [[components.features.readonly]]
  343. == Read-Only
  344. ((("read-only property")))
  345. ((("Component interface", "read-only")))
  346. The property defines whether the value of a component can be changed. The
  347. property is mainly applicable to [classname]#Field# components, as they have a
  348. value that can be edited by the user.
  349. [source, java]
  350. ----
  351. TextField readwrite = new TextField("Read-Write");
  352. readwrite.setValue("You can change this");
  353. readwrite.setReadOnly(false); // The default
  354. layout.addComponent(readwrite);
  355. TextField readonly = new TextField("Read-Only");
  356. readonly.setValue("You can't touch this!");
  357. readonly.setReadOnly(true);
  358. layout.addComponent(readonly);
  359. ----
  360. The resulting read-only text field is shown in
  361. <<figure.components.features.readonly.simple>>.
  362. [[figure.components.features.readonly.simple]]
  363. .A Read-Only Component.
  364. image::img/features-readonly-simple.png[]
  365. Setting a layout or some other component container as read-only does not usually
  366. make the contained components read-only recursively. This is different from, for
  367. example, the disabled state, which is usually applied recursively.
  368. Notice that the value of a selection component is the selection, not its items.
  369. A read-only selection component doesn't therefore allow its selection to be
  370. changed, but other changes are possible. For example, if you have a read-only
  371. [classname]#Table# in editable mode, its contained fields and the underlying
  372. data model can still be edited, and the user could sort it or reorder the
  373. columns.
  374. Client-side state modifications will not be communicated to the server-side and,
  375. more importantly, server-side field components will not accept changes to the
  376. value of a read-only [classname]#Field# component. The latter is an important
  377. security feature, because a malicious user can not fabricate state changes in a
  378. read-only field. This is handled at the level of [classname]#AbstractField# in
  379. [methodname]#setValue()#, so you can not change the value programmatically
  380. either. Calling [methodname]#setValue()# on a read-only field results in
  381. [classname]#Property.ReadOnlyException#.
  382. Also notice that while the read-only status applies automatically to the
  383. property value of a field, it does not apply to other component variables. A
  384. read-only component can accept some other variable changes from the client-side
  385. and some of such changes could be acceptable, such as change in the scroll bar
  386. position of a [classname]#Table#. Custom widgets should check the read-only
  387. state for variables bound to business
  388. data.
  389. ////
  390. TODO: Note this also in the Advanced: Security section.
  391. Possibly also in the GWT chapter.
  392. ////
  393. === CSS Style Rules
  394. Setting a normally editable component to read-only state can change its
  395. appearance to disallow editing the value. In addition to CSS styling, also the
  396. HTML structure can change. For example, [classname]#TextField# loses the edit
  397. box and appears much like a [classname]#Label#.
  398. A read-only component will have the [literal]#++v-readonly++# style. The
  399. following CSS rule would make the text in all read-only [classname]#TextField#
  400. components appear in italic.
  401. [source, css]
  402. ----
  403. .v-textfield.v-readonly {
  404. font-style: italic;
  405. }
  406. ----
  407. [[components.features.stylename]]
  408. == Style Name
  409. ((("style name property")))
  410. ((("Component interface", "style name")))
  411. The __style name__ property defines one or more custom CSS style class names for
  412. the component. The [methodname]#getStyleName()# returns the current style names
  413. as a space-separated list. The [methodname]#setStyleName()# replaces all the
  414. styles with the given style name or a space-separated list of style names. You
  415. can also add and remove individual style names with [methodname]#addStylename()#
  416. and [methodname]#removeStyleName()#. A style name must be a valid CSS style
  417. name.
  418. [source, java]
  419. ----
  420. Label label = new Label("This text has a lot of style");
  421. label.addStyleName("mystyle");
  422. layout.addComponent(label);
  423. ----
  424. The style name will appear in the component's HTML element in two forms:
  425. literally as given and prefixed with the component-specific style name. For
  426. example, if you add a style name [literal]#++mystyle++# to a
  427. [classname]#Button#, the component would get both [literal]#++mystyle++# and
  428. [literal]#++v-button-mystyle++# styles. Neither form may conflict with built-in
  429. style names of Vaadin. For example, [literal]#++focus++# style would conflict
  430. with a built-in style of the same name, and an [literal]#++content++# style for
  431. a [classname]#Panel# component would conflict with the built-in
  432. [literal]#++v-panel-content++# style.
  433. The following CSS rule would apply the style to any component that has the
  434. [literal]#++mystyle++# style.
  435. [source, css]
  436. ----
  437. .mystyle {
  438. font-family: fantasy;
  439. font-style: italic;
  440. font-size: 25px;
  441. font-weight: bolder;
  442. line-height: 30px;
  443. }
  444. ----
  445. The resulting styled component is shown in
  446. <<figure.components.features.stylename>>
  447. [[figure.components.features.stylename]]
  448. .Component with a Custom Style
  449. image::img/features-stylename-simple.png[]
  450. [[components.features.visible]]
  451. == Visible
  452. ((("visible property")))
  453. ((("Component interface", "visible")))
  454. Components can be hidden by setting the __visible__ property to __false__. Also
  455. the caption, icon and any other component features are made hidden. Hidden
  456. components are not just invisible, but their content is not communicated to the
  457. browser at all. That is, they are not made invisible cosmetically with only CSS
  458. rules. This feature is important for security if you have components that
  459. contain security-critical information that must only be shown in specific
  460. application states.
  461. [source, java]
  462. ----
  463. TextField invisible = new TextField("No-see-um");
  464. invisible.setValue("You can't see this!");
  465. invisible.setVisible(false);
  466. layout.addComponent(invisible);
  467. ----
  468. The resulting invisible component is shown in
  469. <<figure.components.features.visible.simple>>.
  470. [[figure.components.features.visible.simple]]
  471. .An Invisible Component.
  472. image::img/features-visible-simple.png[]
  473. Beware that invisible beings can leave footprints. The containing layout cell
  474. that holds the invisible component will not go away, but will show in the layout
  475. as extra empty space. Also expand ratios work just like if the component was
  476. visible - it is the layout cell that expands, not the component.
  477. If you need to make a component only cosmetically invisible, you should use a
  478. custom theme to set it [literal]#++display: none++# style. This is mainly useful
  479. for some special components that have effects even when made invisible in CSS.
  480. If the hidden component has undefined size and is enclosed in a layout that also
  481. has undefined size, the containing layout will collapse when the component
  482. disappears. If you want to have the component keep its size, you have to make it
  483. invisible by setting all its font and other attributes to be transparent. In
  484. such cases, the invisible content of the component can be made visible easily in
  485. the browser.
  486. A component made invisible with the __visible__ property has no particular CSS
  487. style class to indicate that it is hidden. The element does exist though, but
  488. has [literal]#++display: none++# style, which overrides any CSS styling.
  489. [[components.features.sizeable]]
  490. == Sizing Components
  491. ((("[classname]#Sizeable# interface")))
  492. Vaadin components are sizeable; not in the sense that they were fairly large or
  493. that the number of the components and their features are sizeable, but in the
  494. sense that you can make them fairly large on the screen if you like, or small or
  495. whatever size.
  496. The [classname]#Sizeable# interface, shared by all components, provides a number
  497. of manipulation methods and constants for setting the height and width of a
  498. component in absolute or relative units, or for leaving the size undefined.
  499. The size of a component can be set with [methodname]#setWidth()# and
  500. [methodname]#setHeight()# methods. The methods take the size as a floating-point
  501. value. You need to give the unit of the measure as the second parameter for the
  502. above methods. The available units are listed in
  503. <<components.features.sizeable.units.table>> below.
  504. [source, java]
  505. ----
  506. mycomponent.setWidth(100, Sizeable.UNITS_PERCENTAGE);
  507. mycomponent.setWidth(400, Sizeable.UNITS_PIXELS);
  508. ----
  509. Alternatively, you can speficy the size as a string. The format of such a string
  510. must follow the HTML/CSS standards for specifying measures.
  511. [source, java]
  512. ----
  513. mycomponent.setWidth("100%");
  514. mycomponent.setHeight("400px");
  515. ----
  516. The " [literal]#++100%++#" percentage value makes the component take all
  517. available size in the particular direction (see the description of
  518. [parameter]#Sizeable.UNITS_PERCENTAGE# in the table below). You can also use the
  519. shorthand method [methodname]#setSizeFull()# to set the size to 100% in both
  520. directions.
  521. The size can be __undefined__ in either or both dimensions, which means that the
  522. component will take the minimum necessary space. Most components have undefined
  523. size by default, but some layouts have full size in horizontal direction. You
  524. can set the height or width as undefined with
  525. [parameter]#Sizeable.SIZE_UNDEFINED# parameter for [methodname]#setWidth()# and
  526. [methodname]#setHeight()#.
  527. You always need to keep in mind that __a layout with undefined size may not
  528. contain components with defined relative size__, such as "full size". See
  529. <<dummy/../../../framework/layout/layout-settings#layout.settings.size,"Layout
  530. Size">> for details.
  531. The <<components.features.sizeable.units.table>> lists the available units and
  532. their codes defined in the [classname]#Sizeable# interface.
  533. [[components.features.sizeable.units.table]]
  534. .Size Units
  535. |===============
  536. |[parameter]#Unit.PIXELS#|px|The__pixel__is the basic hardware-specific measure of one physical display pixel.
  537. |[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.
  538. |[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.
  539. |[parameter]#Unit.EM#|em|A unit relative to the used font, the width of the upper-case "M" letter.
  540. |[parameter]#Unit.EX#|ex|A unit relative to the used font, the height of the lower-case "x" letter.
  541. |[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.
  542. |[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.
  543. |[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.
  544. |[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.
  545. |===============
  546. If a component inside [classname]#HorizontalLayout# or
  547. [classname]#VerticalLayout# has full size in the namesake direction of the
  548. layout, the component will expand to take all available space not needed by the
  549. other components. See
  550. <<dummy/../../../framework/layout/layout-settings#layout.settings.size,"Layout
  551. Size">> for details.
  552. == Managing Input Focus
  553. When the user clicks on a component, the component gets the __input focus__,
  554. which is indicated by highlighting according to style definitions. If the
  555. component allows inputting text, the focus and insertion point are indicated by
  556. a cursor. Pressing the Tab key moves the focus to the component next in the
  557. __focus order__.
  558. Focusing is supported by all [classname]#Field# components and also by
  559. [classname]#Upload#.
  560. The focus order or __tab index__ of a component is defined as a positive integer
  561. value, which you can set with [methodname]#setTabIndex()# and get with
  562. [methodname]#getTabIndex()#. The tab index is managed in the context of the page
  563. in which the components are contained. The focus order can therefore jump
  564. between two any lower-level component containers, such as sub-windows or panels.
  565. The default focus order is determined by the natural hierarchical order of
  566. components in the order in which they were added under their parents. The
  567. default tab index is 0 (zero).
  568. Giving a negative integer as the tab index removes the component from the focus
  569. order entirely.
  570. === CSS Style Rules
  571. The component having the focus will have an additional style class with the
  572. [literal]#++-focus++# suffix. For example, a [classname]#TextField#, which
  573. normally has the [literal]#++v-textfield++# style, would additionally have the
  574. [literal]#++v-textfield-focus++# style.
  575. For example, the following would make a text field blue when it has focus.
  576. [source, css]
  577. ----
  578. .v-textfield-focus {
  579. background: lightblue;
  580. }
  581. ----