選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

HorizontalLayout.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.ui;
  17. import com.vaadin.shared.ui.orderedlayout.HorizontalLayoutState;
  18. /**
  19. * Horizontal layout
  20. *
  21. * <code>HorizontalLayout</code> is a component container, which shows the
  22. * subcomponents in the order of their addition (horizontally).
  23. *
  24. * @author Vaadin Ltd.
  25. * @since 5.3
  26. */
  27. @SuppressWarnings("serial")
  28. public class HorizontalLayout extends AbstractOrderedLayout {
  29. /**
  30. * Constructs an empty HorizontalLayout.
  31. */
  32. public HorizontalLayout() {
  33. setSpacing(true);
  34. }
  35. /**
  36. * Constructs a HorizontalLayout with the given components. The components
  37. * are added in the given order.
  38. *
  39. * @see AbstractOrderedLayout#addComponents(Component...)
  40. *
  41. * @param children
  42. * The components to add.
  43. */
  44. public HorizontalLayout(Component... children) {
  45. this();
  46. addComponents(children);
  47. }
  48. @Override
  49. protected HorizontalLayoutState getState() {
  50. return (HorizontalLayoutState) super.getState();
  51. }
  52. @Override
  53. protected HorizontalLayoutState getState(boolean markAsDirty) {
  54. return (HorizontalLayoutState) super.getState(markAsDirty);
  55. }
  56. /**
  57. * Adds the given components to this layout and sets them as expanded. The
  58. * width of all added child components are set to 100% so that the expansion
  59. * will be effective. The width of this layout is also set to 100% if it is
  60. * currently undefined.
  61. * <p>
  62. * The components are added in the provided order to the end of this layout.
  63. * Any components that are already children of this layout will be moved to
  64. * new positions.
  65. *
  66. * @param components
  67. * the components to set, not <code>null</code>
  68. * @since 8.0
  69. */
  70. public void addComponentsAndExpand(Component... components) {
  71. addComponents(components);
  72. if (getWidth() < 0) {
  73. setWidth(100, Unit.PERCENTAGE);
  74. }
  75. for (Component child : components) {
  76. child.setWidth(100, Unit.PERCENTAGE);
  77. setExpandRatio(child, 1);
  78. }
  79. }
  80. }