From a48e5a1cb8f6c8ae18af19406d3e7ba3c9886c69 Mon Sep 17 00:00:00 2001 From: Artur Date: Wed, 26 Apr 2017 11:12:01 +0300 Subject: Add an option for defining number of visible items in a NativeSelect (#9109) --- .../src/main/java/com/vaadin/ui/NativeSelect.java | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'server/src') diff --git a/server/src/main/java/com/vaadin/ui/NativeSelect.java b/server/src/main/java/com/vaadin/ui/NativeSelect.java index 4d08aacd12..a0d5741262 100644 --- a/server/src/main/java/com/vaadin/ui/NativeSelect.java +++ b/server/src/main/java/com/vaadin/ui/NativeSelect.java @@ -203,4 +203,33 @@ public class NativeSelect extends AbstractSingleSelect Objects.nonNull(caption); getState().emptySelectionCaption = caption; } + + /** + * Sets the number of items that are visible. If only one item is visible, + * then the box will be displayed as a drop-down list (the default). + * + * @since + * @param visibleItemCount + * the visible item count + * @throws IllegalArgumentException + * if the value is smaller than one + */ + public void setVisibleItemCount(int visibleItemCount) { + if (visibleItemCount < 1) { + throw new IllegalArgumentException( + "There must be at least one item visible"); + } + getState().visibleItemCount = visibleItemCount; + } + + /** + * Gets the number of items that are visible. If only one item is visible, + * then the box will be displayed as a drop-down list. + * + * @since + * @return the visible item count + */ + public int getVisibleItemCount() { + return getState(false).visibleItemCount; + } } -- cgit v1.2.3