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-absolutelayout.asciidoc 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. ---
  2. title: AbsoluteLayout
  3. order: 11
  4. layout: page
  5. ---
  6. [[layout.absolutelayout]]
  7. = AbsoluteLayout
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/layout/absolute-layout"]
  11. endif::web[]
  12. [classname]#AbsoluteLayout# allows placing components in arbitrary positions in
  13. the layout area. The positions are specified in the [methodname]#addComponent()#
  14. method with horizontal and vertical coordinates relative to an edge of the
  15. layout area. The positions can include a third depth dimension, the __z-index__,
  16. which specifies which components are displayed in front and which behind other
  17. components.
  18. The positions are specified by a CSS absolute position string, using the
  19. [literal]#++left++#, [literal]#++right++#, [literal]#++top++#,
  20. [literal]#++bottom++#, and [literal]#++z-index++# properties known from CSS. In
  21. the following example, we have a 300 by 150 pixels large layout and position a
  22. text field 50 pixels from both the left and the top edge:
  23. [source, java]
  24. ----
  25. // A 400x250 pixels size layout
  26. AbsoluteLayout layout = new AbsoluteLayout();
  27. layout.setWidth("400px");
  28. layout.setHeight("250px");
  29. // A component with coordinates for its top-left corner
  30. TextField text = new TextField("Somewhere someplace");
  31. layout.addComponent(text, "left: 50px; top: 50px;");
  32. ----
  33. The [literal]#++left++# and [literal]#++top++# specify the distance from the
  34. left and top edge, respectively. The [literal]#++right++# and
  35. [literal]#++bottom++# specify the distances from the right and top edge.
  36. [source, java]
  37. ----
  38. // At the top-left corner
  39. Button button = new Button( "left: 0px; top: 0px;");
  40. layout.addComponent(button, "left: 0px; top: 0px;");
  41. // At the bottom-right corner
  42. Button buttCorner = new Button( "right: 0px; bottom: 0px;");
  43. layout.addComponent(buttCorner, "right: 0px; bottom: 0px;");
  44. // Relative to the bottom-right corner
  45. Button buttBrRelative = new Button( "right: 50px; bottom: 50px;");
  46. layout.addComponent(buttBrRelative, "right: 50px; bottom: 50px;");
  47. // On the bottom, relative to the left side
  48. Button buttBottom = new Button( "left: 50px; bottom: 0px;");
  49. layout.addComponent(buttBottom, "left: 50px; bottom: 0px;");
  50. // On the right side, up from the bottom
  51. Button buttRight = new Button( "right: 0px; bottom: 100px;");
  52. layout.addComponent(buttRight, "right: 0px; bottom: 100px;");
  53. ----
  54. The result of the above code examples is shown in
  55. <<figure.layout.absolutelayout.bottomright>>.
  56. [[figure.layout.absolutelayout.bottomright]]
  57. .Components Positioned Relative to Various Edges
  58. image::img/absolutelayout-bottomright.png[width=60%, scaledwidth=80%]
  59. Drag and drop is very useful for moving the components contained in an
  60. [classname]#AbsoluteLayout#. Check out the example in
  61. <<dummy/../../../framework/advanced/advanced-dragndrop#advanced.dragndrop.drop-on-component,"Dropping
  62. on a Component">>.
  63. [[layout.absolutelayout.area]]
  64. == Placing a Component in an Area
  65. Earlier, we had components of undefined size and specified the positions of
  66. components by a single pair of coordinates. The other possibility is to specify
  67. an area and let the component fill the area by specifying a proportinal size for
  68. the component, such as " [literal]#++100%++#". Normally, you use
  69. [methodname]#setSizeFull()# to take the entire area given by the layout.
  70. [source, java]
  71. ----
  72. // Specify an area that a component should fill
  73. Panel panel = new Panel("A Panel filling an area");
  74. panel.setSizeFull(); // Fill the entire given area
  75. layout.addComponent(panel, "left: 25px; right: 50px; "+
  76. "top: 100px; bottom: 50px;");
  77. ----
  78. The result is shown in <<figure.layout.absolutelayout.area>>
  79. [[figure.layout.absolutelayout.area]]
  80. .Component Filling an Area Specified by Coordinates
  81. image::img/absolutelayout-area.png[width=50%, scaledwidth=80%]
  82. [[layout.absolutelayout.proportional]]
  83. == Proportional Coordinates
  84. You can also use proportional coordinates to specify the placement of
  85. components:
  86. [source, java]
  87. ----
  88. // A panel that takes 30% to 90% horizontally and
  89. // 20% to 80% vertically
  90. Panel panel = new Panel("A Panel");
  91. panel.setSizeFull(); // Fill the specified area
  92. layout.addComponent(panel, "left: 30%; right: 10%;" +
  93. "top: 20%; bottom: 20%;");
  94. ----
  95. The result is shown in <<figure.layout.absolutelayout.proportional>>
  96. [[figure.layout.absolutelayout.proportional]]
  97. .Specifying an Area by Proportional Coordinates
  98. image::img/absolutelayout-proportional.png[width=50%, scaledwidth=70%]
  99. [[layout.absolutelayout.css]]
  100. == Styling with CSS
  101. [source, css]
  102. ----
  103. .v-absolutelayout {}
  104. .v-absolutelayout-wrapper {}
  105. ----
  106. The [classname]#AbsoluteLayout# component has [literal]#++v-absolutelayout++#
  107. root style. Each component in the layout is contained within an element that has
  108. the [literal]#++v-absolutelayout-wrapper++#. The component captions are outside
  109. the wrapper elements, in a separate element with the usual
  110. [literal]#++v-caption++# style.