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.

layout-panel.asciidoc 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ---
  2. title: Panel
  3. order: 6
  4. layout: page
  5. ---
  6. [[layout.panel]]
  7. = Panel
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/structure/panel"]
  11. endif::web[]
  12. [classname]#Panel# is a single-component container with a frame around the
  13. content. It has an optional caption and an icon which are handled by the panel
  14. itself, not its containing layout. The panel itself does not manage the caption
  15. of its contained component. You need to set the content with
  16. [methodname]#setContent()#.
  17. [classname]#Panel# has 100% width and undefined height by default. This
  18. corresponds with the default sizing of [classname]#VerticalLayout#, which is
  19. perhaps most commonly used as the content of a [classname]#Panel#. If the width
  20. or height of a panel is undefined, the content must have a corresponding
  21. undefined or fixed size in the same direction to avoid a sizing paradox.
  22. [source, java]
  23. ----
  24. Panel panel = new Panel("Astronomer Panel");
  25. panel.addStyleName("mypanelexample");
  26. panel.setSizeUndefined(); // Shrink to fit content
  27. layout.addComponent(panel);
  28. // Create the content
  29. FormLayout content = new FormLayout();
  30. content.addStyleName("mypanelcontent");
  31. content.addComponent(new TextField("Participant"));
  32. content.addComponent(new TextField("Organization"));
  33. content.setSizeUndefined(); // Shrink to fit
  34. content.setMargin(true);
  35. panel.setContent(content);
  36. ----
  37. The resulting layout is shown in <<figure.layout.panel>>.
  38. [[figure.layout.panel]]
  39. .A [classname]#Panel#
  40. image::img/panel.png[width=50%, scaledwidth=70%]
  41. [[layout.panel.scrolling]]
  42. == Scrolling the Panel Content
  43. ((("scroll bars", id="term.layout.panel.scrolling.scrollbars", range="startofrange")))
  44. Normally, if a panel has undefined size in a direction, as it has by default
  45. vertically, it will fit the size of the content and grow as the content grows.
  46. However, if it has a fixed or percentual size and its content becomes too big to
  47. fit in the content area, a scroll bar will appear for the particular direction.
  48. Scroll bars in a [classname]#Panel# are handled natively by the browser with the
  49. [literal]#++overflow: auto++# property in CSS. (((overflow CSS
  50. property)))
  51. In the following example, we have a 300 pixels wide and very high
  52. [classname]#Image# component as the panel content.
  53. [source, java]
  54. ----
  55. // Display an image stored in theme
  56. Image image = new Image(null,
  57. new ThemeResource("img/Ripley_Scroll-300px.jpg"));
  58. // To enable scrollbars, the size of the panel content
  59. // must not be relative to the panel size
  60. image.setSizeUndefined(); // Actually the default
  61. // The panel will give it scrollbars.
  62. Panel panel = new Panel("Scroll");
  63. panel.setWidth("300px");
  64. panel.setHeight("300px");
  65. panel.setContent(image);
  66. layout.addComponent(panel);
  67. ----
  68. The result is shown in <<figure.layout.panel.scrolling>>. Notice that also the
  69. horizontal scrollbar has appeared even though the panel has the same width as
  70. the content (300 pixels) - the 300px width for the panel includes the panel
  71. border and vertical scrollbar.
  72. [[figure.layout.panel.scrolling]]
  73. .Panel with Scroll Bars
  74. image::img/panel-scrolling.png[width=50%, scaledwidth=70%]
  75. ((("[interfacename]#Scrollable#", id="term.layout.panel.scrolling.scrollable", range="startofrange")))
  76. [[layout.panel.scrolling.programmatic]]
  77. === Programmatic Scrolling
  78. [classname]#Panel# implements the [interfacename]#Scrollable# interface to allow
  79. programmatic scrolling. You can set the scroll position in pixels with
  80. [methodname]#setScrollTop()# and [methodname]#setScrollLeft()#. You can also get
  81. the scroll position set previously, but scrolling the panel in the browser does
  82. not update the scroll position to the server-side.
  83. (((range="endofrange", startref="term.layout.panel.scrolling.scrollable")))
  84. (((range="endofrange", startref="term.layout.panel.scrolling.scrollbars")))
  85. [[layout.panel.css]]
  86. == CSS Style Rules
  87. [source, css]
  88. ----
  89. .v-panel {}
  90. .v-panel-caption {}
  91. .v-panel-nocaption {}
  92. .v-panel-content {}
  93. .v-panel-deco {}
  94. ----
  95. The entire panel has [literal]#++v-panel++# style. A panel consists of three
  96. parts: the caption, content, and bottom decorations (shadow). These can be
  97. styled with [literal]#++v-panel-caption++#, [literal]#++v-panel-content++#, and
  98. [literal]#++v-panel-deco++#, respectively. If the panel has no caption, the
  99. caption element will have the style [literal]#++v-panel-nocaption++#.
  100. The built-in [literal]#++borderless++# style in the Valo theme has no
  101. borders or border decorations for the [classname]#Panel#. You can use the
  102. [parameter]#ValoTheme.PANEL_BORDERLESS# constant to
  103. add the style to a panel.