aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main
diff options
context:
space:
mode:
authorLeif Åstrand <legioth@gmail.com>2017-02-08 19:05:31 +0200
committerGitHub <noreply@github.com>2017-02-08 19:05:31 +0200
commit5b4b93133d51d3c0ccf31d8ecb41505c7d2a45f9 (patch)
tree17da9e5fab387e0c3daaa4896b265b90838978ed /server/src/main
parentc09b84d89fb5d7f724e93a1934158e042759aafe (diff)
downloadvaadin-framework-5b4b93133d51d3c0ccf31d8ecb41505c7d2a45f9.tar.gz
vaadin-framework-5b4b93133d51d3c0ccf31d8ecb41505c7d2a45f9.zip
Add addComponentsAndExpand to horizontal and vertical layout (#8480)
Diffstat (limited to 'server/src/main')
-rw-r--r--server/src/main/java/com/vaadin/ui/HorizontalLayout.java22
-rw-r--r--server/src/main/java/com/vaadin/ui/VerticalLayout.java22
2 files changed, 44 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/ui/HorizontalLayout.java b/server/src/main/java/com/vaadin/ui/HorizontalLayout.java
index 07583c6712..ccee900ca1 100644
--- a/server/src/main/java/com/vaadin/ui/HorizontalLayout.java
+++ b/server/src/main/java/com/vaadin/ui/HorizontalLayout.java
@@ -60,4 +60,26 @@ public class HorizontalLayout extends AbstractOrderedLayout {
return (HorizontalLayoutState) super.getState(markAsDirty);
}
+ /**
+ * Adds the given components to this layout and sets them as expanded. The
+ * width of all added child components are set to 100% so that the expansion
+ * will be effective. The width of this layout is also set to 100% if it is
+ * currently undefined.
+ *
+ * @param components
+ * the components to set, not <code>null</code>
+ */
+ public void addComponentsAndExpand(Component... components) {
+ addComponents(components);
+
+ if (getWidth() < 0) {
+ setWidth(100, Unit.PERCENTAGE);
+ }
+
+ for (Component child : components) {
+ child.setWidth(100, Unit.PERCENTAGE);
+ setExpandRatio(child, 1);
+ }
+ }
+
}
diff --git a/server/src/main/java/com/vaadin/ui/VerticalLayout.java b/server/src/main/java/com/vaadin/ui/VerticalLayout.java
index d441e8a664..5d8bda3b4c 100644
--- a/server/src/main/java/com/vaadin/ui/VerticalLayout.java
+++ b/server/src/main/java/com/vaadin/ui/VerticalLayout.java
@@ -62,4 +62,26 @@ public class VerticalLayout extends AbstractOrderedLayout {
protected VerticalLayoutState getState(boolean markAsDirty) {
return (VerticalLayoutState) super.getState(markAsDirty);
}
+
+ /**
+ * Adds the given components to this layout and sets them as expanded. The
+ * height of all added child components are set to 100% so that the
+ * expansion will be effective. The height of this layout is also set to
+ * 100% if it is currently undefined.
+ *
+ * @param components
+ * the components to set, not <code>null</code>
+ */
+ public void addComponentsAndExpand(Component... components) {
+ addComponents(components);
+
+ if (getHeight() < 0) {
+ setHeight(100, Unit.PERCENTAGE);
+ }
+
+ for (Component child : components) {
+ child.setHeight(100, Unit.PERCENTAGE);
+ setExpandRatio(child, 1);
+ }
+ }
}