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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. ---
  2. title: HorizontalSplitPanel and VerticalSplitPanel
  3. order: 8
  4. layout: page
  5. ---
  6. [[layout.splitpanel]]
  7. = [classname]#HorizontalSplitPanel# and [classname]#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. [source, java]
  24. ----
  25. // Have a panel to put stuff in
  26. Panel panel = new Panel("Split Panels Inside This Panel");
  27. // Have a horizontal split panel as its content
  28. HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
  29. panel.setContent(hsplit);
  30. // Put a component in the left panel
  31. Tree tree = new Tree("Menu", TreeExample.createTreeContent());
  32. hsplit.setFirstComponent(tree);
  33. // Put a vertical split panel in the right panel
  34. VerticalSplitPanel vsplit = new VerticalSplitPanel();
  35. hsplit.setSecondComponent(vsplit);
  36. // Put other components in the right panel
  37. vsplit.addComponent(new Label("Here's the upper panel"));
  38. vsplit.addComponent(new Label("Here's the lower panel"));
  39. ----
  40. See the http://demo.vaadin.com/book-examples-vaadin7/book#layout.splitpanel.basic[on-line example, window="_blank"].
  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[]
  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. See the http://demo.vaadin.com/book-examples-vaadin7/book#layout.splitpanel.splitposition[on-line example, window="_blank"].
  62. Another version of the [methodname]#setSplitPosition()# method allows leaving
  63. out the unit, using the same unit as previously. The method also has versions
  64. take take a boolean parameter, [parameter]#reverse#, which allows defining the
  65. size of the right or bottom panel instead of the left or top panel.
  66. The split bar allows the user to adjust the split position by dragging the bar
  67. with mouse. To lock the split bar, use [methodname]#setLocked(true)#. When
  68. locked, the move handle in the middle of the bar is disabled.
  69. [source, java]
  70. ----
  71. // Lock the splitter
  72. hsplit.setLocked(true);
  73. ----
  74. See the http://demo.vaadin.com/book-examples-vaadin7/book#layout.splitpanel.splitposition[on-line example, window="_blank"].
  75. Setting the split position programmatically and locking the split bar is
  76. illustrated in <<figure.component.splitpanel.splitposition>>.
  77. [[figure.component.splitpanel.splitposition]]
  78. .A Layout With Nested SplitPanels
  79. image::img/splitpanel-splitposition.png[]
  80. Notice that the size of a split panel must not be undefined in the split
  81. direction.
  82. == CSS Style Rules
  83. [source, css]
  84. ----
  85. /* For a horizontal SplitPanel. */
  86. .v-splitpanel-horizontal {}
  87. .v-splitpanel-hsplitter {}
  88. .v-splitpanel-hsplitter-locked {}
  89. /* For a vertical SplitPanel. */
  90. .v-splitpanel-vertical {}
  91. .v-splitpanel-vsplitter {}
  92. .v-splitpanel-vsplitter-locked {}
  93. /* The two container panels. */
  94. .v-splitpanel-first-container {} /* Top or left panel. */
  95. .v-splitpanel-second-container {} /* Bottom or right panel. */
  96. ----
  97. The entire split panel has the style [literal]#++v-splitpanel-horizontal++# or
  98. [literal]#++v-splitpanel-vertical++#, depending on the panel direction. The
  99. split bar or __splitter__ between the two content panels has either the
  100. [literal]#++...-splitter++# or [literal]#++...-splitter-locked++# style,
  101. depending on whether its position is locked or not.
  102. (((range="endofrange", startref="term.layout.splitpanel.horizontal")))
  103. (((range="endofrange", startref="term.layout.splitpanel.vertical")))