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-splitpanel.asciidoc 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. ---
  2. title: HorizontalSplitPanel and VerticalSplitPanel
  3. order: 8
  4. layout: page
  5. ---
  6. [[layout.splitpanel]]
  7. = HorizontalSplitPanel and VerticalSplitPanel
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/structure/"]
  11. endif::web[]
  12. ((("[classname]#HorizontalSplitPanel#", id="term.layout.splitpanel.horizontal", range="startofrange")))
  13. ((("[classname]#VerticalSplitPanel#", id="term.layout.splitpanel.vertical", range="startofrange")))
  14. [classname]#HorizontalSplitPanel# and [classname]#VerticalSplitPanel# are a
  15. two-component containers that divide the available space into two areas to
  16. accomodate the two components. [classname]#HorizontalSplitPanel# makes the split
  17. horizontally with a vertical splitter bar, and [classname]#VerticalSplitPanel#
  18. vertically with a horizontal splitter bar. The user can drag the bar to adjust
  19. its position.
  20. You can set the two components with the [methodname]#setFirstComponent()# and
  21. [methodname]#setSecondComponent()# methods, or with the regular
  22. [methodname]#addComponent()# method.
  23. // TODO replace Tree with something else in the example code and screenshot
  24. [source, java]
  25. ----
  26. // Have a panel to put stuff in
  27. Panel panel = new Panel("Split Panels Inside This Panel");
  28. // Have a horizontal split panel as its content
  29. HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
  30. panel.setContent(hsplit);
  31. // Put a component in the left panel
  32. Tree tree = new Tree("Menu", TreeExample.createTreeContent());
  33. hsplit.setFirstComponent(tree);
  34. // Put a vertical split panel in the right panel
  35. VerticalSplitPanel vsplit = new VerticalSplitPanel();
  36. hsplit.setSecondComponent(vsplit);
  37. // Put other components in the right panel
  38. vsplit.addComponent(new Label("Here's the upper panel"));
  39. vsplit.addComponent(new Label("Here's the lower panel"));
  40. ----
  41. The result is shown in <<figure.splitpanel.basic>>. Observe that the tree is cut
  42. horizontally as it can not fit in the layout. If its height exceeds the height
  43. of the panel, a vertical scroll bar will appear automatically. If horizontal
  44. scroll bar is necessary, you could put the content in a [classname]#Panel#,
  45. which can have scroll bars in both directions.
  46. [[figure.splitpanel.basic]]
  47. .[classname]#HorizontalSplitPanel# and [classname]#VerticalSplitPanel#
  48. image::img/splitpanel-example1.png[width=60%, scaledwidth=80%]
  49. You can set the split position with [methodname]#setSplitPosition()#. It accepts
  50. any units defined in the [classname]#Sizeable# interface, with percentual size
  51. relative to the size of the component.
  52. [source, java]
  53. ----
  54. // Have a horizontal split panel
  55. HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
  56. hsplit.setFirstComponent(new Label("75% wide panel"));
  57. hsplit.setSecondComponent(new Label("25% wide panel"));
  58. // Set the position of the splitter as percentage
  59. hsplit.setSplitPosition(75, Sizeable.UNITS_PERCENTAGE);
  60. ----
  61. Another version of the [methodname]#setSplitPosition()# method allows leaving
  62. out the unit, using the same unit as previously. The method also has versions
  63. take take a boolean parameter, [parameter]#reverse#, which allows defining the
  64. size of the right or bottom panel instead of the left or top panel.
  65. The split bar allows the user to adjust the split position by dragging the bar
  66. with mouse. To lock the split bar, use [methodname]#setLocked(true)#. When
  67. locked, the move handle in the middle of the bar is disabled.
  68. [source, java]
  69. ----
  70. // Lock the splitter
  71. hsplit.setLocked(true);
  72. ----
  73. Setting the split position programmatically and locking the split bar is
  74. illustrated in <<figure.component.splitpanel.splitposition>>.
  75. [[figure.component.splitpanel.splitposition]]
  76. .A Layout With Nested SplitPanels
  77. image::img/splitpanel-splitposition.png[width=50%, scaledwidth=70%]
  78. Notice that the size of a split panel must not be undefined in the split
  79. direction.
  80. == CSS Style Rules
  81. [source, css]
  82. ----
  83. /* For a horizontal SplitPanel. */
  84. .v-splitpanel-horizontal {}
  85. .v-splitpanel-hsplitter {}
  86. .v-splitpanel-hsplitter-locked {}
  87. /* For a vertical SplitPanel. */
  88. .v-splitpanel-vertical {}
  89. .v-splitpanel-vsplitter {}
  90. .v-splitpanel-vsplitter-locked {}
  91. /* The two container panels. */
  92. .v-splitpanel-first-container {} /* Top or left panel. */
  93. .v-splitpanel-second-container {} /* Bottom or right panel. */
  94. ----
  95. The entire split panel has the style [literal]#++v-splitpanel-horizontal++# or
  96. [literal]#++v-splitpanel-vertical++#, depending on the panel direction. The
  97. split bar or __splitter__ between the two content panels has either the
  98. [literal]#++...-splitter++# or [literal]#++...-splitter-locked++# style,
  99. depending on whether its position is locked or not.
  100. (((range="endofrange", startref="term.layout.splitpanel.horizontal")))
  101. (((range="endofrange", startref="term.layout.splitpanel.vertical")))