SelectList list;\r
private float prefWidth, prefHeight;\r
private ClickListener clickListener;\r
+ private int maxDropdownCount;\r
\r
public SelectBox (Object[] items, Skin skin) {\r
this(items, skin.get(SelectBoxStyle.class));\r
setItems(items);\r
setWidth(getPrefWidth());\r
setHeight(getPrefHeight());\r
+ setMaxDropdownCount(0);\r
\r
addListener(clickListener = new ClickListener() {\r
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {\r
});\r
}\r
\r
+ /**\r
+ * Set the max number of dropdown List items to display when the box is opened.\r
+ * @param num_items Max number of items to display, or <= 0 to display them all\r
+ */\r
+ public void setMaxDropdownCount(int num_items) {\r
+ maxDropdownCount = num_items;\r
+ }\r
+\r
+ /** @return Max number of dropdown List items to display when the box is opened, or <= 0 to display them all. */\r
+ public int getMaxDropdownCount() {\r
+ return maxDropdownCount;\r
+ }\r
+\r
public void setStyle (SelectBoxStyle style) {\r
if (style == null) throw new IllegalArgumentException("style cannot be null.");\r
this.style = style;\r
list.setSelectedIndex(selectedIndex);\r
\r
// Show the list above or below the select box, limited to the available height.\r
- float height = getPrefHeight();\r
+ //float height = getPrefHeight(); // old method\r
+ \r
+ // set the available height to show the max desired dropdown items\r
+ float height = list.getItemHeight() * ((getMaxDropdownCount() <= 0 ? list.getItems().length : Math.min(getMaxDropdownCount(), list.getItems().length)) + 1);\r
float heightBelow = tmpCoords.y;\r
float heightAbove = stage.getCamera().viewportHeight - tmpCoords.y - SelectBox.this.getHeight();\r
boolean below = true;\r