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/SplitMenuButton.java b/modules/controls/src/main/java/javafx/scene/control/SplitMenuButton.java --- a/modules/controls/src/main/java/javafx/scene/control/SplitMenuButton.java +++ b/modules/controls/src/main/java/javafx/scene/control/SplitMenuButton.java @@ -30,6 +30,7 @@ import javafx.scene.AccessibleAttribute; import javafx.scene.AccessibleRole; import com.sun.javafx.scene.control.skin.SplitMenuButtonSkin; +import javafx.scene.Node; /** * The SplitMenuButton, like the {@link MenuButton} is closely associated with @@ -79,18 +80,53 @@ /** * Creates a new empty split menu button. Use {@link #setText(String)}, - * {@link #setGraphic(Node)} and {@link #getItems()} to set the content. + * {@link #setGraphic(javafx.scene.Node)} and {@link #getItems()} to set the content. */ public SplitMenuButton() { this((MenuItem[])null); } /** + * Creates a new empty split menu button with the given text to display on the + * button. Use {@link #setGraphic(javafx.scene.Node)} and {@link #getItems()} to set the + * content. + * + * @param text the text to display on the split menu button + */ + public SplitMenuButton(String text) { + this(text, null); + } + + /** + * Creates a new empty split menu button with the given text and graphic to + * display on the button. Use {@link #getItems()} to set the content. + * + * @param text the text to display on the split menu button + * @param graphic the graphic to display on the split menu button + */ + public SplitMenuButton(String text, Node graphic) { + this(text, graphic, (MenuItem[])null); + } + + /** * Creates a new split menu button with the given list of menu items. * * @param items The items to show within this button's menu */ public SplitMenuButton(MenuItem... items) { + this(null, null, items); + } + + /** + * Creates a new split 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 split menu button + * @param graphic the graphic to display on the split menu button + * @param items The items to display in the popup menu. + */ + public SplitMenuButton(String text, Node graphic, MenuItem... items) { if (items != null) { getItems().addAll(items); } 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 @@ -95,7 +95,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 @@ -105,11 +105,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)) { @@ -124,6 +133,10 @@ } } }); + + if (tabs != null) { + getTabs().addAll(tabs); + } // initialize pseudo-class state Side edge = getSide(); diff --git a/modules/controls/src/main/java/javafx/scene/control/TableView.java b/modules/controls/src/main/java/javafx/scene/control/TableView.java --- a/modules/controls/src/main/java/javafx/scene/control/TableView.java +++ b/modules/controls/src/main/java/javafx/scene/control/TableView.java @@ -495,7 +495,20 @@ * default state of other properties. */ public TableView() { - this(FXCollections.observableArrayList()); + this((TableColumn[])null); + } + + /** + * Creates a default TableView control with no content, but with the given + * columns installed into the TableView. + * + *

Refer to the {@link TableView} class documentation for details on the + * default state of other properties. + * + * @param columns The columns to display in the TableView. + */ + public TableView(TableColumn... columns) { + this(FXCollections.observableArrayList(), columns); } /** @@ -510,6 +523,23 @@ * for changes (to automatically show in the TableView). */ public TableView(ObservableList items) { + this(items, (TableColumn[])null); + } + + /** + * Creates a TableView with the content provided in the items ObservableList, + * and with the given columns installed into the TableView. + * This also sets up an observer such that any changes to the items list + * will be immediately reflected in the TableView itself. + * + *

Refer to the {@link TableView} class documentation for details on the + * default state of other properties. + * + * @param items The items to insert into the TableView, and the list to watch + * for changes (to automatically show in the TableView). + * @param columns The columns to display in the TableView. + */ + public TableView(ObservableList items, TableColumn... columns) { getStyleClass().setAll(DEFAULT_STYLE_CLASS); setRole(AccessibleRole.TABLE_VIEW); @@ -548,6 +578,10 @@ focusedProperty().addListener(focusedListener); + if (columns != null) { + getColumns().addAll(columns); + } + isInited = true; } diff --git a/modules/controls/src/main/java/javafx/scene/control/TreeTableView.java b/modules/controls/src/main/java/javafx/scene/control/TreeTableView.java --- a/modules/controls/src/main/java/javafx/scene/control/TreeTableView.java +++ b/modules/controls/src/main/java/javafx/scene/control/TreeTableView.java @@ -349,7 +349,20 @@ * default state of other properties. */ public TreeTableView() { - this(null); + this((TreeTableColumn[])null); + } + + /** + * Creates a default TreeTableView control with no content, but with the given + * columns installed into the TreeTableView. + * + *

Refer to the {@link TreeTableView} class documentation for details on the + * default state of other properties. + * + * @param columns The columns to display in the TreeTableView. + */ + public TreeTableView(TreeTableColumn... columns) { + this(null, columns); } /** @@ -361,6 +374,20 @@ * @param root The node to be the root in this TreeTableView. */ public TreeTableView(TreeItem root) { + this(root, (TreeTableColumn[])null); + } + + /** + * Creates a TreeTableView with the root set to the provided root, + * and with the given columns installed into the TreeTableView. + * + *

Refer to the {@link TreeTableView} class documentation for details on the + * default state of other properties. + * + * @param root The node to be the root in this TreeTableView. + * @param columns The columns to display in the TreeTableView. + */ + public TreeTableView(TreeItem root, TreeTableColumn... columns) { getStyleClass().setAll(DEFAULT_STYLE_CLASS); setRole(AccessibleRole.TREE_TABLE_VIEW); @@ -396,6 +423,10 @@ focusedProperty().addListener(focusedListener); + if (columns != null) { + getColumns().addAll(columns); + } + isInited = true; }