diff --git a/modules/controls/src/main/java/javafx/scene/control/Accordion.java b/modules/controls/src/main/java/javafx/scene/control/Accordion.java --- a/modules/controls/src/main/java/javafx/scene/control/Accordion.java +++ b/modules/controls/src/main/java/javafx/scene/control/Accordion.java @@ -72,7 +72,21 @@ * Creates a new Accordion with no TitledPanes. */ public Accordion() { + this((TitledPane[])null); + } + + /** + * Creates a new Accordion with the given TitledPanes showing within it. + * + * @param titledPanes The TitledPanes to show inside the Accordion. + */ + public Accordion(TitledPane... titledPanes) { getStyleClass().setAll(DEFAULT_STYLE_CLASS); + + if (titledPanes != null) { + getPanes().addAll(titledPanes); + } + // focusTraversable is styleable through css. Calling setFocusTraversable // makes it look to css like the user set the value and css will not // override. Initializing focusTraversable by calling applyStyle with null diff --git a/modules/controls/src/main/java/javafx/scene/control/Menu.java b/modules/controls/src/main/java/javafx/scene/control/Menu.java --- a/modules/controls/src/main/java/javafx/scene/control/Menu.java +++ b/modules/controls/src/main/java/javafx/scene/control/Menu.java @@ -131,6 +131,8 @@ /** * Constructs a Menu and sets the display text with the specified text. + * + * @param text the text to display on the menu button */ public Menu(String text) { this(text,null); @@ -139,11 +141,31 @@ /** * Constructs a Menu and sets the display text with the specified text * and sets the graphic {@link Node} to the given node. + * + * @param text the text to display on the menu button + * @param graphic the graphic to display on the menu button */ public Menu(String text, Node graphic) { + this(text, graphic, (MenuItem[])null); + } + + /** + * Constructs a Menu and sets the display text with the specified text, + * the graphic {@link Node} to the given node, and inserts the given items + * into the {@link #getItems() items} list. + * + * @param text the text to display on the menu button + * @param graphic the graphic to display on the menu button + * @param items The items to display in the popup menu. + */ + public Menu(String text, Node graphic, MenuItem... items) { super(text,graphic); getStyleClass().add(DEFAULT_STYLE_CLASS); + if (items != null) { + getItems().addAll(items); + } + parentPopupProperty().addListener(observable -> { for (int i = 0; i < getItems().size(); i++) { MenuItem item = getItems().get(i); diff --git a/modules/controls/src/main/java/javafx/scene/control/MenuBar.java b/modules/controls/src/main/java/javafx/scene/control/MenuBar.java --- a/modules/controls/src/main/java/javafx/scene/control/MenuBar.java +++ b/modules/controls/src/main/java/javafx/scene/control/MenuBar.java @@ -81,9 +81,26 @@ * * **************************************************************************/ + /** + * Creates a new empty MenuBar. + */ public MenuBar() { + this((Menu[])null); + } + + /** + * Creates a new MenuBar populated with the given menus. + * + * @param menus The menus to place inside the MenuBar + */ + public MenuBar(Menu... menus) { getStyleClass().setAll(DEFAULT_STYLE_CLASS); setRole(AccessibleRole.MENU_BAR); + + if (menus != null) { + getMenus().addAll(menus); + } + // focusTraversable is styleable through css. Calling setFocusTraversable // makes it look to css like the user set the value and css will not // override. Initializing focusTraversable by calling applyStyle with null diff --git a/modules/controls/src/main/java/javafx/scene/control/MenuButton.java b/modules/controls/src/main/java/javafx/scene/control/MenuButton.java --- a/modules/controls/src/main/java/javafx/scene/control/MenuButton.java +++ b/modules/controls/src/main/java/javafx/scene/control/MenuButton.java @@ -92,7 +92,7 @@ /** * Creates a new empty menu button with the given text to display on the - * menu. Use {@link #setGraphic(Node)} and {@link #getItems()} to set the + * button. Use {@link #setGraphic(Node)} and {@link #getItems()} to set the * content. * * @param text the text to display on the menu button @@ -103,18 +103,35 @@ /** * Creates a new empty menu button with the given text and graphic to - * display on the menu. Use {@link #getItems()} to set the content. + * display on the button. Use {@link #getItems()} to set the content. * * @param text the text to display on the menu button * @param graphic the graphic to display on the menu button */ public MenuButton(String text, Node graphic) { + this(text, graphic, (MenuItem[])null); + } + + /** + * Creates a new menu button with the given text and graphic to + * display on the button, and inserts the given items + * into the {@link #getItems() items} list. + * + * @param text the text to display on the menu button + * @param graphic the graphic to display on the menu button + * @param items The items to display in the popup menu. + */ + public MenuButton(String text, Node graphic, MenuItem... items) { if (text != null) { setText(text); } if (graphic != null) { setGraphic(graphic); } + if (items != null) { + getItems().addAll(items); + } + getStyleClass().setAll(DEFAULT_STYLE_CLASS); setRole(AccessibleRole.MENU_BUTTON); setMnemonicParsing(true); // enable mnemonic auto-parsing by default diff --git a/modules/controls/src/main/java/javafx/scene/control/SplitPane.java b/modules/controls/src/main/java/javafx/scene/control/SplitPane.java --- a/modules/controls/src/main/java/javafx/scene/control/SplitPane.java +++ b/modules/controls/src/main/java/javafx/scene/control/SplitPane.java @@ -174,6 +174,16 @@ * Creates a new SplitPane with no content. */ public SplitPane() { + this((Node[])null); + } + + /** + * Creates a new SplitPane with the given items set as the content to split + * between one or more dividers. + * + * @param items The items to place inside the SplitPane. + */ + public SplitPane(Node... items) { getStyleClass().setAll(DEFAULT_STYLE_CLASS); // focusTraversable is styleable through css. Calling setFocusTraversable // makes it look to css like the user set the value and css will not @@ -181,7 +191,7 @@ // null StyleOrigin ensures that css will be able to override the value. ((StyleableProperty)(WritableValue)focusTraversableProperty()).applyStyle(null, Boolean.FALSE); - items.addListener(new ListChangeListener() { + getItems().addListener(new ListChangeListener() { @Override public void onChanged(Change c) { while (c.next()) { int from = c.getFrom(); @@ -207,7 +217,7 @@ } } dividers.clear(); - for (int i = 0; i < items.size() - 1; i++) { + for (int i = 0; i < getItems().size() - 1; i++) { if (dividerCache.containsKey(i) && dividerCache.get(i) != Double.MAX_VALUE) { Divider d = new Divider(); d.setPosition(dividerCache.get(i)); @@ -219,6 +229,10 @@ } } }); + + if (items != null) { + getItems().addAll(items); + } // initialize pseudo-class state pseudoClassStateChanged(HORIZONTAL_PSEUDOCLASS_STATE, true); diff --git a/modules/controls/src/main/java/javafx/scene/control/Tab.java b/modules/controls/src/main/java/javafx/scene/control/Tab.java --- a/modules/controls/src/main/java/javafx/scene/control/Tab.java +++ b/modules/controls/src/main/java/javafx/scene/control/Tab.java @@ -97,7 +97,18 @@ * @param text The title of the tab. */ public Tab(String text) { + this(text, null); + } + + /** + * Creates a tab with a text title and the specified content node. + * + * @param text The title of the tab. + * @param content The content of the tab. + */ + public Tab(String text, Node content) { setText(text); + setContent(content); styleClass.addAll(DEFAULT_STYLE_CLASS); } diff --git a/modules/controls/src/main/java/javafx/scene/control/TabPane.java b/modules/controls/src/main/java/javafx/scene/control/TabPane.java --- a/modules/controls/src/main/java/javafx/scene/control/TabPane.java +++ b/modules/controls/src/main/java/javafx/scene/control/TabPane.java @@ -110,11 +110,20 @@ * Constructs a new TabPane. */ public TabPane() { + this((Tab[])null); + } + + /** + * Constructs a new TabPane with the given tabs set to show. + * + * @param tabs The {@link Tab tabs} to display inside the TabPane. + */ + public TabPane(Tab... tabs) { getStyleClass().setAll("tab-pane"); setRole(AccessibleRole.TAB_PANE); setSelectionModel(new TabPaneSelectionModel(this)); - tabs.addListener((ListChangeListener) c -> { + this.tabs.addListener((ListChangeListener) c -> { while (c.next()) { for (Tab tab : c.getRemoved()) { if (tab != null && !getTabs().contains(tab)) { @@ -129,6 +138,10 @@ } } }); + + if (tabs != null) { + getTabs().addAll(tabs); + } // initialize pseudo-class state Side edge = getSide();