Class UIFactoryMethods
- Direct Known Subclasses:
UI
color(String) and font(String),
and layout constants (see UILayoutConstants).
This class is intended to be used by the
UI namespace class ONLY!
Please do not inherit or import this class in your own code directly, as it is not intended to be used outside the
UI namespace.
-
Field Summary
Fields inherited from class swingtree.UILayoutConstants
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_X_CENTER, ALIGN_X_LEFT, ALIGN_X_RIGHT, ALIGN_Y_BOTTOM, ALIGN_Y_CENTER, ALIGN_Y_TOP, BOTTOM, CENTER, DEBUG, DOCK_EAST, DOCK_NORTH, DOCK_SOUTH, DOCK_WEST, FILL, FILL_X, FILL_Y, FLOW_X, FLOW_Y, GAP_BOTTOM_PUSH, GAP_LEFT_PUSH, GAP_RIGHT_PUSH, GAP_TOP_PUSH, GROW, GROW_X, GROW_Y, LEFT, NO_CACHE, NO_GRID, PUSH, PUSH_X, PUSH_Y, RIGHT, SHRINK, SHRINK_X, SHRINK_Y, SPAN, TOP, WRAP -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidanimate(sprouts.Var<T> state, Function<T, Animatable<T>> animatable) Use this to animate the contents of a property through using anAnimatableinstance holding a transformational function for the intendedAnimationStatusbased changes and aLifeTimedefining the duration of the animation.static <T> voidanimate(sprouts.Var<T> state, Animatable<T> animatable) Use this to animate the contents of a property through using anAnimatableinstance holding a transformational function for the intendedAnimationStatusbased changes and aLifeTimedefining the duration of the animation.static AnimationDispatcheranimateFor(double duration, TimeUnit unit) Exposes a builder API for creating and scheduling periodic animation updates.static AnimationDispatcheranimateFor(double duration, TimeUnit unit, Stride stride) Exposes a builder API for creating and scheduling periodic animation updates.static AnimationDispatcheranimateFor(long duration, TimeUnit unit) Exposes an API for scheduling periodic animation updates.static AnimationDispatcheranimateFor(LifeTime duration) Exposes an API for scheduling periodic animation updates.static AnimationDispatcheranimateFor(LifeTime duration, Component component) Exposes an API for scheduling periodic animation updates for a specific component whoseComponent.repaint()method should be called after every animation update.static <E extends Enum<E>>
voidShows a dialog where the user can select a value from a list of options based on the enum type implicitly defined by the given enum based property.Shows a dialog where the user can select a value from a list of options based on the enum type implicitly defined by the given enum based property.Shows a dialog where the user can select a value from a list of options based on the enum type implicitly defined by the given enum based property.static UIForLabel<JLabel> Use this to create a UI builder for aJLabelwith bold font.static UIForLabel<JLabel> Use this to create a UI builder for a boundJLabelwith bold font.box()Use this to create a builder for aJBoxinstance, which is a general purpose component wrapper type with the following properties: It is transparent, meaning that it does not paint its background.Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager.Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager.box(net.miginfocom.layout.LC attr) Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager.Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager.box(sprouts.Val<LayoutConstraint> attr) Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager.box(LayoutConstraint attr) Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager.box(LayoutConstraint attr, String colConstraints) Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager.box(LayoutConstraint attr, String colConstraints, String rowConstraints) static UIForButton<JButton> button()Use this to create a builder for theJButtonUI component without any text displayed on top.static UIForButton<JButton> Use this to create a builder for theJButtonUI component with an icon displayed on top which should be scaled to the provided dimensions.static UIForButton<JButton> Use this to create a builder for theJButtonUI component with a default icon as well as a hover icon displayed on top which should both be scaled to the provided dimensions.static UIForButton<JButton> button(int width, int height, IconDeclaration icon) Use this to create a builder for theJButtonUI component with an icon displayed on top which should be scaled to the provided dimensions.static UIForButton<JButton> button(int width, int height, IconDeclaration icon, IconDeclaration onHover) Use this to create a builder for theJButtonUI component with a default icon as well as a hover icon displayed on top which should both be scaled to the provided dimensions.static UIForButton<JButton> Use this to create a builder for theJButtonUI component with the provided text displayed on top.static UIForButton<JButton> Use this to create a builder for theJButtonUI component with an icon displayed on top.static UIForButton<JButton> Use this to create a builder for theJButtonUI component with a default icon as well as a hover icon displayed on top.static UIForButton<JButton> Use this to create a builder for theJButtonUI component with a default, an on-hover and an on-press icon displayed on top.static UIForButton<JButton> button(ImageIcon icon, UI.FitComponent fit) Use this to create a builder for theJButtonUI component with an icon displayed on top.static UIForButton<JButton> Create a builder for theJButtonUI component where the text of the provided property is dynamically displayed on top.static UIForButton<JButton> button(IconDeclaration icon) Use this to create a builder for theJButtonUI component with an icon displayed on top.static UIForButton<JButton> button(IconDeclaration icon, IconDeclaration onHover) Use this to create a builder for theJButtonUI component with a default icon as well as a hover icon displayed on top.static UIForButton<JButton> button(IconDeclaration icon, IconDeclaration onHover, IconDeclaration onPress) Use this to create a builder for theJButtonUI component with a default, an on-hover and an on-press icon displayed on top.static UIForButton<JButton> button(IconDeclaration icon, UI.FitComponent fit) Use this to create a builder for theJButtonUI component with an icon displayed on top.static UIForButton<JButton> buttonWithIcon(sprouts.Val<IconDeclaration> icon) Use this to create a builder for theJButtonUI component with a dynamically displayed icon on top.static UIForCheckBox<JCheckBox> Creates a builder node wrapping a newJCheckBoxinstance with the provided text displayed on it.static UIForCheckBox<JCheckBox> Creates a builder node wrapping a newJCheckBoxinstance with the provided text displayed on it and the provided selection property dynamically determining whether the checkbox is selected or not.static UIForCheckBox<JCheckBox> Creates a builder node wrapping a newJCheckBoxinstance where the provided text property dynamically displays its value on the checkbox.static UIForCheckBox<JCheckBox> Creates a builder node wrapping a newJCheckBoxinstance where the provided text property dynamically displays its value on the checkbox and the provided selection property dynamically determines whether the checkbox is selected or not.A factory method to create aJCheckBoxMenuItemwithout text displayed on top of the menu button.checkBoxMenuItem(String text) A factory method to create aJCheckBoxMenuItemwith the provided text displayed on the menu button.checkBoxMenuItem(String text, Icon icon) A factory method to create aJCheckBoxMenuItemwith the provided text displayed on the menu button and the provided icon displayed on the menu button.checkBoxMenuItem(String text, sprouts.Var<Boolean> isSelected) A factory method to create aJCheckBoxMenuItemwith some custom text and a boolean property, dynamically determining whether the menu item is selected or not.checkBoxMenuItem(sprouts.Val<String> text) A factory method to create aJCheckBoxMenuItembound to the provided text property, whose value will be displayed on the menu button dynamically.checkBoxMenuItem(sprouts.Val<String> text, Icon icon) A factory method to create aJCheckBoxMenuItembound to the provided text property, whose value will be displayed on the menu button dynamically and the provided icon displayed on the menu button.checkBoxMenuItem(sprouts.Val<String> text, sprouts.Var<Boolean> isSelected) A factory method to create aJCheckBoxMenuItembound to the provided text property, whose value will be displayed on the menu button dynamically and the provided boolean property, dynamically determining whether the menu item is selected or not.static <E extends Enum<E>>
OptionsDialog<E> Exposes theOptionsDialogAPI for creating a question dialog that allows the user to select a value from an array of provided enum values.static <E extends Enum<E>>
OptionsDialog<E> Exposes theOptionsDialogAPI for creating a question dialog that allows the user to select and set a value from the provided enum based property.static UI.Colorcolor(double r, double g, double b) Creates a newColorobject from the specified red, green and blue values.static UI.Colorcolor(double r, double g, double b, double a) Creates a newColorobject from the specified red, green, blue and alpha values.static UI.Colorcolor(int r, int g, int b) Creates a newColorobject from the specified red, green and blue values.static UI.Colorcolor(int r, int g, int b, int a) Creates a newColorobject from the specified red, green, blue and alpha values.static UI.ColorTries to parse the supplied string as a color value based on various formats.static <E> UIForCombo<E, JComboBox<E>> comboBox()Use this to create a UI builder for a theJComboBoxcomponent type.static <E> UIForCombo<E, JComboBox<E>> comboBox(E... items) Use this to declare a UI builder for theJComboBoxcomponent type with the provided array of elements as selectable items.static <E> UIForCombo<E, JComboBox<E>> static <E> UIForCombo<E, JComboBox<E>> Use this to declare a builder for a newJComboBoxinstance with the provided list of elements as selectable items.static <E> UIForCombo<E, JComboBox<E>> Use this to declare a builder for a newJComboBoxinstance with the provided list of elements as selectable items and a custom renderer function to display the items in the combo box as text.static <E> UIForCombo<E, JComboBox<E>> comboBox(ComboBoxModel<E> model) Created a combo box UI builder node with the providedComboBoxModel.static <E> UIForCombo<E, JComboBox<E>> comboBox(ComboBoxModel<E> model, Function<E, String> renderer) Created a combo box UI builder node with the providedComboBoxModeland a lambda function mapping each model entry to a user-friendly human-readableStringrepresentation.static <E> UIForCombo<E, JComboBox<E>> comboBox(sprouts.Vals<E> items) Use this to create a builder for a newJComboBoxinstance with the provided properties list object as selectable (and immutable) items which may not be modified by the user.static <E> UIForCombo<E, JComboBox<E>> Creates a declarative UI builder for theJComboBoxcomponent type where the provided property list dynamically models the selectable items in the combo box and a renderer function determines how the items are displayed as text in the combo box dropdown list.static <E extends Enum<E>>
UIForCombo<E, JComboBox<E>> comboBox(sprouts.Var<E> selectedItem) Use this to create a builder for a newJComboBoxinstance where the provided enum based property dynamically models the selected item as well as all possible options (all the enum states).static <E> UIForCombo<E, JComboBox<E>> comboBox(sprouts.Var<E> var, E... items) Creates a combo box UI builder node with aVarproperty as the model for the current selection and an array of items as a fixed-size model for the selectable items.static <E> UIForCombo<E, JComboBox<E>> Creates a combo box UI declaration with aVarproperty as the model for the current selection and an array of items as a fixed-size model for the selectable items, as well as a lambda function which maps each combo box item to a user-friendlyStringrepresentation.static <E extends Enum<E>>
UIForCombo<E, JComboBox<E>> Use this to create a builder for a newJComboBoxinstance where the provided enum based property dynamically models the selected item as well as all possible options (all the enum states).static <E> UIForCombo<E, JComboBox<E>> Creates a combo box UI builder node with aVarproperty as the model for the current selection and a list of items as a dynamically sized model for the selectable items.static <E> UIForCombo<E, JComboBox<E>> Creates a declarative combo box UI based on the provided selection property and the list of items as well as a custom renderer function to display the items as text in the combo box.static <E> UIForCombo<E, JComboBox<E>> comboBox(sprouts.Var<E> selectedItem, sprouts.Val<sprouts.Tuple<E>> items) Creates a combo box UI builder node with aVarproperty as the model for the current selection and a tuple property of items as a selectable items model that may change dynamically.static <E> UIForCombo<E, JComboBox<E>> comboBox(sprouts.Var<E> selectedItem, sprouts.Val<sprouts.Tuple<E>> items, Function<E, String> renderer) Creates a declarative combo box UI based on the provided selection property, a property of an array of selectable items and a custom renderer function to display the items as the desired text in the combo box.static <E> UIForCombo<E, JComboBox<E>> comboBox(sprouts.Var<E> selection, sprouts.Vals<E> items) Creates a combo box UI builder node with aVarproperty as the model for the current selection and a property list of items as a dynamically sized model for the selectable items which may not be modified by the user.static <E> UIForCombo<E, JComboBox<E>> Creates a declarative combo box UI based on the provided selection property, a property list of selectable items as well as a custom renderer function to display the items as the desired text in the combo box.static <E> UIForCombo<E, JComboBox<E>> comboBox(sprouts.Var<E> var, sprouts.Var<sprouts.Tuple<E>> items) Creates a combo box UI builder node with aVarproperty as the model for the current selection and a tuple property of items as a selectable items model which may be modified by the user or change dynamically in your code.static <E> UIForCombo<E, JComboBox<E>> Creates a declarative combo box UI based on the provided selection property, a property of an array of selectable items and a custom renderer function to display the items as the desired text in the combo box.static <E> UIForCombo<E, JComboBox<E>> comboBox(sprouts.Var<E> selection, sprouts.Vars<E> items) Creates a combo box UI builder node with aVarproperty as the model for the current selection and a list of items as a dynamically sized model for the selectable items.static <E> UIForCombo<E, JComboBox<E>> Creates a declarative combo box UI based on the provided selection property, a property list of selectable items as well as a custom renderer function to display the items as the desired text in the combo box.static <E> UIForCombo<E, JComboBox<E>> comboBox(sprouts.Vars<E> items) Use this to create a builder for a newJComboBoxinstance with the provided properties list object as selectable (and mutable) items.static <E> UIForCombo<E, JComboBox<E>> Creates a declarative UI builder for theJComboBoxcomponent type where the provided property list dynamically models the selectable items in the combo box and a renderer function determines how the items are displayed as text in the combo box dropdown list.static <E> UIForCombo<E, JComboBox<E>> comboBoxWithUnmodifiable(E... items) Use this to declare a UI builder for theJComboBoxtype with the provided array of elements as selectable items which may not be modified by the user.static <E> UIForCombo<E, JComboBox<E>> comboBoxWithUnmodifiable(E[] items, Function<E, String> renderer) Use this to declare a UI builder for theJComboBoxtype with the provided array of elements as selectable items which may not be modified by the user.static <E> UIForCombo<E, JComboBox<E>> comboBoxWithUnmodifiable(List<E> items) Use this to create a builder for a newJComboBoxinstance with the providedUI.ListViewof elements as selectable items which may not be modified by the user.static <E> UIForCombo<E, JComboBox<E>> comboBoxWithUnmodifiable(List<E> items, Function<E, String> renderer) Creates a declarative combo box UI based on the provided list of items, which may not be modified by the user.static ConfirmAnswerShows a conformation dialog with the given message and returns the user's answer in the form of aConfirmAnswerenum constant.static ConfirmAnswerShows a conformation dialog with the given title and message and returns the user's answer in the form of aConfirmAnswerenum constant.static ConfirmDialogconfirmation(String toBeConfirmed) Exposes theConfirmDialogAPI, an immutable builder config type for creating a confirmation dialog designed to ask a question.static UIForJDialog<JDialog> dialog()Use this to create a builder for the suppliedJDialog.static UIForJDialog<JDialog> Use this to create a builder for the suppliedJDialogwith the supplied owner.static UIForJDialog<JDialog> Use this to create a builder for the suppliedJDialogwith the supplied owner and title.static UIForJDialog<JDialog> Use this to create a builder for the suppliedJDialogwith the supplied title.static UIForEditorPane<JEditorPane> Use this to create a builder for a newJEditorPaneUI component.static voidShows an error dialog with the given message.static voidShows an error dialog with the given message and dialog title.Loads anImageIconfrom the resource folder, the classpath, a local file or from cache if it has already been loaded.findIcon(IconDeclaration declaration) Loads anImageIconfrom the resource folder, the classpath, a local file or from cache if it has already been loaded.findSvgIcon(String path) Loads anSvgIconfrom the resource folder, the classpath, a local file or from cache if it has already been loaded.findSvgIcon(IconDeclaration declaration) Loads anSvgIconfrom the resource folder, the classpath, a local file or from cache if it has already been loaded.static UI.FontReturns theUI.Fontthat thefontStringargument describes.static UIForFormattedTextFieldUse this to create a builder for a newJFormattedTextFieldUI component.static UIForFormattedTextFieldformattedTextField(String text) Use this to create a builder for a newJFormattedTextFieldinstance with the provided text displayed on it.static UIForFormattedTextFieldformattedTextField(sprouts.Val<String> text) Use this to create a builder for a newJFormattedTextFieldinstance with the provided text property dynamically displaying its value in the text field.static UIForFormattedTextFieldformattedTextField(sprouts.Var<String> text) Use this to create a builder for a newJFormattedTextFieldinstance with the provided text property dynamically displaying its value in the formatted text field.static UIForJFrame<JFrame> frame()Use this to create a builder for the suppliedJFrame.static UIForJFrame<JFrame> Use this to create a builder for the suppliedJFramewith the supplied title.static UIForLabel<JLabel> Use this to create a builder for aJLabeldisplaying HTML.static UIForLabel<JLabel> Use this to create a builder for aJLabeldisplaying HTML.Creates a builder node wrapping a newJIconinstance with the icon found at the provided path displayed on it and scaled to the provided width and height.Creates a builder node wrapping a newJIconinstance with the provided icon scaled to the provided width and height.icon(int width, int height, IconDeclaration icon) Creates a builder node wrapping a newJIconinstance with the icon found at the path defined by the suppliedIconDeclarationdisplayed on it and scaled to the provided width and height.Creates a builder node wrapping a newJIconinstance with the icon found at the provided path displayed on it.Creates a builder node wrapping a newJIconinstance with the provided icon displayed on it.icon(sprouts.Val<IconDeclaration> icon) Creates a UI declaration for aJIconwhich is dynamically bound to the providedValproperty containing anIconDeclaration.icon(IconDeclaration icon) Creates a builder node wrapping a newJIconinstance with the icon found at the path provided by the suppliedIconDeclarationdisplayed on it.Creates a declarative builder for theJIconcomponent with the icon found at the path defined by the suppliedIconDeclarationdisplayed on it and scaled to fit the providedSize, consisting of a width and height.icon(Size size, IconDeclaration icon) Creates a declarative builder for theJIconcomponent with the icon found at the path defined by the suppliedIconDeclarationdisplayed on it and scaled to fit the providedSize, consisting of a width and height.static voidShows an info dialog with the given message.static voidShows an info dialog with the given message and dialog title.static UIForLabel<JLabel> Use this to create a UI builder for a text-less label containing and displaying an icon.static UIForLabel<JLabel> label(int width, int height, IconDeclaration icon) Use this to create a UI builder for a text-less label containing and displaying an icon.static UIForLabel<JLabel> Use this to create a builder for theJLabelUI component.static UIForLabel<JLabel> label(String text, UI.Alignment alignment) Use this to create a builder for theJLabelUI component.static UIForLabel<JLabel> label(String text, UI.HorizontalAlignment alignment) Use this to create a builder for theJLabelUI component.static UIForLabel<JLabel> Use this to create a UI builder for a text-less label containing and displaying an icon.static UIForLabel<JLabel> Use this to create a builder for theJLabelUI component.static UIForLabel<JLabel> label(sprouts.Val<String> text, UI.HorizontalAlignment alignment) Use this to create a builder for theJLabelUI component.static UIForLabel<JLabel> label(IconDeclaration icon) Use this to create a UI builder for a text-less label containing and displaying an icon.static UIForLabel<JLabel> labelWithIcon(sprouts.Val<IconDeclaration> icon) Use this to create a UI builder for a text-less label containing and displaying an icon dynamically.static LifeTimeA factory method for creating aLifeTimeinstance with the given duration and time unit.list()Allows for the creation of a declarative UI for theJListcomponent type.list(E... elements) Creates a newJListinstance builder with the provided array as a data model.Creates a newJListinstance with the providedUI.ListViewas data model.Allows for the creation of a declarative UI for a newJListinstance with a custom list model.list(sprouts.Val<E> selection, sprouts.Vals<E> elements) Allows for the creation of a newJListinstance with 2 observable collections as data model, aValproperty for the selection and aValsproperty list for the elements.list(sprouts.Vals<E> elements) Allows for the creation of a newJListinstance with the provided observable property list (aValsobject) as data model.list(sprouts.Var<E> selection, sprouts.Vals<E> elements) Allows for the creation of a newJListinstance with 2 observable collections as data model, aVarproperty for the selection and aValsproperty list for the elements.listOf(E... elements) Creates a newJListinstance with the provided array as data model.Creates a newJListinstance with the providedUI.ListViewas data model.listOf(sprouts.Vals<E> elements) A functionally identical alias method forlist(Vals), which allows for the creation of a newJListinstance with the provided observable property list (aValsobject) as data model.menu()A convenient factory method for creating a declarative builder object for a plainJMenucomponent.A convenient factory method for creating a declarative builder object for aJMenucomponent initialized with the provided text.A convenient factory method for creating a declarative builder object for aJMenucomponent bound to the supplied text property.static UIForMenuItem<JMenuItem> menuItem()A convenient factory method for creating a declarative builder object for a theJMenuItemcomponent type.
Menu items are usually passed toJMenus orJPopupMenus like so:static UIForMenuItem<JMenuItem> This factory method creates aJMenuwith the provided text displayed on the menu button.static UIForMenuItem<JMenuItem> Use this factory method to create aJMenuItemwith the provided text and default icon.static UIForMenuItem<JMenuItem> menuItem(String text, sprouts.Val<IconDeclaration> icon) Allows you to create a menu item with an icon property bound to it.static UIForMenuItem<JMenuItem> menuItem(String text, IconDeclaration icon) Use this factory method to create aJMenuItemwith the provided text and default icon based on the providedIconDeclaration.static UIForMenuItem<JMenuItem> This factory method creates aJMenuItemwith the provided text property bound to the menu item.static UIForMenuItem<JMenuItem> A factory method for creating aJMenuItemwith an icon and the supplied text property uni-directionally bound to the menu item.static UIForMenuItem<JMenuItem> menuItem(sprouts.Val<String> text, sprouts.Val<IconDeclaration> icon) Allows you to create a menu item with a text property and an icon property bound to it.static UIForMenuItem<JMenuItem> menuItem(sprouts.Val<String> text, IconDeclaration icon) A factory method for creating aJMenuItemwith an icon and the supplied text property uni-directionally bound to the menu item.static MessageDialogExposes theMessageDialogAPI, an immutable builder config for creating a message dialog with a given message text.static <N extends Number>
UIForTextField<JTextField> numericTextField(sprouts.Var<N> number) Use this to create a builder for a newJTextFieldinstance with the provided number property dynamically displaying its value on the text field.static <N extends Number>
UIForTextField<JTextField> numericTextField(sprouts.Var<N> number, Function<N, String> formatter) Use this to create a builder for a newJTextFieldinstance with the provided number property dynamically displaying its value on the text field and a function which will be used to format the number as a string.static <N extends Number>
UIForTextField<JTextField> numericTextField(sprouts.Var<N> number, sprouts.Var<Boolean> isValid) Use this to create a builder for a newJTextFieldinstance with the provided number property dynamically displaying its value on the text field and a boolean property which will be set totrueif the text field contains a valid number, andfalseotherwise.static <N extends Number>
UIForTextField<JTextField> numericTextField(sprouts.Var<N> number, sprouts.Var<Boolean> isValid, Function<N, String> formatter) Use this to create a builder for a newJTextFieldinstance with the provided number property dynamically displaying its value on the text field and a boolean property which will be set totrueif the text field contains a valid number, andfalseotherwise.static <A extends JTextArea>
UIForTextArea<A> of(A area) Use this to create a builder for the providedJTextAreainstance.of(B component) Use this to create a builder for the providedJBoxinstance, which is a general purpose component wrapper type with the following properties: It is transparent, meaning that it does not paint its background.static <E,C extends JComboBox<E>>
UIForCombo<E, C> of(C component) static <D extends JDialog>
UIForJDialog<D> of(D dialog) This returns an instance of a SwingTree builder for aJDialogtype.static <F extends JTextField>
UIForTextField<F> of(F component) Use this to create a builder for the providedJTextFieldinstance.static <H extends UI.TableHeader>
UIForTableHeader<H> of(H header) Allows you to wrap a customJTableHeadertype in a declarative SwingTree UI builder.of(I icon) Use this to create a builder for the providedJIconinstance.static UIForFormattedTextFieldof(JFormattedTextField component) Use this to create a builder for the providedJFormattedTextFieldinstance.Use this to create a builder for a concreteJListcomponent type instance.static <L extends JLabel>
UIForLabel<L> of(L label) Use this to create a builder for the providedJLabelinstance.of(M component) Use this to create a builder for the providedJMenuinstance.static <P extends JPanel>
UIForPanel<P> of(P component) Use this to create a builder for the providedJPaneltype.static <R extends JRadioButton>
UIForRadioButton<R> of(R component) Use this to create a builder for the providedJRadioButtoninstance.static <S extends JSeparator>
UIForSeparator<S> of(S separator) This returns an instance of aUIForSeparatorbuilder responsible for building aJSeparatorby exposing helpful utility methods for it.static <M extends JMenuItem>
UIForMenuItem<M> of(MenuBuilder<M> builder) If you are using builders for customJMenuItemcomponents, implement this to allow theUIAPI to call theSwingBuilder.build()method for you.static <T extends JComponent>
UIForSwing<T> of(SwingBuilder<T> builder) If you are using builders for your customJComponent, implement this to allow theUIAPI to call theSwingBuilder.build()method for you.static <T extends JComponent>
UIForSwing<T> of(T component) This returns an instance of a generic swing tree builder for anything extending theJComponentclass.static UIForPanel<JPanel> panel()Use this to create a builder for a newJPanelUI component with aMigLayoutas its layout manager.static UIForPanel<JPanel> Use this to create a builder for theJPanelUI component.static UIForPanel<JPanel> Use this to create a builder for theJPanelUI component.static UIForPanel<JPanel> Use this to create a builder for a newJPanelUI component with aMigLayoutas its layout manager and the provided constraints.static UIForPanel<JPanel> panel(net.miginfocom.layout.LC attr) Use this to create a builder for theJPanelUI component.static UIForPanel<JPanel> Use this to create a builder for a newJPanelUI component with aMigLayoutas its layout manager and the provided constraints.static UIForPanel<JPanel> Use this to create a builder for a newJPanelUI component with aMigLayoutas its layout manager and the provided constraints.static UIForPanel<JPanel> panel(sprouts.Val<LayoutConstraint> attr) Use this to create a builder for theJPanelUI component with a dynamically updated set ofMigLayoutconstraints/attributes.static UIForPanel<JPanel> panel(LayoutConstraint attr) Use this to create a builder for theJPanelUI component.static UIForPanel<JPanel> panel(LayoutConstraint attr, String colConstraints) Use this to create a builder for theJPanelUI component.static UIForPanel<JPanel> panel(LayoutConstraint attr, String colConstraints, String rowConstraints) Use this to create a builder for a newJPanelUI component with aMigLayoutas its layout manager and the provided constraints.static UIForPasswordField<JPasswordField> Use this to create a builder for a newJPasswordFieldUI component.static UIForPasswordField<JPasswordField> passwordField(String text) Use this to create a builder for a newJPasswordFieldinstance with the provided text as the initial password.static UIForPasswordField<JPasswordField> passwordField(sprouts.Val<String> text) Use this to create a builder for a newJPasswordFieldinstance with the provided text property dynamically displaying its value in the password field.static UIForPasswordField<JPasswordField> passwordField(sprouts.Var<String> text) Use this to create a builder for a newJPasswordFieldinstance with the provided text property dynamically displaying its value in the password field.static UIForPopup<JPopupMenu> Use this to create a swing tree builder node for theJPopupMenuUI component.static UIForProgressBar<JProgressBar> A factory method for creating a progress bar builder with a defaultJProgressBarimplementation.static UIForProgressBar<JProgressBar> progressBar(int min, int max) Use this to create a builder for a newJProgressBarinstance with the provided minimum and maximum values.static UIForProgressBar<JProgressBar> progressBar(int min, int max, int value) Use this to create a builder for a newJProgressBarinstance with the provided minimum, maximum and current value.static UIForProgressBar<JProgressBar> progressBar(int min, int max, sprouts.Val<Integer> value) Use this to create a builder for a newJProgressBarinstance with the provided minimum, maximum and current value property dynamically bound to the progress bar.static UIForProgressBar<JProgressBar> progressBar(sprouts.Val<UI.Align> align, sprouts.Val<Double> progress) Use this to create a builder for a newJProgressBarinstance with a default minimum and maximum value of 0 and 100 and the provided alignment property and double based progress property (a property wrapping a double value between 0 and 1) dynamically bound to the progress bar.static UIForProgressBar<JProgressBar> progressBar(UI.Align align, double progress) Use this to create a builder for a newJProgressBarinstance with a default minimum and maximum value of 0 and 100 and the provided alignment and double based progress property (a property wrapping a double value between 0 and 1) dynamically bound to the progress bar.static UIForProgressBar<JProgressBar> progressBar(UI.Align align, int min, int max) Use this to create a builder for a newJProgressBarinstance with the provided alignment, minimum and maximum values.static UIForProgressBar<JProgressBar> progressBar(UI.Align align, int min, int max, int value) Use this to create a builder for a newJProgressBarinstance with the provided alignment, minimum, maximum and current value.static UIForProgressBar<JProgressBar> progressBar(UI.Align align, int min, int max, sprouts.Val<Integer> value) Use this to create a builder for a newJProgressBarinstance with the provided alignment, minimum, maximum and current value property dynamically bound to the progress bar.static UIForProgressBar<JProgressBar> progressBar(UI.Align align, sprouts.Val<Double> progress) Use this to create a builder for a newJProgressBarinstance with a default minimum and maximum value of 0 and 100 and the provided alignment and double based progress property (a property wrapping a double value between 0 and 1) dynamically bound to the progress bar.static <E extends Enum<E>>
UIForRadioButton<JRadioButton> radioButton(E state, sprouts.Var<E> selection) Creates a builder node wrapping a newJRadioButtoninstance dynamically bound to an enum basedVarinstance which will be used to dynamically model the selection state of the wrappedJToggleButtontype by checking weather the property matches the provided enum or not.static UIForRadioButton<JRadioButton> radioButton(String text) Creates a builder node wrapping a newJRadioButtoninstance with the provided text displayed on it.static UIForRadioButton<JRadioButton> radioButton(String text, sprouts.Var<Boolean> selected) Creates a builder node wrapping a newJRadioButtoninstance with the provided text displayed on it and the provided selection property dynamically determining whether the radio button is selected or not.static <T> UIForRadioButton<JRadioButton> radioButton(String label, T state, sprouts.Var<T> selection) Creates a declarative UI builder for theJRadioButtoncomponent type which is dynamically bound to the equality of the provided state and the provided selection property.static UIForRadioButton<JRadioButton> radioButton(sprouts.Val<String> text) Creates a builder node wrapping a newJRadioButtoninstance where the provided text property dynamically displays its value on the radio button.static UIForRadioButton<JRadioButton> radioButton(sprouts.Val<String> text, sprouts.Var<Boolean> selected) Creates a builder node wrapping a newJRadioButtoninstance where the provided text property dynamically displays its value on the radio button and the provided selection property dynamically determines whether the radio button is selected or not.A factory method to create a plainJRadioButtonMenuIteminstance.static <E extends Enum<E>>
UIForRadioButtonMenuItem<JRadioButtonMenuItem> radioButtonMenuItem(E state, sprouts.Var<E> property) A factory method to create aJRadioButtonMenuItembound to a fixed enum value and a variable enum property which will dynamically select the menu item based on the equality of the fixed enum value and the variable enum property value.radioButtonMenuItem(String text) A factory method to create aJRadioButtonMenuItemwith the provided text displayed on the menu button.radioButtonMenuItem(String text, Icon icon) A factory method to create aJRadioButtonMenuItemwith the provided text displayed on the menu button and the provided icon displayed on the menu button.radioButtonMenuItem(String text, sprouts.Var<Boolean> isSelected) A factory method to create aJRadioButtonMenuItemwith some custom text and a boolean property, dynamically determining whether the radio-button-based menu item is selected or not.radioButtonMenuItem(sprouts.Val<String> text) A factory method to create aJRadioButtonMenuItembound to the provided text property, whose value will be displayed on the menu button dynamically.radioButtonMenuItem(sprouts.Val<String> text, Icon icon) A factory method to create aJRadioButtonMenuItembound to the provided text property, whose value will be displayed on the menu button dynamically and the provided icon displayed on the menu button.radioButtonMenuItem(sprouts.Val<String> text, sprouts.Var<Boolean> isSelected) A factory method to create aJRadioButtonMenuItemwith some custom text and a boolean property, dynamically determining whether the radio-button-based menu item is selected or not.static @Nullable IconscaleIconTo(Size size, @Nullable Icon icon) static UIForScrollPane<JScrollPane> Use this to create a builder for a newJScrollPaneUI component.static UIForScrollPane<JScrollPane> scrollPane(Configurator<ScrollableComponentDelegate> configurator) Allows you to create a declarative builder for theJScrollPanecomponent type, where you can also configure how the contained component should behave in the scroll pane viewport through aConfiguratorlambda.static UIForScrollPanels<JScrollPanels> Use this to create a builder for a newJScrollPanelsUI component.static UIForScrollPanels<JScrollPanels> scrollPanels(UI.Align align) Use this to create a builder for a newJScrollPanelsUI component.static UIForScrollPanels<JScrollPanels> scrollPanels(UI.Align align, Dimension size) Use this to create a builder for a newJScrollPanelsUI component.static UIForSeparator<JSeparator> This returns an instance of aUIForSeparatorbuilder responsible for building aJSeparatorby exposing helpful utility methods for it.static UIForSeparator<JSeparator> Use this to create a swing tree builder node for theJSeparatorwhose alignment is dynamically determined based on a provided property.static UIForSeparator<JSeparator> This returns an instance of aUIForSeparatorbuilder responsible for building aJSeparatorby exposing helpful utility methods for it.static voidUse this to quickly launch a UI component in aJFramewindow at the center of the screen.
Warning: This method should only be invoked from the Event Dispatch Thread (EDT).static voidUse this to quickly launch a UI component in a titledJFramewindow at the center of the screen.
Warning: This method should only be invoked from the Event Dispatch Thread (EDT).static voidstatic <C extends JComponent>
voidshow(String title, UIForAnySwing<?, C> ui) Use this to quickly launch a UI component in a titledJFramewindow at the center of the screen.static voidstatic <C extends JComponent>
voidshow(UIForAnySwing<?, C> ui) Use this to quickly launch a UI component in aJFramewindow at the center of the screen.static voidUse this to quickly launch a UI component with a custom event processor in a titledJFramewindow at the center of the screen.static voidshowUsing(EventProcessor eventProcessor, Function<JFrame, Component> uiSupplier) Use this to quickly launch a UI component with a custom event processor inJFramewindow at the center of the screen.static UIForSlider<JSlider> Use this to create a builder for a newJSliderinstance based on the provided alignment property which dynamically determines if the property is aligned vertically or horizontally.static UIForSlider<JSlider> Use this to create a builder for a newJSliderinstance based on tbe provided alignment type determining if the slider will be aligned vertically or horizontally.static UIForSlider<JSlider> Use this to create a builder for a newJSliderinstance based on tbe provided alignment type, min slider value and max slider value.static UIForSlider<JSlider> Creates a slider with the specified alignment and the specified minimum, maximum, and initial values.static <N extends Number>
UIForSlider<JSlider> Creates a slider with the specified alignment and the specified minimum, maximum, and dynamic value.static <N extends Number>
UIForSlider<JSlider> Creates a slider with the specified alignment and the specified minimum, maximum, and dynamic value property.static <N extends Number>
UIForSlider<JSlider> Creates a slider with the specified alignment and the specified minimum, maximum, and value property views.static <N extends Number>
UIForSlider<JSlider> Creates a slider with the specified alignment and the specified minimum, maximum, and value property views.static UIForSpinner<JSpinner> spinner()Use this to create a builder for a newJSpinnerUI component.static UIForSpinner<JSpinner> spinner(int value, int min, int max) Use this to create a builder for the providedJSpinnerinstance with the providedmin,maxand defaultvalueas the model.static UIForSpinner<JSpinner> spinner(int value, int min, int max, int step) Use this to create a builder for the providedJSpinnerinstance with the providedmin,max, defaultvalueandstepas the model.static UIForSpinner<JSpinner> spinner(SpinnerModel model) Use this to create a builder for the providedJSpinnerinstance with the providedSpinnerModelas the model.static UIForSpinner<JSpinner> spinner(sprouts.Var<?> value) Use this factory method to create aJSpinnerbound to a property of any type.static UIForSplitButton<JSplitButton> splitButton(String text) Use this to buildJSplitButtons with custom text displayed ont top.static <E extends Enum<E>>
UIForSplitButton<JSplitButton> splitButton(sprouts.Var<E> selection) Use this to buildJSplitButtons where the selectable options are represented by anEnumtype.static <E extends Enum<E>>
UIForSplitButton<JSplitButton> splitButton(sprouts.Var<E> selection, Function<E, String> labelProvider) Use this to buildJSplitButtons where the selectable options are represented by anEnumtype.static <E extends Enum<E>>
UIForSplitButton<JSplitButton> splitButton(sprouts.Var<E> selection, sprouts.Event clickEvent) Use this to buildJSplitButtons where the selectable options are represented by anEnumtype, and the click event is handles by anEventinstance.static <E extends Enum<E>>
UIForSplitButton<JSplitButton> splitButton(sprouts.Var<E> selection, sprouts.Event clickEvent, Function<E, String> labelProvider) Use this to buildJSplitButtons where the selectable options are represented by anEnumtype, and the click event is handles by anEventinstance.Use this to add entries to theJSplitButtonby passingSplitIteminstances toUIForSplitButtonbuilder like so:Use this to add property-bound entries to theJSplitButtonby passingSplitIteminstances toUIForSplitButtonbuilder like so:static UIForSplitPane<JSplitPane> Use this to create a builder for a newJSplitPaneinstance based on the provided alignment property determining how the split itself should be aligned.static UIForSplitPane<JSplitPane> Use this to create a builder for a newJSplitPaneinstance based on the provided alignment enum determining how the split itself should be aligned.static SplitItem<JRadioButtonMenuItem> splitRadioItem(String text) Use this to add radio item entries to theJSplitButtonby passingSplitIteminstances toUIForSplitButtonbuilder like so:static Tabstatic Tabtab(JComponent component) static TabA factory method producing aTabinstance with the providedtitleproperty which can dynamically change the title of the tab button.static Tabtab(UIForAnySwing<?, ?> builder) static UIForTabbedPane<JTabbedPane> Use this to create a builder for a newJTabbedPaneUI component.static UIForTabbedPane<JTabbedPane> tabbedPane(sprouts.Val<Integer> selectedIndex) Use this to create a builder for a newJTabbedPaneUI component with the providedselectedIndexproperty which should be determined the tab selection of theJTabbedPanedynamically.static UIForTabbedPane<JTabbedPane> tabbedPane(sprouts.Var<Integer> selectedIndex) Use this to create a builder for a newJTabbedPaneUI component with the providedselectedIndexproperty which should determine the tab selection of theJTabbedPanedynamically.static UIForTabbedPane<JTabbedPane> tabbedPane(UI.OverflowPolicy tabsPolicy) Use this to create a builder for a newJTabbedPaneUI component with the providedUI.OverflowPolicyapplied to the tab buttons (seeJTabbedPane.setTabLayoutPolicy(int)).static UIForTabbedPane<JTabbedPane> tabbedPane(UI.Side tabsSide) Use this to create a builder for a newJTabbedPaneUI component with the providedUI.Sideapplied to the tab buttons (seeJTabbedPane.setTabLayoutPolicy(int)).static UIForTabbedPane<JTabbedPane> tabbedPane(UI.Side tabsSide, UI.OverflowPolicy tabsPolicy) Use this to create a builder for a newJTabbedPaneUI component with the providedUI.OverflowPolicyandUI.Sideapplied to the tab buttons (seeJTabbedPane.setTabLayoutPolicy(int)andJTabbedPane.setTabPlacement(int)).static UIForTable<JTable> table()Creates a declarative UI builder for theJTablecomponent type.static <T> UIForTable<JTable> table(Class<T> itemType, Configurator<BasicTableModel.Builder<T>> tableModelBuildable) Creates a newJTableinstance builder with the provided table model configuration as a basis for creating the table model in a declarative fashion.static UIForTable<JTable> table(Configurator<BasicTableModel.Builder<Object>> tableModelBuildable) Creates a newJTableinstance builder with the provided table model configuration as a basis for creating the table model in a declarative fashion.static <E> UIForTable<JTable> table(UI.ListData dataFormat, TableListDataSource<E> dataSource) static <E> UIForTable<JTable> table(UI.MapData dataFormat, TableMapDataSource<E> dataSource) Use this to create a newJTablewith a table model whose data can be represented based on a map of column names to lists of table entries (basically a column major matrix).static UIForTableHeader<UI.TableHeader> Allows you to create a declarative builder for theJTableHeaderUI component.static UIForTextArea<JTextArea> Use this to create a builder for a newJTextAreainstance with the provided text as the initial text.static UIForTextArea<JTextArea> Use this to create a builder for a newJTextAreainstance with the provided text property dynamically displaying its value in the text area.static UIForTextArea<JTextArea> Use this to create a builder for a newJTextAreainstance with the provided text property dynamically displaying its value in the text area.static UIForTextField<JTextField> Use this to create a builder for a newJTextFieldUI component.static UIForTextField<JTextField> Use this to create a builder for a newJTextFieldinstance with the provided text displayed on it.static UIForTextField<JTextField> Use this to create a builder for a newJTextFieldinstance with the provided text property dynamically displaying its value on the text field.static UIForTextField<JTextField> Use this to create a builder for a newJTextFieldinstance with the provided text property dynamically displaying its value on the text field.static UIForTextField<JTextField> textField(UI.HorizontalAlignment direction) A convenience method for creating a builder for aJTextFieldwith the specifiedUI.HorizontalAlignmentconstant as the text orientation.static UIForTextField<JTextField> textField(UI.HorizontalAlignment orientation, String text) A convenience method for creating a builder for aJTextFieldwith the specified text and text orientation.static UIForTextField<JTextField> textField(UI.HorizontalAlignment orientation, sprouts.Val<String> text) Creates a UI builder for a text field where the text is aligned according to the providedUI.HorizontalAlignmentconstant, and the text of the text field is uni-directionally bound to a string property.static UIForTextField<JTextField> textField(UI.HorizontalAlignment textOrientation, sprouts.Var<String> text) Creates a UI builder for a text field where the text is aligned according to the providedUI.HorizontalAlignmentconstant, and the text of the text field is bound to a string property.static UIForTextPane<JTextPane> textPane()Use this to create a builder for a newJTextPaneUI component.static UIForToggleButton<JToggleButton> Use this to create a builder for aJToggleButtoninstance.static UIForToggleButton<JToggleButton> toggleButton(int width, int height, ImageIcon icon) Use this to create a builder for theJToggleButtonUI component with an icon displayed on it scaled according to the provided width and height.static UIForToggleButton<JToggleButton> toggleButton(int width, int height, IconDeclaration icon) Use this to create a builder for theJToggleButtonUI component with an icon displayed on it scaled according to the provided width and height.static UIForToggleButton<JToggleButton> toggleButton(int width, int height, IconDeclaration icon, UI.FitComponent fit) Creates a declarative toggle button builder for aJToggleButtondisplaying the provided icon scaled to fit the desired size andUI.FitComponentpolicy.static UIForToggleButton<JToggleButton> toggleButton(String text) Use this to create a builder for a newJToggleButtoninstance with the provided text displayed on it.static UIForToggleButton<JToggleButton> toggleButton(String text, sprouts.Var<Boolean> isToggled) Use this to create a builder for a newJToggleButtoninstance with the provided text displayed on it and the provided boolean property dynamically determining whether the toggle button is selected or not.static UIForToggleButton<JToggleButton> toggleButton(Icon icon) Use this to create a builder for a newJToggleButtoninstance with the providedIcondisplayed on it.static UIForToggleButton<JToggleButton> toggleButton(Icon icon, sprouts.Var<Boolean> isToggled) Use this to create a builder for a newJToggleButtoninstance with the providedIcondisplayed on it and the provided boolean property dynamically determining whether the toggle button is selected or not.static UIForToggleButton<JToggleButton> toggleButton(ImageIcon icon, UI.FitComponent fit) Use this to create a builder for a newJToggleButtoninstance with anImageIcondisplayed on it and the suppliedUI.FitComponentdetermining how the icon should be fit the content bounds of the button.static UIForToggleButton<JToggleButton> toggleButton(sprouts.Val<String> text) Use this to create a builder for a newJToggleButtoninstance where the provided text property dynamically displays its value on the toggle button.static UIForToggleButton<JToggleButton> toggleButton(sprouts.Val<String> text, sprouts.Var<Boolean> isToggled) Use this to create a builder for a newJToggleButtoninstance where the provided text property dynamically displays its value on the toggle button and the provided boolean property dynamically determines whether the toggle button is selected or not.static UIForToggleButton<JToggleButton> toggleButton(sprouts.Var<Boolean> isToggled) Use this to create a builder for a newJToggleButtoninstance where the provided boolean property dynamically determines whether the toggle button is selected or not.static UIForToggleButton<JToggleButton> toggleButton(IconDeclaration icon) Use this to create a builder for a newJToggleButtoninstance with the icon found at the path provided by the suppliedIconDeclarationdisplayed on top of it.static UIForToggleButton<JToggleButton> toggleButton(IconDeclaration icon, UI.FitComponent fit) static UIForToggleButton<JToggleButton> toggleButtonWithIcon(sprouts.Val<IconDeclaration> icon) Use this to create a builder for a newJToggleButtoninstance where the providedIconDeclarationbased property dynamically displays the targeted image on the toggle button.static UIForToggleButton<JToggleButton> toggleButtonWithIcon(sprouts.Val<IconDeclaration> icon, sprouts.Var<Boolean> isToggled) Use this to create a builder for a newJToggleButtoninstance where the providedIconDeclarationproperty dynamically displays its targeted icon on the toggle button and the provided boolean property dynamically determines whether the toggle button is selected or not.static UIForToolBar<JToolBar> toolBar()Use this to create a builder for a newJToolBarinstance.static UIForToolBar<JToolBar> static UIForToolBar<JToolBar> static <T> Tuse(StyleSheet styleSheet, Supplier<T> scope) Sets aStyleSheetwhich will be applied to all SwingTree UIs defined in the subsequent lambda scope.static <T> Tuse(EventProcessor processor, Supplier<T> scope) Sets theEventProcessorto be used for all subsequent UI building operations.static voidShows a warning dialog with the given message.static voidShows a warning dialog with the given message and dialog title.Methods inherited from class swingtree.UILayoutConstants
AC, ALIGN, AUTO_SPAN, AUTO_SPAN, CC, DOCK, GAP_BOTTOM, GAP_LEFT, GAP_REL, GAP_RIGHT, GAP_TOP, GROW, GROW_X, GROW_Y, HEIGHT, INS, INS, INSETS, INSETS, LC, PAD, PAD, PUSH, PUSH_X, PUSH_Y, SHRINK, SHRINK_PRIO, SHRINK_X, SHRINK_Y, SKIP, SPAN, SPAN, SPAN_X, SPAN_Y, SPLIT, WIDTH, WRAP
-
Constructor Details
-
UIFactoryMethods
public UIFactoryMethods()
-
-
Method Details
-
color
Creates a newColorobject from the specified red, green and blue values.- Parameters:
r- The red value (0-255).g- The green value (0-255).b- The blue value (0-255).- Returns:
- The new color.
-
color
Creates a newColorobject from the specified red, green, blue and alpha values.- Parameters:
r- The red value (0-255).g- The green value (0-255).b- The blue value (0-255).a- The alpha value (0-255).- Returns:
- The new color.
-
color
Creates a newColorobject from the specified red, green and blue values.- Parameters:
r- The red value (0.0-1.0).g- The green value (0.0-1.0).b- The blue value (0.0-1.0).- Returns:
- The new color.
-
color
Creates a newColorobject from the specified red, green, blue and alpha values.- Parameters:
r- The red value (0.0-1.0).g- The green value (0.0-1.0).b- The blue value (0.0-1.0).a- The alpha value (0.0-1.0).- Returns:
- The new color.
-
color
Tries to parse the supplied string as a color value based on various formats.- Parameters:
colorAsString- The string to parse.- Returns:
- The parsed color.
- Throws:
IllegalArgumentException- If the string could not be parsed.NullPointerException- If the string is null.
-
font
Returns theUI.Fontthat thefontStringargument describes. To ensure that this method returns the desired Font, format thefontStringparameter in one of these ways:- fontname-style-pointsize
- fontname-pointsize
- fontname-style
- fontname
- fontname style pointsize
- fontname pointsize
- fontname style
- fontname
"PLAIN","BOLD","BOLDITALIC", or"ITALIC", andpointsizeis a positive decimal integer representation of the point size. For example, if you want a font that is Arial, bold, with a point size of 18, you would call this method with: "Arial-BOLD-18". This is equivalent to calling the Font constructor :new Font("Arial", Font.BOLD, 18);and the values are interpreted as specified by that constructor.A valid trailing decimal field is always interpreted as the pointsize. Therefore, a
fontnamecontaining a trailing decimal value should not be used in thefontnameonly form.If a style name field is not one of the valid style strings, it is interpreted as part of the font name, and the default style is used.
Only one of ' ' or '-' may be used to separate fields in the input. The identified separator is the one closest to the end of the string, which separates a valid pointsize, or a valid style name from the rest of the string. Null (empty) pointsize and style fields are treated as valid fields with the default value for that field.
Some font names may include the separator characters ' ' or '-'. If
fontStringis not formed with 3 components, e.g. such thatstyleorpointsizefields are not present infontString, andfontnamealso contains a character determined to be the separator character then these characters where they appear as intended to be part offontnamemay instead be interpreted as separators so the font name may not be properly recognized.The default size is 12 and the default style is PLAIN. If
strdoes not specify a valid size, the returnedFonthas a size of 12. IffontStringdoes not specify a valid style, the returned Font has a style of PLAIN. If you do not specify a valid font name in thefontStringargument, this method will return a font with the family name "Dialog". To determine what font family names are available on your system, use theGraphicsEnvironment.getAvailableFontFamilyNames()method. IffontStringisnull, a newFontis returned with the family name "Dialog", a size of 12 and a PLAIN style.- Parameters:
fontString- the name of the font, ornull- Returns:
- the
Fontobject thatfontStringdescribes. - Throws:
NullPointerException- iffontStringisnull
-
of
This returns an instance of a generic swing tree builder for anything extending theJComponentclass.- Type Parameters:
T- The concrete type of this new component.- Parameters:
component- The new component instance which ought to be part of the Swing UI.- Returns:
- A basic UI builder instance wrapping any
JComponent.
-
of
Use this to create a builder for the providedJPaneltype.
This method is typically used to enable declarative UI design for customJPanelbased components either within the constructor of a custom subclass, like so:
class MyCustomPanel extends JPanel { public MyCustomPanel() { UI.of(this) .add(UI.label("Hello Swing!")) .add(UI.button("Click Me")) .add(UI.button("Or Me") ); } }
... or as part of a UI declaration, where the customJPaneltype is added to the components tree, like so:
UI.show( UI.panel() .add( new MyCustomPanel() ) .add(..more stuff..) );- Type Parameters:
P- The type parameter of the concreteJPaneltype to be wrapped.- Parameters:
component- TheJPanelinstance to be wrapped by a swing tree UI builder for panel components.- Returns:
- A builder instance for the provided
JPanel, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
panel
Use this to create a builder for a newJPanelUI component with aMigLayoutas its layout manager. This is in essence a convenience method forUI.of(new JPanel(new MigLayout())).- Returns:
- A builder instance for a new
JPanel, which enables fluent method chaining.
-
panel
Use this to create a builder for theJPanelUI component. This is essentially a convenience method for the following:
UI.of(new JPanel(new MigLayout(attr)))- Parameters:
attr- The layout attributes which will be passed to theMigLayoutconstructor as first argument.- Returns:
- A builder instance for a new
JPanel, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifattrisnull.- See Also:
-
panel
Use this to create a builder for theJPanelUI component. This is essentially a convenience method for the following:
UI.of(new JPanel(new MigLayout(attr, colConstraints)))- Parameters:
attr- The layout attributes which will be passed to theMigLayoutconstructor as first argument.colConstraints- The layout which will be passed to theMigLayoutconstructor as second argument.- Returns:
- A builder instance for a new
JPanel, which enables fluent method chaining. - See Also:
-
panel
Use this to create a builder for a newJPanelUI component with aMigLayoutas its layout manager and the provided constraints. This is essentially a convenience method for the following:
UI.of(new JPanel(new MigLayout(attr, colConstraints, rowConstraints)))- Parameters:
attr- The layout attributes.colConstraints- The column constraints.rowConstraints- The row constraints.- Returns:
- A builder instance for a new
JPanel, which enables fluent method chaining. - See Also:
-
panel
Use this to create a builder for theJPanelUI component. This is in essence a convenience method forUI.of(new JPanel()).withLayout(attr).- Parameters:
attr- The layout attributes which will be passed to theMigLayoutconstructor as first argument.- Returns:
- A builder instance for a new
JPanel, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifattrisnull.- See Also:
-
panel
Use this to create a builder for theJPanelUI component. This is essentially a convenience method for the following:
UI.of(new JPanel(new MigLayout(attr, colConstraints)))- Parameters:
attr- The layout attributes which will be passed to theMigLayoutconstructor as first argument.colConstraints- The layout which will be passed to theMigLayoutconstructor as second argument.- Returns:
- A builder instance for a new
JPanel, which enables fluent method chaining. - See Also:
-
panel
public static UIForPanel<JPanel> panel(LayoutConstraint attr, String colConstraints, String rowConstraints) Use this to create a builder for a newJPanelUI component with aMigLayoutas its layout manager and the provided constraints. This is essentially a convenience method for the following:
UI.of(new JPanel(new MigLayout(attr, colConstraints, rowConstraints)))- Parameters:
attr- The layout attributes in the form of aLayoutConstraintconstants.colConstraints- The column constraints.rowConstraints- The row constraints.- Returns:
- A builder instance for a new
JPanel, which enables fluent method chaining. - See Also:
-
panel
Use this to create a builder for theJPanelUI component. This is in essence a convenience method forUI.of(new JPanel()).withLayout(attr).
This method is typiclly used alongside theUILayoutConstants.LC()factory method to create a layout attributes/constraints builder, like so:
UI.panel( UI.LC() .insets("10 10 10 10") .debug() ) .add(..) .add(..)- Parameters:
attr- The constraint attributes concerning the entireMigLayoutin the form of aLCinstance.- Returns:
- A builder instance for a new
JPanel, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifattrisnull.- See Also:
-
panel
Use this to create a builder for a newJPanelUI component with aMigLayoutas its layout manager and the provided constraints. This is essentially a convenience method for the following:
UI.of(new JPanel(new MigLayout(attr, ConstraintParser.parseColumnConstraints(colConstraints)))) -
panel
public static UIForPanel<JPanel> panel(net.miginfocom.layout.LC attr, String colConstraints, String rowConstraints) Use this to create a builder for a newJPanelUI component with aMigLayoutas its layout manager and the provided constraints. This is essentially a convenience method for the following:
UI.of(new JPanel( new MigLayout( attr, ConstraintParser.parseColumnConstraints(colConstraints), ConstraintParser.parseRowConstraints(rowConstraints) ) ))- Parameters:
attr- The layout attributes in the form of aLCinstance.colConstraints- The column constraints in the form of aStringinstance.rowConstraints- The row constraints in the form of aStringinstance.- Returns:
- A builder instance for a new
JPanel, which enables fluent method chaining. - See Also:
-
panel
Use this to create a builder for theJPanelUI component with a dynamically updated set ofMigLayoutconstraints/attributes. This is in essence a convenience method forUI.of(new JPanel()).withLayout(attr).- Parameters:
attr- The layout attributes property which will be passed to theMigLayoutconstructor as first argument.- Returns:
- A builder instance for a new
JPanel, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifattrisnull.- See Also:
-
of
Use this to create a builder for the providedJBoxinstance, which is a general purpose component wrapper type with the following properties:- It is transparent, meaning that it does not paint its background.
-
The default layout manager is a
MigLayout. - The insets (the space between the wrapped component and the box's border) are set to zero.
- There the gap size between the components added to the box is set to zero. So they will be tightly packed.
JBoxtype is in no way related to theBoxLayout! The term box is referring to the purpose of this component, which is to tightly store and wrap other sub-components seamlessly...This method is typically used to enable declarative UI design for custom
JBoxbased components either within the constructor of a custom subclass, like so:
class MyCustomBox extends JBox { public MyCustomBox() { UI.of(this) .add(UI.label("Hello Swing!")) .add(UI.button("Click Me")) .add(UI.button("Or Me") ); } }
... or as part of a UI declaration, where the customJBoxtype is added to the component tree, like so:
UI.show( UI.panel() .add( new MyCustomBox() ) .add(..more stuff..) );- Type Parameters:
B- THe type parameter defining the concreteJBoxtype.- Parameters:
component- The box component type for which a builder should be created.- Returns:
- A builder for the provided box component.
- Throws:
IllegalArgumentException- ifcomponentisnull.
-
box
Use this to create a builder for aJBoxinstance, which is a general purpose component wrapper type with the following properties:- It is transparent, meaning that it does not paint its background.
-
The default layout manager is a
MigLayout. - The insets (the spaces between the wrapped component and the box's border) are all set to zero.
- The gap sizes between the components added to the box is set to zero. So the children of this component will be tightly packed.
JBoxtype is in no way related to theBoxLayout! The term box is referring to the purpose of this component, which is to tightly store and wrap other sub-components seamlessly...This factory method is especially useful for when you simply want to nest components tightly without having to worry about the layout manager or the background color covering the background of the parent component.
Note that you can also emulate theJBoxtype with aJPanelusingUI.panel("ins 0, gap 0").makeNonOpaque().- Returns:
- A builder instance for a new
JBox, which enables fluent method chaining.
-
box
Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager. This is conceptually the same as a transparentJPanelwithout any insets and aMigLayoutconstructed using the provided constraints.- Parameters:
attr- The layout attributes which will be passed to theMigLayoutconstructor as first argument.- Returns:
- A builder instance for a new
JBox, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifattrisnull.- See Also:
-
box
Use this to create a builder for aJBox, conceptually the same as a transparentJPanelwithout any insets and aMigLayoutconstructed using the provided constraints.
Please note that theJBoxtype is in no way related to theBoxLayout! The term box is referring to the purpose of this component, which is to tightly store and wrap other sub-components seamlessly...- Parameters:
attr- The layout attributes which will be passed to theMigLayoutconstructor as first argument.colConstraints- The layout which will be passed to theMigLayoutconstructor as second argument.- Returns:
- A builder instance for a transparent
JBox, which enables fluent method chaining. - See Also:
-
box
Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager. This factory method is especially useful for when you simply want to nest components tightly without having to worry about the layout manager or the background color covering the background of the parent component.
Note that you can also emulate theJBoxtype with aJPanelusingUI.panel(attr, colConstraints, rowConstraints).makeNonOpaque()
Please note that theJBoxtype is in no way related to theBoxLayout! The term box is referring to the purpose of this component, which is to tightly store and wrap other sub-components seamlessly...- Parameters:
attr- The layout attributes.colConstraints- The column constraints.rowConstraints- The row constraints.- Returns:
- A builder instance for a new
JBox, which enables fluent method chaining. - See Also:
-
box
Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager. This is conceptually the same as a transparentJPanelwithout any insets and aMigLayoutconstructed using the provided constraints.
Please note that theJBoxtype is in no way related to theBoxLayout! The term box is referring to the purpose of this component, which is to tightly store and wrap other subcomponents seamlessly...
This method allows you to pass aLayoutConstraintconstants as the layout attributes, which is an instance typically chosen from theUIclass constants like for exampleUILayoutConstants.FILL,UILayoutConstants.FILL_X,UILayoutConstants.FILL_Y...
A typical usage example would be:
In this code snippet the creates aUI.box(UI.FILL_X.and(UI.WRAP(2))) .add(..) .add(..)JBoxwith aMigLayoutas its layout manager where the box will fill the parent component horizontally and the components added to the box will be wrapped after every two components.- Parameters:
attr- The layout attributes which will be passed to theMigLayoutconstructor as first argument.- Returns:
- A builder instance for a transparent
JBox, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifattrisnull.- See Also:
-
box
Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager. This is conceptually the same as a transparentJPanelwithout any insets and aMigLayoutconstructed using the provided constraints.
Please note that theJBoxtype is in no way related to theBoxLayout! The term box is referring to the purpose of this component, which is to tightly store and wrap other subcomponents seamlessly...This method allows you to pass a
LayoutConstraintconstants as the layout attributes, which is an instance typically chosen from theUIclass constants like for exampleUILayoutConstants.FILL,UILayoutConstants.FILL_X,UILayoutConstants.FILL_Y...
A typical usage example would be:
In this code snippet that creates aUI.box(UI.FILL, "[shrink]6[grow]") .add(..) .add(..)JBoxwith aMigLayoutas its layout manager where the box will fill the parent component horizontally and vertically and the first column of components will be shrunk to their preferred size and the second column will grow to fill the available space. Both columns will have a gap of 6 pixels between them.- Parameters:
attr- The layout attributes which will be passed to theMigLayoutconstructor as first argument.colConstraints- The layout which will be passed to theMigLayoutconstructor as second argument.- Returns:
- A builder instance for a transparent
JBox, which enables fluent method chaining. - See Also:
-
box
public static UIForBox<JBox> box(LayoutConstraint attr, String colConstraints, String rowConstraints) Use this to create a builder for aJBox, conceptually the same as a transparentJPanelwithout any insets and aMigLayoutconstructed using the provided constraints. This is essentially a convenience method for the following:
UI.of(new JBox(new MigLayout(attr, colConstraints, rowConstraints)))
Please note that theJBoxtype is in no way related to theBoxLayout! The term box is referring to the purpose of this component, which is to tightly store and wrap other subcomponents seamlessly...- Parameters:
attr- The layout attributes in the form of aLayoutConstraintconstants.colConstraints- The column constraints.rowConstraints- The row constraints.- Returns:
- A builder instance for a transparent
JBox, which enables fluent method chaining. - See Also:
-
box
Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager.
Please note that theJBoxtype is in no way related to theBoxLayout! The term box is referring to the purpose of this component, which is to tightly store and wrap other sub-components seamlessly...- Parameters:
attr- The layout attributes which will be passed to theMigLayoutconstructor as first argument.- Returns:
- A builder instance for a transparent
JBox, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifattrisnull.- See Also:
-
box
Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager. This is conceptually the same as a transparentJPanelwithout any insets and aMigLayoutconstructed using the provided constraints. This is essentially a convenience method that can also be expressed as:
UI.of(new JBox(new MigLayout(attr, colConstraints)))
Please note that theJBoxtype is in no way related to theBoxLayout! The term box is referring to the purpose of this component, which is to tightly store and wrap other subcomponents seamlessly...- Parameters:
attr- The layout attributes in the form of aLayoutConstraintconstants.colConstraints- The column constraints.- Returns:
- A builder instance for a transparent
JBox, which enables fluent method chaining. - See Also:
-
box
public static UIForBox<JBox> box(net.miginfocom.layout.LC attr, String colConstraints, String rowConstraints) Use this to create a builder for aJBox, conceptually the same as a transparentJPanelwithout any insets and aMigLayoutconstructed using the provided constraints. This is essentially a convenience method which may also be expressed as:
UI.of(new JBox()) .peek( box -> { box.setLayout( new MigLayout( attr, ConstraintParser.parseColumnConstraints(colConstraints), ConstraintParser.parseRowConstraints(rowConstraints) ) ) })
Please note that theJBoxtype is in no way related to theBoxLayout! The term box is referring to the purpose of this component, which is to tightly store and wrap other sub-components seamlessly...- Parameters:
attr- The layout attributes in the form of aLayoutConstraintconstants.colConstraints- The column constraints.rowConstraints- The row constraints.- Returns:
- A builder instance for a transparent
JBox, which enables fluent method chaining. - See Also:
-
box
Use this to create a builder for aJBox, a generic component wrapper type which is transparent and without any insets as well as with aMigLayoutas its layout manager. This is conceptually the same as a transparentJPanelwithout any insets and aMigLayoutconstructed using the provided constraints. This method allows you to dynamically determine theLayoutConstraintconstants of theMigLayoutinstance, by passing aValproperty which will be observed and its value passed to theMigLayoutconstructor whenever it changes. This is in essence a convenience method for:UI.box().withLayout(attr.viewAsString( it -> it+", ins 0")).- Parameters:
attr- The layout attributes property which will be passed to theMigLayoutconstructor as first argument.- Returns:
- A builder instance for a new
JBox, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifattrisnull.- See Also:
-
of
If you are using builders for your customJComponent, implement this to allow theUIAPI to call theSwingBuilder.build()method for you.- Type Parameters:
T- The UI component type built by implementations of the provided builder.- Parameters:
builder- A builder for customJComponenttypes.- Returns:
- A basic UI builder instance wrapping any
JComponent.
-
of
If you are using builders for customJMenuItemcomponents, implement this to allow theUIAPI to call theSwingBuilder.build()method for you. -
of
Use this to create a swing tree builder node for theJPopupMenuUI component.- Type Parameters:
P- The concrete type of this new component.- Parameters:
popup- The newJPopupMenuinstance which ought to be part of the Swing UI.- Returns:
- A builder instance for a
JPopupMenu, which enables fluent method chaining.
-
popupMenu
Use this to create a swing tree builder node for theJPopupMenuUI component. This is in essence a convenience method forUI.of(new JPopupMenu()).- Returns:
- A builder instance for a
JPopupMenu, which enables fluent method chaining.
-
of
This returns an instance of aUIForSeparatorbuilder responsible for building aJSeparatorby exposing helpful utility methods for it.- Type Parameters:
S- The concrete type of this new component.- Parameters:
separator- The newJSeparatorinstance which ought to be part of the Swing UI.- Returns:
- A
UIForSeparatorUI builder instance which wraps theJSeparatorand exposes helpful methods.
-
separator
This returns an instance of aUIForSeparatorbuilder responsible for building aJSeparatorby exposing helpful utility methods for it. This is in essence a convenience method forUI.of(new JSeparator()).- Returns:
- A
UIForSeparatorUI builder instance which wraps theJSeparatorand exposes helpful methods.
-
separator
This returns an instance of aUIForSeparatorbuilder responsible for building aJSeparatorby exposing helpful utility methods for it. This is in essence a convenience method forUI.of(new JSeparator(JSeparator.VERTICAL)).- Parameters:
align- The alignment of the separator which may either be horizontal or vertical.- Returns:
- A
UIForSeparatorUI builder instance which wraps theJSeparatorand exposes helpful methods.
-
separator
Use this to create a swing tree builder node for theJSeparatorwhose alignment is dynamically determined based on a provided property.- Parameters:
align- The alignment property of the separator which may either be horizontal or vertical.- Returns:
- A
UIForSeparatorUI builder instance which wraps theJSeparatorand exposes helpful methods.
-
of
This returns aJButtonswing tree builder.- Type Parameters:
T- The concrete type of this new component.- Parameters:
component- The button component which ought to be wrapped by the swing tree UI builder.- Returns:
- A basic UI
JButtonbuilder instance.
-
button
Use this to create a builder for theJButtonUI component without any text displayed on top. This is in essence a convenience method forUI.of(new JButton()).- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Use this to create a builder for theJButtonUI component with the provided text displayed on top. This is in essence a convenience method forUI.of(new JButton(String text)).- Parameters:
text- The text to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Create a builder for theJButtonUI component where the text of the provided property is dynamically displayed on top.- Parameters:
text- The text property to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Use this to create a builder for theJButtonUI component with an icon displayed on top. This is in essence a convenience method forUI.of(new JButton()).peek( it -> it.setIcon(icon) ).- Parameters:
icon- The icon to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Use this to create a builder for theJButtonUI component with an icon displayed on top.- Parameters:
icon- The icon to be displayed on top of the button.fit- The fit mode of the icon.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Use this to create a builder for theJButtonUI component with an icon displayed on top. The icon is determined based on the providedIconDeclarationinstance which is conceptually merely a resource path to the icon.- Parameters:
icon- The desired icon to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Use this to create a builder for theJButtonUI component with an icon displayed on top. The icon is determined based on the providedIconDeclarationinstance which is conceptually merely a resource path to the icon.- Parameters:
icon- The desired icon to be displayed on top of the button.fit- The fit mode of the icon.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Use this to create a builder for theJButtonUI component with an icon displayed on top which should be scaled to the provided dimensions. This is in essence a convenience method forUI.of(new JButton()).peek( it -> it.setIcon(icon) ).- Parameters:
width- The width the icon should be scaled to.height- The height the icon should be scaled to.icon- The icon to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Use this to create a builder for theJButtonUI component with an icon displayed on top which should be scaled to the provided dimensions. The icon is determined based on the providedIconDeclarationinstance which is conceptually merely a resource path to the icon.- Parameters:
width- The width the icon should be scaled to.height- The height the icon should be scaled to.icon- The desired icon to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
buttonWithIcon
Use this to create a builder for theJButtonUI component with a dynamically displayed icon on top.Note that you may not use the
IconorImageIconclasses directly, instead you must use implementations of theIconDeclarationinterface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is that traditional Swing icons are heavy objects whose loading may or may not succeed. Therefore, they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclarationinterface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.This is especially useful in the case of unit tests for your view model, where the icon may not be available at all, but you still want to test the behavior of your view model.
- Parameters:
icon- The icon property whose value ought to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Use this to create a builder for theJButtonUI component with a default icon as well as a hover icon displayed on top.- Parameters:
icon- The default icon to be displayed on top of the button.onHover- The hover icon to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Use this to create a builder for theJButtonUI component with a default icon as well as a hover icon displayed on top. The icons are determined based on the providedIconDeclarationinstances which is conceptually merely a resource path to the icons.- Parameters:
icon- The default icon to be displayed on top of the button.onHover- The hover icon to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Use this to create a builder for theJButtonUI component with a default icon as well as a hover icon displayed on top which should both be scaled to the provided dimensions.- Parameters:
width- The width the icons should be scaled to.height- The height the icons should be scaled to.icon- The default icon to be displayed on top of the button.onHover- The hover icon to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
public static UIForButton<JButton> button(int width, int height, IconDeclaration icon, IconDeclaration onHover) Use this to create a builder for theJButtonUI component with a default icon as well as a hover icon displayed on top which should both be scaled to the provided dimensions. The icons are determined based on the providedIconDeclarationinstances which is conceptually merely a resource path to the icons.- Parameters:
width- The width the icons should be scaled to.height- The height the icons should be scaled to.icon- The default icon to be displayed on top of the button.onHover- The hover icon to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
Use this to create a builder for theJButtonUI component with a default, an on-hover and an on-press icon displayed on top. This is in essence a convenience method for:UI.of(new JButton()).peek( it -> { it.setIcon(icon); it.setRolloverIcon(onHover); it.setPressedIcon(onPress); })- Parameters:
icon- The default icon to be displayed on top of the button.onHover- The hover icon to be displayed on top of the button.onPress- The pressed icon to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
button
public static UIForButton<JButton> button(IconDeclaration icon, IconDeclaration onHover, IconDeclaration onPress) Use this to create a builder for theJButtonUI component with a default, an on-hover and an on-press icon displayed on top. The icons are determined based on the providedIconDeclarationinstances which is conceptually merely a resource paths to the icons.- Parameters:
icon- The default icon to be displayed on top of the button.onHover- The hover icon to be displayed on top of the button.onPress- The pressed icon to be displayed on top of the button.- Returns:
- A builder instance for a
JButton, which enables fluent method chaining.
-
of
Use this to create a builder for theJSplitButtonUI component. This is in essence a convenience method forUI.of(new JSplitButton()).- Type Parameters:
B- The concrete type of this new component.- Parameters:
splitButton- The split button component which ought to be wrapped by the swing tree UI builder.- Returns:
- A builder instance for a
JSplitButton, which enables fluent method chaining.
-
splitButton
Use this to buildJSplitButtons with custom text displayed ont top. TheJSplitButtonwrapped by the returned builder can be populated withJMenuItems like so:
UI.splitButton("Displayed on button!") .add(UI.splitItem("first")) .add(UI.splitItem("second").onButtonClick( it -> ... )) .add(UI.splitItem("third"))- Parameters:
text- The text which should be displayed on the wrappedJSplitButton- Returns:
- A UI builder instance wrapping a
JSplitButton.
-
splitButton
public static <E extends Enum<E>> UIForSplitButton<JSplitButton> splitButton(sprouts.Var<E> selection, sprouts.Event clickEvent) Use this to buildJSplitButtons where the selectable options are represented by anEnumtype, and the click event is handles by anEventinstance.
Here's an example of how to use this method:
// In your view model: enum Size { SMALL, MEDIUM, LARGE } private Var<Size> selection = Var.of(Size.SMALL); private Event clickEvent = Event.of(()->{ ... } public Var<Size> selection() { return selection; } public Event clickEvent() { return clickEvent; } // In your view: UI.splitButton(vm.selection(), vm.clickEvent())Tip: For the text displayed on the split button, the selected enum state will be converted to strings based on the
Object.toString()method. If you want to customize how they are displayed (e.g. so that 'Size.LARGE' is displayed as 'Large' instead of 'LARGE') it is recommended to usesplitButton(Var, Event, Function)instead. But you can also override theObject.toString()method in your enum.- Type Parameters:
E- The type of theEnumrepresenting the selectable options.- Parameters:
selection- TheVarwhich holds the currently selectedEnumvalue. This will be updated when the user selects a new value.clickEvent- TheEventwhich will be fired when the user clicks on the button.- Returns:
- A UI builder instance wrapping a
JSplitButton.
-
splitButton
public static <E extends Enum<E>> UIForSplitButton<JSplitButton> splitButton(sprouts.Var<E> selection, sprouts.Event clickEvent, Function<E, String> labelProvider) Use this to buildJSplitButtons where the selectable options are represented by anEnumtype, and the click event is handles by anEventinstance.
Here's an example of how to use this method:
// In your view model: enum Size { SMALL, MEDIUM, LARGE } private Var<Size> selection = Var.of(Size.SMALL); private Event clickEvent = Event.of(()->{ ... } public Var<Size> selection() { return selection; } public Event clickEvent() { return clickEvent; } // In your view: UI.splitButton(vm.selection(), vm.clickEvent(), it -> it.toString().toLowerCase())Note that the text displayed on the split button is based on the supplied
Functionwhich converts the enum instances to strings. In this function you may, for example, convert 'Size.LARGE' to 'Large' instead of 'LARGE'.- Type Parameters:
E- The type of theEnumrepresenting the selectable options.- Parameters:
selection- TheVarwhich holds the currently selectedEnumvalue. This will be updated when the user selects a new value.clickEvent- TheEventwhich will be fired when the user clicks on the button.labelProvider- A function which converts the enum instances to strings.- Returns:
- A UI builder instance wrapping a
JSplitButton.
-
splitButton
public static <E extends Enum<E>> UIForSplitButton<JSplitButton> splitButton(sprouts.Var<E> selection) Use this to buildJSplitButtons where the selectable options are represented by anEnumtype.
Here's an example of how to use this method:
// In your view model: enum Size { SMALL, MEDIUM, LARGE } private Var<Size> selection = Var.of(Size.SMALL); public Var<Size> selection() { return selection; } // In your view: UI.splitButton(vm.selection())Tip: The text displayed on the button is based on the
Object.toString()method of the enum instances. If you want to customize how they are displayed (i.e. so that 'Size.LARGE' is displayed as 'Large' instead of 'LARGE') it is recommended to usesplitButton(Var, Function)instead. But you can also choose to override theObject.toString()method in your enum to achieve the same effect.- Type Parameters:
E- The type of theEnumrepresenting the selectable options.- Parameters:
selection- TheVarwhich holds the currently selectedEnumvalue. This will be updated when the user selects a new value.- Returns:
- A UI builder instance wrapping a
JSplitButton.
-
splitButton
public static <E extends Enum<E>> UIForSplitButton<JSplitButton> splitButton(sprouts.Var<E> selection, Function<E, String> labelProvider) Use this to buildJSplitButtons where the selectable options are represented by anEnumtype.
Here's an example of how to use this method:
// In your view model: enum Size { SMALL, MEDIUM, LARGE } private Var<Size> selection = Var.of(Size.SMALL); public Var<Size> selection() { return selection; } // In your view: UI.splitButton(vm.selection(), it -> it.toString().toLowerCase())Note that the text displayed on the split button is based on the supplied
Functionwhich converts the enum instances to strings. In this function you may for example convert 'Size.LARGE' to 'Large' instead of 'LARGE'. In the above example we simply convert the enum instances to lower case strings, but you can customize this function to your liking.- Type Parameters:
E- The type of theEnumrepresenting the selectable options.- Parameters:
selection- TheVarwhich holds the currently selectedEnumvalue. This will be updated when the user selects a new value.labelProvider- A function which converts the enum instances to strings.- Returns:
- A UI builder instance wrapping a
JSplitButton.
-
splitItem
Use this to add entries to theJSplitButtonby passingSplitIteminstances toUIForSplitButtonbuilder like so:
You can also use theUI.splitButton("Button") .add(UI.splitItem("first")) .add(UI.splitItem("second")) .add(UI.splitItem("third"))SplitItemwrapper class to wrap useful action lambdas for the split item.- Parameters:
text- The text displayed on theJMenuItemexposed by theJSplitButtonsJPopupMenu.- Returns:
- A new
SplitItemwrapping a simpleJMenuItem.
-
splitItem
Use this to add property-bound entries to theJSplitButtonby passingSplitIteminstances toUIForSplitButtonbuilder like so:
You can also use theUI.splitButton("Button") .add(UI.splitItem(viewModel.getFirstButtonName())) .add(UI.splitItem(viewModel.getSecondButtonName())) .add(UI.splitItem(viewModel.getThirdButtonName()))SplitItemwrapper class to wrap useful action lambdas for the split item.- Parameters:
text- The text property to dynamically display text on theJMenuItemexposed by theJSplitButtonsJPopupMenu.- Returns:
- A new
SplitItemwrapping a simpleJMenuItem.
-
splitRadioItem
Use this to add radio item entries to theJSplitButtonby passingSplitIteminstances toUIForSplitButtonbuilder like so:
You can also use theUI.splitButton("Button") .add(UI.splitRadioItem("first")) .add(UI.splitRadioItem("second")) .add(UI.splitRadioItem("third"))SplitItemwrapper class to wrap useful action lambdas for the split item.- Parameters:
text- The text displayed on theJRadioButtonMenuItemexposed by theJSplitButtonsJPopupMenu.- Returns:
- A new
SplitItemwrapping a simpleJRadioButtonMenuItem.
-
of
Creates a UI builder for a customJTabbedPanetype.- Type Parameters:
P- The pane type parameter.- Parameters:
pane- TheJTabbedPanetype which should be used wrapped.- Returns:
- This instance, to allow for method chaining.
-
tabbedPane
Use this to create a builder for a newJTabbedPaneUI component. This is in essence a convenience method forUI.of(new JTabbedPane()). To add tabs to this builder use the tab object returned bytab(String)like so:UI.tabbedPane() .add(UI.tab("one").add(UI.panel().add(..))) .add(UI.tab("two").withTip("I give info!").add(UI.label("read me"))) .add(UI.tab("three").withIcon(someIcon).add(UI.button("click me")))- Returns:
- A builder instance for a new
JTabbedPane, which enables fluent method chaining.
-
tabbedPane
Use this to create a builder for a newJTabbedPaneUI component with the providedUI.Sideapplied to the tab buttons (seeJTabbedPane.setTabLayoutPolicy(int)). In order to add tabs to this builder use the tab object returned bytab(String)like so:UI.tabbedPane(UI.Side.RIGHT) .add(UI.tab("first").add(UI.panel().add(..))) .add(UI.tab("second").withTip("I give info!").add(UI.label("read me"))) .add(UI.tab("third").withIcon(someIcon).add(UI.button("click me")))- Parameters:
tabsSide- The position of the tab buttons which may beUI.Side.TOP,UI.Side.RIGHT,UI.Side.BOTTOM,UI.Side.LEFT.- Returns:
- A builder instance wrapping a new
JTabbedPane, which enables fluent method chaining. - Throws:
IllegalArgumentException- iftabsPositionisnull.
-
tabbedPane
public static UIForTabbedPane<JTabbedPane> tabbedPane(UI.Side tabsSide, UI.OverflowPolicy tabsPolicy) Use this to create a builder for a newJTabbedPaneUI component with the providedUI.OverflowPolicyandUI.Sideapplied to the tab buttons (seeJTabbedPane.setTabLayoutPolicy(int)andJTabbedPane.setTabPlacement(int)). To add tabs to this builder use the tab object returned bytab(String)like so:UI.tabbedPane(UI.Side.LEFT, UI.OverflowPolicy.WRAP) .add(UI.tab("First").add(UI.panel().add(..))) .add(UI.tab("second").withTip("I give info!").add(UI.label("read me"))) .add(UI.tab("third").withIcon(someIcon).add(UI.button("click me")))- Parameters:
tabsSide- The position of the tab buttons which may beUI.Side.TOP,UI.Side.RIGHT,UI.Side.BOTTOM,UI.Side.LEFT.tabsPolicy- The overflow policy of the tab buttons which can either beUI.OverflowPolicy.SCROLLorUILayoutConstants.WRAP(int).- Returns:
- A builder instance wrapping a new
JTabbedPane, which enables fluent method chaining. - Throws:
IllegalArgumentException- iftabsPositionortabsPolicyarenull.
-
tabbedPane
Use this to create a builder for a newJTabbedPaneUI component with the providedUI.OverflowPolicyapplied to the tab buttons (seeJTabbedPane.setTabLayoutPolicy(int)). To add tabs to this builder use the tab object returned bytab(String)like so:UI.tabbedPane(UI.OverflowPolicy.SCROLL) .add(UI.tab("First").add(UI.panel().add(..))) .add(UI.tab("second").withTip("I give info!").add(UI.label("read me"))) .add(UI.tab("third").withIcon(someIcon).add(UI.button("click me")))- Parameters:
tabsPolicy- The overflow policy of the tab button which can either beUI.OverflowPolicy.SCROLLorUILayoutConstants.WRAP(int).- Returns:
- A builder instance wrapping a new
JTabbedPane, which enables fluent method chaining. - Throws:
IllegalArgumentException- iftabsPolicyisnull.
-
tabbedPane
Use this to create a builder for a newJTabbedPaneUI component with the providedselectedIndexproperty which should be determined the tab selection of theJTabbedPanedynamically. To add tabs to this builder use the tab object returned bytab(String)like so:
Note that contrary to methodUI.tabbedPane(vm.getSelectionIndex()) .add(UI.tab("First").add(UI.panel().add(..))) .add(UI.tab("second").withTip("I give info!").add(UI.label("read me"))) .add(UI.tab("third").withIcon(someIcon).add(UI.button("click me")))tabbedPane(Var), this method receives aValproperty which may not be changed by the GUI user. If you want to allow the user to change the selection index property state, usetabbedPane(Var)instead.- Parameters:
selectedIndex- The index of the tab to select.- Returns:
- A builder instance wrapping a new
JTabbedPane, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifselectedIndexisnull.
-
tabbedPane
Use this to create a builder for a newJTabbedPaneUI component with the providedselectedIndexproperty which should determine the tab selection of theJTabbedPanedynamically. To add tabs to this builder use the tab object returned bytab(String)like so:UI.tabbedPane(vm.getSelectionIndex()) .add(UI.tab("First").add(UI.panel().add(..))) .add(UI.tab("second").withTip("I give info!").add(UI.label("read me"))) .add(UI.tab("third").withIcon(someIcon).add(UI.button("click me")))- Parameters:
selectedIndex- The index of the tab to select.- Returns:
- A builder instance wrapping a new
JTabbedPane, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifselectedIndexisnull.
-
tab
Use this to add tabs to aJTabbedPaneby passingTabinstances toUIForTabbedPanebuilder like so:
UI.tabbedPane() .add(UI.tab("First").add(UI.panel().add(..))) .add(UI.tab("second").withTip("I give info!").add(UI.label("read me"))) .add(UI.tab("third").withIcon(someIcon).add(UI.button("click me")))- Parameters:
title- The text displayed on the tab button.- Returns:
- A
Tabinstance containing everything needed to be added to aJTabbedPane. - Throws:
IllegalArgumentException- iftitleisnull.
-
tab
A factory method producing aTabinstance with the providedtitleproperty which can dynamically change the title of the tab button. Use this to add tabs to aJTabbedPaneby passingTabinstances toUIForTabbedPanebuilder like so:
UI.tabbedPane() .add(UI.tab(property1).add(UI.panel().add(..))) .add(UI.tab(property2).withTip("I give info!").add(UI.label("read me"))) .add(UI.tab(property3).withIcon(someIcon).add(UI.button("click me")))- Parameters:
title- The text property dynamically changing the title of the tab button when the property changes.- Returns:
- A
Tabinstance containing everything needed to be added to aJTabbedPane. - Throws:
IllegalArgumentException- iftitleisnull.
-
tab
Use this to add tabs to aJTabbedPaneby passingTabinstances toUIForTabbedPanebuilder like so:
UI.tabbedPane() .add(UI.tab(new JButton("X")).add(UI.panel().add(..))) .add(UI.tab(new JLabel("Hi!")).withTip("I give info!").add(UI.label("read me"))) .add(UI.tab(new JPanel()).add(UI.button("click me")))- Parameters:
component- The component displayed on the tab button.- Returns:
- A
Tabinstance containing everything needed to be added to aJTabbedPane. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
tab
Use this to add tabs to aJTabbedPaneby passingTabinstances toUIForTabbedPanebuilder like so:
UI.tabbedPane() .add(UI.tab(UI.button("X")).add(UI.panel().add(..))) .add(UI.tab(UI.label("Hi!")).withTip("I give info!").add(UI.label("read me"))) .add(UI.tab(UI.of(...)).withIcon(someIcon).add(UI.button("click me")))- Parameters:
builder- The builder wrapping the component displayed on the tab button.- Returns:
- A
Tabinstance containing everything needed to be added to aJTabbedPane. - Throws:
IllegalArgumentException- ifbuilderisnull.
-
of
Use this to create a builder for the providedJMenuinstance.- Type Parameters:
M- The concrete type of the menu.- Parameters:
component- TheJMenucomponent which should be wrapped by the swing tree UI builder designed for menus.- Returns:
- A builder instance for the provided
JMenu, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
of
Use this to create a builder for the providedJMenuIteminstance.- Type Parameters:
M- The type parameter of the concrete menu item component.- Parameters:
component- TheJMenuItemcomponent which should be wrapped by the swing tree UI builder designed for menu items.- Returns:
- A builder instance for the provided
JMenuItem, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
of
A factory method to wrap the providedJRadioButtonMenuIteminstance in a SwingTree UI builder.- Type Parameters:
M- The type of theJRadioButtonMenuIteminstance to be wrapped.- Parameters:
radioMenuItem- TheJRadioButtonMenuIteminstance to be wrapped.- Returns:
- A builder instance for the provided
JRadioButtonMenuItem, which enables fluent method chaining.
-
radioButtonMenuItem
A factory method to create a plainJRadioButtonMenuIteminstance.
Here an example demonstrating the usage of this method:
UI.popupMenu() .add(UI.radioButtonMenuItem().onClick( it -> {..} )) .add(UI.radioButtonMenuItem().onClick( it -> {..} ))- Returns:
- A builder instance for the provided
JRadioButtonMenuItem, which enables fluent method chaining.
-
radioButtonMenuItem
A factory method to create aJRadioButtonMenuItemwith the provided text displayed on the menu button.
Here an example demonstrating the usage of this method:
UI.popupMenu() .add(UI.radioButtonMenuItem("Delete").onClick( it -> {..} )) .add(UI.radioButtonMenuItem("Edit").onClick( it -> {..} ))- Parameters:
text- The text which should be displayed on the wrappedJRadioButtonMenuItem.- Returns:
- A builder instance for the provided
JRadioButtonMenuItem, which enables fluent method chaining.
-
radioButtonMenuItem
public static UIForRadioButtonMenuItem<JRadioButtonMenuItem> radioButtonMenuItem(sprouts.Val<String> text) A factory method to create aJRadioButtonMenuItembound to the provided text property, whose value will be displayed on the menu button dynamically.
Here an example demonstrating the usage of this method:
Note that in a real application you would take the text property from a model object through a plain old getter method (e.g.UI.popupMenu() .add(UI.radioButtonMenuItem(Val.of("Delete")).onClick( it -> {..} )) .add(UI.radioButtonMenuItem(Val.of("Edit")).onClick( it -> {..} ))myViewModel.getTextProperty()).- Parameters:
text- The text property which should be displayed on the wrappedJRadioButtonMenuItemdynamically.- Returns:
- A builder instance for the provided
JRadioButtonMenuItem, which enables fluent method chaining.
-
radioButtonMenuItem
public static UIForRadioButtonMenuItem<JRadioButtonMenuItem> radioButtonMenuItem(String text, Icon icon) A factory method to create aJRadioButtonMenuItemwith the provided text displayed on the menu button and the provided icon displayed on the menu button.
Here an example demonstrating the usage of this method:
UI.popupMenu() .add(UI.radioButtonMenuItem("Delete", UI.icon("delete.png")).onClick( it -> {..} )) .add(UI.radioButtonMenuItem("Edit", UI.icon("edit.png")).onClick( it -> {..} ))- Parameters:
text- The text which should be displayed on the wrappedJRadioButtonMenuItem.icon- The icon which should be displayed on the wrappedJRadioButtonMenuItem.- Returns:
- A builder instance for the provided
JRadioButtonMenuItem, which enables fluent method chaining.
-
radioButtonMenuItem
public static UIForRadioButtonMenuItem<JRadioButtonMenuItem> radioButtonMenuItem(sprouts.Val<String> text, Icon icon) A factory method to create aJRadioButtonMenuItembound to the provided text property, whose value will be displayed on the menu button dynamically and the provided icon displayed on the menu button.
Here an example demonstrating the usage of this method:
Note that in a real application you would take the text property from a model object through a plain old getter method (e.g.UI.popupMenu() .add(UI.radioButtonMenuItem(Val.of("Delete"), UI.icon("delete.png")).onClick( it -> {..} )) .add(UI.radioButtonMenuItem(Val.of("Edit"), UI.icon("edit.png")).onClick( it -> {..} ))myViewModel.getTextProperty()).- Parameters:
text- The text property which should be displayed on the wrappedJRadioButtonMenuItemdynamically.icon- The icon which should be displayed on the wrappedJRadioButtonMenuItem.- Returns:
- A builder instance for the provided
JRadioButtonMenuItem, which enables fluent method chaining.
-
radioButtonMenuItem
public static <E extends Enum<E>> UIForRadioButtonMenuItem<JRadioButtonMenuItem> radioButtonMenuItem(E state, sprouts.Var<E> property) A factory method to create aJRadioButtonMenuItembound to a fixed enum value and a variable enum property which will dynamically select the menu item based on the equality of the fixed enum value and the variable enum property value.
Consider the following example code:
In this example theUI.popupMenu() .add(UI.radioButtonMenuItem(Unit.SECONDS, myViewModel.unitProperty())) .add(UI.radioButtonMenuItem(Unit.MINUTES, myViewModel.unitProperty())) .add(UI.radioButtonMenuItem(Unit.HOURS, myViewModel.unitProperty()))myViewModel.unitProperty()is aVarproperty of example typeUnit. A given menu item will be selected if the value of themyViewModel.unitProperty()is equal to the first enum value passed to the factory method. This first enum will also be used as the text of the menu item through thetoString().- Type Parameters:
E- The type of the enum.- Parameters:
state- The fixed enum value which will be used as the text of the menu item andproperty- The variable enum property which will be used to select the menu item.- Returns:
- A builder instance for the provided
JRadioButtonMenuItem, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifstateorpropertyarenull.
-
radioButtonMenuItem
public static UIForRadioButtonMenuItem<JRadioButtonMenuItem> radioButtonMenuItem(String text, sprouts.Var<Boolean> isSelected) A factory method to create aJRadioButtonMenuItemwith some custom text and a boolean property, dynamically determining whether the radio-button-based menu item is selected or not.
Here an example demonstrating the usage of this method:
Note that in a real application you would take the boolean property from a model object through a plain old getter method (e.g.// inside your view model class: Var<Boolean> isSelected1 = Var.of(false); Var<Boolean> isSelected2 = Var.of(false); // inside your view class: UI.popupMenu() .add(UI.radioButtonMenuItem("Make Coffee", isSelected1).onClick( it -> {..} )) .add(UI.radioButtonMenuItem("Make Tea", isSelected2).onClick( it -> {..} ))myViewModel.getIsSelectedProperty()).- Parameters:
text- The text which should be displayed on the wrappedJRadioButtonMenuItem.isSelected- The boolean property which will be bound to the menu item to dynamically determines whether the menu item is selected or not.- Returns:
- A builder instance for the provided
JRadioButtonMenuItem, which enables fluent method chaining.
-
radioButtonMenuItem
public static UIForRadioButtonMenuItem<JRadioButtonMenuItem> radioButtonMenuItem(sprouts.Val<String> text, sprouts.Var<Boolean> isSelected) A factory method to create aJRadioButtonMenuItemwith some custom text and a boolean property, dynamically determining whether the radio-button-based menu item is selected or not.
Here an example demonstrating the usage of this method:
Note that in a real application you would take the// inside your view model class: Var<Boolean> isSelected1 = Var.of(false); Var<Boolean> isSelected2 = Var.of(false); // inside your view class: UI.popupMenu() .add(UI.radioButtonMenuItem(Val.of("Make Coffee"), isSelected1).onClick( it -> {..} )) .add(UI.radioButtonMenuItem(Val.of("Make Tea"), isSelected2).onClick( it -> {..} ))Stringandbooleanproperties from a view model object through plain old getter methods (e.g.myViewModel.getTextProperty()andmyViewModel.getIsSelectedProperty()).- Parameters:
text- The text property whose text should dynamically be displayed on the wrappedJRadioButtonMenuItem.isSelected- The boolean property which will be bound to the menu item to dynamically determines whether the menu item is selected or not.- Returns:
- A builder instance for the provided
JRadioButtonMenuItem, which enables fluent method chaining.
-
of
A factory method to wrap the providedJCheckBoxMenuIteminstance in a SwingTree UI builder.- Type Parameters:
M- The type of theJCheckBoxMenuIteminstance to be wrapped.- Parameters:
checkBoxMenuItem- TheJCheckBoxMenuIteminstance to be wrapped.- Returns:
- A builder instance for the provided
JCheckBoxMenuItem, which enables fluent method chaining.
-
checkBoxMenuItem
A factory method to create aJCheckBoxMenuItemwithout text displayed on top of the menu button.
Here an example demonstrating the usage of this method:
UI.popupMenu() .add(UI.checkBoxMenuItem().onClick( it -> {..} )) .add(UI.checkBoxMenuItem().onClick( it -> {..} ))- Returns:
- A builder instance for the provided
JCheckBoxMenuItem, which enables fluent method chaining.
-
checkBoxMenuItem
A factory method to create aJCheckBoxMenuItemwith the provided text displayed on the menu button.
Here an example demonstrating the usage of this method:
UI.popupMenu() .add(UI.checkBoxMenuItem("Delete").onClick( it -> {..} )) .add(UI.checkBoxMenuItem("Edit").onClick( it -> {..} ))- Parameters:
text- The text which should be displayed on the wrappedJCheckBoxMenuItem.- Returns:
- A builder instance for the provided
JCheckBoxMenuItem, which enables fluent method chaining.
-
checkBoxMenuItem
A factory method to create aJCheckBoxMenuItembound to the provided text property, whose value will be displayed on the menu button dynamically.
Here an example demonstrating the usage of this method:
Note that in a real application you would take the text property from a model object through a plain old getter method (e.g.UI.popupMenu() .add(UI.checkBoxMenuItem(Val.of("Delete")).onClick( it -> {..} )) .add(UI.checkBoxMenuItem(Val.of("Edit")).onClick( it -> {..} ))myViewModel.getTextProperty()).- Parameters:
text- The text property which should be displayed on the wrappedJCheckBoxMenuItemdynamically.- Returns:
- A builder instance for the provided
JCheckBoxMenuItem, which enables fluent method chaining.
-
checkBoxMenuItem
A factory method to create aJCheckBoxMenuItemwith the provided text displayed on the menu button and the provided icon displayed on the menu button.
Here an example demonstrating the usage of this method:
UI.popupMenu() .add(UI.checkBoxMenuItem("Delete", UI.icon("delete.png")).onClick( it -> {..} )) .add(UI.checkBoxMenuItem("Edit", UI.icon("edit.png")).onClick( it -> {..} ))- Parameters:
text- The text which should be displayed on the wrappedJCheckBoxMenuItem.icon- The icon which should be displayed on the wrappedJCheckBoxMenuItem.- Returns:
- A builder instance for the provided
JCheckBoxMenuItem, which enables fluent method chaining.
-
checkBoxMenuItem
public static UIForCheckBoxMenuItem<JCheckBoxMenuItem> checkBoxMenuItem(String text, sprouts.Var<Boolean> isSelected) A factory method to create aJCheckBoxMenuItemwith some custom text and a boolean property, dynamically determining whether the menu item is selected or not.
Here an example demonstrating the usage of this method:
Note that in a real application you would take the boolean property from a model object through a plain old getter method (e.g.// inside your view model class: Var<Boolean> isSelected = Var.of(false); // inside your view class: UI.popupMenu() .add(UI.checkBoxMenuItem("Delete", isSelected).onClick( it -> {..} )) .add(UI.checkBoxMenuItem("Edit", isSelected).onClick( it -> {..} ))myViewModel.getIsSelectedProperty()).- Parameters:
text- The text which should be displayed on the wrappedJCheckBoxMenuItem.isSelected- The boolean property which will be bound to the menu item to dynamically determine whether the menu item is selected or not.- Returns:
- A builder instance for the provided
JCheckBoxMenuItem, which enables fluent method chaining.
-
checkBoxMenuItem
public static UIForCheckBoxMenuItem<JCheckBoxMenuItem> checkBoxMenuItem(sprouts.Val<String> text, Icon icon) A factory method to create aJCheckBoxMenuItembound to the provided text property, whose value will be displayed on the menu button dynamically and the provided icon displayed on the menu button.
Here an example demonstrating the usage of this method:
Note that in a real application you would take the text property from a model object through a plain old getter method (e.g.UI.popupMenu() .add(UI.checkBoxMenuItem(Val.of("Delete"), UI.icon("delete.png")).onClick( it -> {..} )) .add(UI.checkBoxMenuItem(Val.of("Edit"), UI.icon("edit.png")).onClick( it -> {..} ))myViewModel.getTextProperty()).- Parameters:
text- The text property which should be displayed on the wrappedJCheckBoxMenuItemdynamically.icon- The icon which should be displayed on the wrappedJCheckBoxMenuItem.- Returns:
- A builder instance for the provided
JCheckBoxMenuItem, which enables fluent method chaining.
-
checkBoxMenuItem
public static UIForCheckBoxMenuItem<JCheckBoxMenuItem> checkBoxMenuItem(sprouts.Val<String> text, sprouts.Var<Boolean> isSelected) A factory method to create aJCheckBoxMenuItembound to the provided text property, whose value will be displayed on the menu button dynamically and the provided boolean property, dynamically determining whether the menu item is selected or not.
Here an example demonstrating the usage of this method:
Note that in a real application you would take the text property from a model object through a plain old getter method (e.g.// inside your view model class: Var<Boolean> isSelected = Var.of(false); // inside your view class: UI.popupMenu() .add(UI.checkBoxMenuItem(Val.of("Delete"), isSelected).onClick( it -> {..} )) .add(UI.checkBoxMenuItem(Val.of("Edit"), isSelected).onClick( it -> {..} ))myViewModel.getTextProperty()).- Parameters:
text- The text property which should be displayed on the wrappedJCheckBoxMenuItemdynamically.isSelected- The boolean property which will be bound to the menu item to dynamically determines whether the menu item is selected or not.- Returns:
- A builder instance for the provided
JCheckBoxMenuItem, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJToolBarinstance. Using method chaining, you can populate theJToolBarby like so:
UI.of(myToolBar) .add(UI.button("X")) .add(UI.button("Y")) .add(UI.button("Z")) .addSeparator() .add(UI.button("A"))- Type Parameters:
T- The type of theJToolBarinstance to be wrapped.- Parameters:
component- TheJToolBarinstance to be wrapped.- Returns:
- A builder instance for the provided
JToolBar, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
toolBar
Use this to create a builder for a newJToolBarinstance. Use method chaining to add buttons or other components to aJToolBarby passing them toUIForToolBarbuilder like so:
UI.toolBar() .add(UI.button("X")) .add(UI.button("Y")) .add(UI.button("Z")) .addSeparator() .add(UI.button("A"))- Returns:
- A builder instance for the provided
JToolBar, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
toolBar
A factory method for creating aJToolBarinstance where the providedUI.Alignenum defines the orientation of theJToolBar.- Parameters:
align- TheUI.Alignenum which defines the orientation of theJToolBar.- Returns:
- A builder instance for the provided
JToolBar, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifalignisnull.
-
toolBar
A factory method for creating aJToolBarinstance where the providedValproperty dynamically defines the orientation of theJToolBar- Parameters:
align- TheValproperty which dynamically defines the orientation of theJToolBar.- Returns:
- A builder instance for the provided
JToolBar, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifalignisnull.
-
of
Use this to create a builder for the providedJScrollPanecomponent.- Type Parameters:
P- The type parameter defining the concrete scroll pane type.- Parameters:
component- TheJScrollPanecomponent which should be represented by the returned builder.- Returns:
- A
UIForScrollPanebuilder representing the provided component. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
scrollPane
Use this to create a builder for a newJScrollPaneUI component. This is in essence a convenience method forUI.of(new JScrollPane()).
Here is an example of a simple scroll panel with a text area inside:UI.scrollPane() .withScrollBarPolicy(UI.Scroll.NEVER) .add(UI.textArea("I am a text area with this text inside."))- Returns:
- A builder instance for a new
JScrollPane, which enables fluent method chaining. - See Also:
-
scrollPane
public static UIForScrollPane<JScrollPane> scrollPane(Configurator<ScrollableComponentDelegate> configurator) Allows you to create a declarative builder for theJScrollPanecomponent type, where you can also configure how the contained component should behave in the scroll pane viewport through aConfiguratorlambda.
The configurator receives aScrollableComponentDelegateon which you can define properties like the preferred viewport size, unit increment, block increment, and whether the component should fit the width or height of the viewport.
Here a short code snippet demonstrating how this factory method is typically used:
Note that these properties are directly translated to an underlying implementation of theUI.panel() .withBorderTitled("Scrollable Panel") .add( UI.scrollPane(conf -> conf .prefSize(400, 300) .unitIncrement(20) .blockIncrement(50) .fitWidth(true) .fitHeight(false) ) )Scrollableinterface which will wrap your content component seamlessly in the scroll pane when added using one of the variousaddmethods.
So you do not have to implement theScrollableinterface yourself!
The
ScrollableComponentDelegateobject passed to the configurator exposes some context information you may find useful when defining its properties. Like for example the currentScrollableComponentDelegate.view(), which implements theScrollableand wraps yourScrollableComponentDelegate.content()component. You can also access theScrollableComponentDelegate.viewport()as well as the currentscrollPane()component itself!
Note that the provided
Configuratorwill be called for every call to a method of the underlyingScrollablecomponent implementation, so the settings you define in the configurator are updated dynamically based on the context captured by the lambda as well as the involved components, like viewport, view, content and the scroll pane itself.- Parameters:
configurator- A configurator for configuring the scrollable content of the scroll pane.- Returns:
- A builder instance for a new
JScrollPane, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJScrollPanelscomponent.- Type Parameters:
P- The type parameter defining the concrete scroll panels type.- Parameters:
component- TheJScrollPanelscomponent which should be represented by the returned builder.- Returns:
- A
UIForScrollPanelsbuilder representing the provided component. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
scrollPanels
Use this to create a builder for a newJScrollPanelsUI component. This is in essence a convenience method forUI.of(new JScrollPanels()).
Here is an example of a simple scroll panel with a text area inside:UI.scrollPanels() .withScrollBarPolicy(UI.Scroll.NEVER) .add(UI.textArea("I am a text area with this text inside.")) .add(UI.label("I am a label!")) .add(UI.button("I am a button! Click me!"))- Returns:
- A builder instance for a new
JScrollPanels, which enables fluent method chaining.
-
scrollPanels
Use this to create a builder for a newJScrollPanelsUI component. This is in essence a convenience method forUI.of(new JScrollPanels()).
Here is an example of a simple scroll panel with a text area inside:UI.scrollPanels(UI.Align.HORIZONTAL) .withScrollBarPolicy(UI.Scroll.NEVER) .add(UI.textArea("I am a text area with this text inside.")) .add(UI.label("I am a label!")) .add(UI.button("I am a button! Click me!"))- Parameters:
align- The alignment of the scroll panels.- Returns:
- A builder instance for a new
JScrollPanels, which enables fluent method chaining.
-
scrollPanels
Use this to create a builder for a newJScrollPanelsUI component. This is in essence a convenience method forUI.of(new JScrollPanels()).
Here is an example of a simple scroll panel with a text area inside:UI.scrollPanels(UI.Align.HORIZONTAL, new Dimension(100,100)) .withScrollBarPolicy(UI.Scroll.NEVER) .add(UI.textArea("I am a text area with this text inside.")) .add(UI.label("I am a label!")) .add(UI.button("I am a button! Click me!"))- Parameters:
align- The alignment of the scroll panels.size- The size of the scroll panels.- Returns:
- A builder instance for a new
JScrollPanels, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJSplitPaneinstance.- Type Parameters:
P- The type of theJSplitPaneinstance.- Parameters:
component- TheJSplitPaneinstance to create a builder for.- Returns:
- A builder instance for the provided
JSplitPane, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
splitPane
Use this to create a builder for a newJSplitPaneinstance based on the provided alignment enum determining how the split itself should be aligned.
You can create a simple split pane based UI like so:
UI.splitPane(UI.Align.HORIZONTAL) // The split bar will be horizontal .withDividerAt(50) .add(UI.panel().add(...)) // top .add(UI.scrollPane().add(...)) // bottom- Parameters:
align- The alignment determining if theJSplitPanesplit bar is aligned vertically or horizontally.- Returns:
- A builder instance for the provided
JSplitPane, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifalignisnull.
-
splitPane
Use this to create a builder for a newJSplitPaneinstance based on the provided alignment property determining how the split itself should be aligned.
You can create a simple split pane based UI like so:
UI.splitPane(viewModel.getAlignment()) .withDividerAt(50) .add(UI.panel().add(...)) // top .add(UI.scrollPane().add(...)) // bottom
The split pane will be updated whenever the provided property changes.
Note: The provided property must not benull! Otherwise, anIllegalArgumentExceptionwill be thrown.- Parameters:
align- The alignment determining if theJSplitPanesplit bar is aligned vertically or horizontally.- Returns:
- A builder instance for the provided
JSplitPane, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifalignisnull.
-
of
Use this to create a builder for the providedJEditorPaneinstance.- Type Parameters:
P- The type of theJEditorPaneinstance.- Parameters:
component- TheJEditorPaneinstance to create a builder for.- Returns:
- A builder instance for the provided
JEditorPane, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
editorPane
Use this to create a builder for a newJEditorPaneUI component. This is in essence a convenience method forUI.of(new JEditorPane()).- Returns:
- A builder instance for a new
JEditorPane, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJTextPaneinstance.- Type Parameters:
P- The type of theJTextPaneinstance.- Parameters:
component- TheJTextPaneinstance to create a builder for.- Returns:
- A builder instance for the provided
JTextPane, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
textPane
Use this to create a builder for a newJTextPaneUI component. This is in essence a convenience method forUI.of(new JTextPane()).- Returns:
- A builder instance for a new
JTextPane, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJSliderinstance.- Type Parameters:
S- The type of theJSliderinstance.- Parameters:
component- TheJSliderinstance to create a builder for.- Returns:
- A builder instance for the provided
JSlider, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
slider
Use this to create a builder for a newJSliderinstance based on tbe provided alignment type determining if the slider will be aligned vertically or horizontally.- Parameters:
align- The alignment determining if theJSlideraligns vertically or horizontally.- Returns:
- A builder instance for the provided
JSlider, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifalignisnull.- See Also:
-
slider
Use this to create a builder for a newJSliderinstance based on the provided alignment property which dynamically determines if the property is aligned vertically or horizontally.- Parameters:
align- The alignment property determining if theJSlideraligns vertically or horizontally.- Returns:
- A builder instance for the provided
JSlider, which enables fluent method chaining. - Throws:
IllegalArgumentException- if thealignproperty isnull.- See Also:
-
slider
Use this to create a builder for a newJSliderinstance based on tbe provided alignment type, min slider value and max slider value.- Parameters:
align- The alignment determining if theJSlideraligns vertically or horizontally.min- The minimum possible value of the slider.max- The maximum possible value of the slider.- Returns:
- A builder instance for the provided
JSlider, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifalignisnull.- See Also:
-
slider
Creates a slider with the specified alignment and the specified minimum, maximum, and initial values.- Parameters:
align- The alignment determining if theJSlideraligns vertically or horizontally.min- The minimum possible value of the slider.max- The maximum possible value of the slider.value- the initial value of the slider- Returns:
- A builder instance for the provided
JSlider, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifalignisnull.- See Also:
-
slider
public static <N extends Number> UIForSlider<JSlider> slider(UI.Align align, N min, N max, sprouts.Val<N> value) Creates a slider with the specified alignment and the specified minimum, maximum, and dynamic value.
The slider will be updated whenever the provided property changes. But note that the property is of the read onlyValtype, which means that when the user moves the slider, the property will not be updated.
If you want bidirectional binding, useslider(UI.Align, Number, Number, Var)instead of this method.- Type Parameters:
N- The type of the number used for the slider values.- Parameters:
align- The alignment determining if theJSlideraligns vertically or horizontally.min- The minimum possible value of the slider.max- The maximum possible value of the slider.value- The property holding the value of the slider- Returns:
- A builder instance for the provided
JSlider, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifalignisnull.- See Also:
-
slider
public static <N extends Number> UIForSlider<JSlider> slider(UI.Align align, N min, N max, sprouts.Var<N> value) Creates a slider with the specified alignment and the specified minimum, maximum, and dynamic value property. The property will be updated whenever the user moves the slider and the slider will be updated whenever the property changes in your code (seeVar.set(Object)).- Type Parameters:
N- The type of the number used for the slider values. This may beInteger,Double,Float,Longor any other number type.- Parameters:
align- The alignment determining if theJSlideraligns vertically or horizontally.min- The minimum possible value of the slider.max- The maximum possible value of the slider.value- The property holding the value of the slider- Returns:
- A builder instance for the provided
JSlider, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifalignisnull.- See Also:
-
slider
public static <N extends Number> UIForSlider<JSlider> slider(UI.Align align, sprouts.Val<N> min, sprouts.Val<N> max, sprouts.Val<N> value) Creates a slider with the specified alignment and the specified minimum, maximum, and value property views. The min, max and value may be updated dynamically when the properties change their values. The current value property item will however not be updated whenever the user moves the slider due to the usage of the read onlyValtype.- Type Parameters:
N- The type of the number used for the slider values. This may beInteger,Double,Float,Longor any other number type.- Parameters:
align- The alignment determining if theJSlideraligns vertically or horizontally.min- The minimum possible value of the slider, which may be updated dynamically when the property changes.max- The maximum possible value of the slider, which may be updated dynamically when the property changes.value- The property holding the value of the slider which may be updated dynamically when the property changes in your code (seeVar.set(Object)).- Returns:
- A builder instance for the provided
JSlider, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifalign,min,maxorvalueisnull.- See Also:
-
slider
public static <N extends Number> UIForSlider<JSlider> slider(UI.Align align, sprouts.Val<N> min, sprouts.Val<N> max, sprouts.Var<N> value) Creates a slider with the specified alignment and the specified minimum, maximum, and value property views. The min, max and value may be updated dynamically when the properties change their values in your code. The current value property may also be updated by the user moving the slider due to the usage of the read-writeVartype here in contrast toslider(UI.Align, Val, Val, Val).- Type Parameters:
N- The type of the number used for the slider values. This may beInteger,Double,Float,Longor any other number type.- Parameters:
align- The alignment determining if theJSlideraligns vertically or horizontally.min- The minimum possible value of the slider, which may be updated dynamically when the property changes.max- The maximum possible value of the slider, which may be updated dynamically when the property changes.value- The property holding the value of the slider which may be updated dynamically when the property changes in your code (seeVar.set(Object)) or when the user moves the slider.- Returns:
- A builder instance for the provided
JSlider, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifalign,min,maxorvalueisnull.- See Also:
-
of
Use this to create a builder for the providedJComboBoxinstance.
This is useful when you want to write declarative UI with a customJComboBoxtype. Also seecomboBox()for a more convenient way to create a newJComboBoxinstance. -
comboBox
Use this to create a UI builder for a theJComboBoxcomponent type. This is similar toUI.of(new JComboBox()). -
comboBox
Use this to declare a UI builder for theJComboBoxcomponent type with the provided array of elements as selectable items.
Note that the user may modify the items in the provided array (if the combo box is editable), if you do not want that, consider usingcomboBoxWithUnmodifiable(Object[])orcomboBoxWithUnmodifiable(java.util.List).- Type Parameters:
E- The type of the elements in theJComboBox.- Parameters:
items- The array of elements to be selectable in theJComboBox.- Returns:
- A builder instance for the new
JComboBox, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
comboBox
Use this create a UI declaration for theJComboBoxcomponent type with the provided array of elements as selectable items and a lambda function converting each item into a user-friendlyStringrepresentation.
Note that the user may modify the items in the provided array (if the combo box is editable), if you do not want that, consider usingcomboBoxWithUnmodifiable(Object[])orcomboBoxWithUnmodifiable(java.util.List).- Type Parameters:
E- The type of the elements in theJComboBox.- Parameters:
items- The array of elements to be selectable in theJComboBox.renderer- A lambda function which is used for mapping each entry to a user-friendlyStringrepresentation.- Returns:
- A builder instance for the new
JComboBox, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
comboBoxWithUnmodifiable
Use this to declare a UI builder for theJComboBoxtype with the provided array of elements as selectable items which may not be modified by the user.- Type Parameters:
E- The type of the elements in theJComboBox.- Parameters:
items- The unmodifiable array of elements to be selectable in theJList.- Returns:
- A builder instance for the new
JComboBox, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
comboBoxWithUnmodifiable
public static <E> UIForCombo<E,JComboBox<E>> comboBoxWithUnmodifiable(E[] items, Function<E, String> renderer) Use this to declare a UI builder for theJComboBoxtype with the provided array of elements as selectable items which may not be modified by the user. Use this create a UI declaration for theJComboBoxcomponent type with the provided array of elements as selectable but unmodifiable items and a lambda function converting each item into a user-friendlyStringrepresentation.- Type Parameters:
E- The type of the elements in theJComboBox.- Parameters:
items- The unmodifiable array of elements to be selectable in the drop down list of the combo box.renderer- A lambda function which is used for mapping each entry to a user-friendlyStringrepresentation shown in the combo box drop down list.- Returns:
- A builder instance for the new
JComboBox, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
comboBox
Use this to create a builder for a newJComboBoxinstance where the provided enum based property dynamically models the selected item as well as all possible options (all the enum states). The property will be updated whenever the user selects a new item in theJComboBoxand theJComboBoxwill be updated whenever the property changes in your code (seeVar.set(Object)).
Here's an example of how to use this method:
// In your view model: enum Size { SMALL, MEDIUM, LARGE } private Var<Size> selection = Var.of(Size.SMALL); public Var<Size> selection() { return selection; } // In your view: UI.comboBox(vm.selection())Tip: The text displayed on the combo box is based on the
Object.toString()method of the enum instances. If you want to customize how they are displayed (So that 'Size.LARGE' is displayed as 'Large' instead of 'LARGE') simply override theObject.toString()method in your enum.- Type Parameters:
E- The type of the elements in the combo box.- Parameters:
selectedItem- A property modelling the selected item in the combo box.- Returns:
- A builder instance for the new
JComboBox, which enables fluent method chaining.
-
comboBox
public static <E extends Enum<E>> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> selectedItem, Function<E, String> renderer) Use this to create a builder for a newJComboBoxinstance where the provided enum based property dynamically models the selected item as well as all possible options (all the enum states). The property will be updated whenever the user selects a new item in theJComboBoxand theJComboBoxwill be updated whenever the property changes in your code (seeVar.set(Object)).
Here's an example of how to use this method:
// In your view model: enum Size { SMALL, MEDIUM, LARGE } private Var<Size> selection = Var.of(Size.SMALL); public Var<Size> selection() { return selection; } // In your view: UI.comboBox(vm.selection(), e -> switch (e) { case SMALL -> "Small"; case MEDIUM -> "Medium"; case LARGE -> "Large"; })Note that the second argument is a function that maps each enum state to the text which is actually displayed in the combo box to the user.
- Type Parameters:
E- The type of the elements in the combo box.- Parameters:
selectedItem- A property modelling the selected item in the combo box.renderer- A lambda function which is used for mapping each entry to a user friendlyStringrepresentation.- Returns:
- A builder instance for the new
JComboBox, which enables fluent method chaining.
-
comboBox
Use this to declare a builder for a newJComboBoxinstance with the provided list of elements as selectable items.- Type Parameters:
E- The type of the elements in the list.- Parameters:
items- The list of elements to be selectable in theJComboBox.- Returns:
- A builder instance for the provided
JComboBox, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
comboBox
Use this to declare a builder for a newJComboBoxinstance with the provided list of elements as selectable items and a custom renderer function to display the items in the combo box as text.
Here's an example of how to use this method:
In this example, the combo box will display the items as "APPLE", "BANANA", "CHERRY". The provided function is called for each item in the list to determine the text that should be displayed in the combo box.// In your view model: List<String> items = List.of("Apple", "Banana", "Cherry"); // In your view: UI.comboBox(items, fruit -> fruit.toUpperCase())- Type Parameters:
E- The type of the elements in the list.- Parameters:
items- The list of elements to be selectable in theJComboBox.renderer- A function that maps each item to the text that should be displayed in the combo box.- Returns:
- A builder instance for the
JComboBoxtype, to allow for fluent method chaining.
-
comboBoxWithUnmodifiable
Use this to create a builder for a newJComboBoxinstance with the providedUI.ListViewof elements as selectable items which may not be modified by the user.
So even if the combo box is editable, the user will not be able to modify the items in the list (the selected item inside the text field can still be modified though). -
comboBoxWithUnmodifiable
public static <E> UIForCombo<E,JComboBox<E>> comboBoxWithUnmodifiable(List<E> items, Function<E, String> renderer) Creates a declarative combo box UI based on the provided list of items, which may not be modified by the user.
An additional renderer function is provided to customize how the items are displayed as texts in the combo box.
Here's an example of how the method may be used:
In this example, the combo box will display the items as "john", "jane", "jack". The provided function is called for each item in the list to determine the text that should be displayed in the combo box.// In your view model: List<String> items = List.of("John", "Jane", "Jack"); // In your view: UI.comboBoxWithUnmodifiable(items, name -> name.toLowerCase())- Type Parameters:
E- The type of the elements in the list.- Parameters:
items- The list of elements to be selectable in theJComboBox.renderer- A function that maps each item to the text that should be displayed in the combo box.- Returns:
- A builder instance for the
JComboBoxtype, to allow for fluent method chaining.
-
comboBox
Creates a combo box UI builder node with aVarproperty as the model for the current selection and a list of items as a dynamically sized model for the selectable items.Note that the provided list may be mutated by the combo box UI component
- Type Parameters:
E- The type of the elements in the list.- Parameters:
selection- The property holding the current selection.items- The list of selectable items.- Returns:
- A builder instance for the provided
JList, which enables fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> selection, List<E> items, Function<E, String> renderer) Creates a declarative combo box UI based on the provided selection property and the list of items as well as a custom renderer function to display the items as text in the combo box.
Here's an example of how the method can be used:
In this example, the provided function is called for each item in the list to determine the text that should be displayed in the combo box.// In your view model: List<String> days = List.of("Monday", "Tuesday", "Wednesday"); Var<String> selectedDay = Var.of("Monday"); // In your view: UI.comboBox(selectedDay, days, day -> "Day: " + day) // The combo box will display the items as "Day: Monday", "Day: Tuesday", "Day: Wednesday"- Type Parameters:
E- The type of the elements in the list.- Parameters:
selection- The property holding the current selection, which will be updated whenever the user selects a new item.items- The list of selectable items.renderer- A function that maps each item to the text that should be displayed in the combo box.- Returns:
- A builder instance for the
JComboBoxtype, to allow for fluent method chaining.
-
comboBox
Use this to create a builder for a newJComboBoxinstance with the provided properties list object as selectable (and mutable) items.- Type Parameters:
E- The type of the elements in the list.- Parameters:
items- TheVarsproperties of elements to be selectable in theJComboBox.- Returns:
- A declarative builder for the provided
JComboBox, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Vars<E> items, Function<E, String> renderer) Creates a declarative UI builder for theJComboBoxcomponent type where the provided property list dynamically models the selectable items in the combo box and a renderer function determines how the items are displayed as text in the combo box dropdown list.
The following example demonstrates how this method may be used:
// In your view model: enum Coffee { ESPRESSO, LATTE, CAPPUCCINO } Vars<Coffee> items = Vars.of(Coffee.ESPRESSO, Coffee.LATTE, Coffee.CAPPUCCINO); // In your view: UI.comboBox(items, coffee -> switch (coffee) { case ESPRESSO -> "Espresso"; case LATTE -> "Latte"; case CAPPUCCINO -> "Cappuccino"; }) .onSelection( it -> ... )- Type Parameters:
E- The type of the elements in the list.- Parameters:
items- The property holding the list of selectable items.renderer- A function that maps each item to the text that should be displayed in the combo box.- Returns:
- A declarative builder for the
JComboBoxtype, to allow for fluent method chaining.
-
comboBox
Use this to create a builder for a newJComboBoxinstance with the provided properties list object as selectable (and immutable) items which may not be modified by the user. -
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Vals<E> items, Function<E, String> renderer) Creates a declarative UI builder for theJComboBoxcomponent type where the provided property list dynamically models the selectable items in the combo box and a renderer function determines how the items are displayed as text in the combo box dropdown list.
The following example demonstrates how this method may be used:
Note that the provided list may not be modified by the user due to the use of the// In your view model: enum Coffee { ESPRESSO, LATTE, CAPPUCCINO } Vals<Coffee> items = Vals.of(Coffee.ESPRESSO, Coffee.LATTE, Coffee.CAPPUCCINO); // In your view: UI.comboBox(items, coffee -> switch (coffee) { case ESPRESSO -> "Espresso"; case LATTE -> "Latte"; case CAPPUCCINO -> "Cappuccino"; }) .onSelection( it -> ... )Valsproperty type, which is an immutable view of the list of items.- Type Parameters:
E- The type of the elements in the list.- Parameters:
items- The property holding the list of selectable items.renderer- A function that maps each item to the text that should be displayed in the combo box.- Returns:
- A declarative builder for the
JComboBoxtype, to allow for fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> selection, sprouts.Vars<E> items) Creates a combo box UI builder node with aVarproperty as the model for the current selection and a list of items as a dynamically sized model for the selectable items.Note that the provided list may be mutated by the combo box UI component
- Type Parameters:
E- The type of the elements in the list.- Parameters:
selection- The property holding the current selection.items- The list of selectable items.- Returns:
- A builder instance for the provided
JList, which enables fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> selection, sprouts.Vars<E> items, Function<E, String> renderer) Creates a declarative combo box UI based on the provided selection property, a property list of selectable items as well as a custom renderer function to display the items as the desired text in the combo box.
Here's an example of how the method can be used:
In the example above, the provided function is called for each item in the list to determine the text that should be displayed in the combo box dropdown list.// In your view model: enum Sentiment { POSITIVE, NEUTRAL, NEGATIVE } Var<Sentiment> selected = Var.of(Sentiment.NEUTRAL); Vars<Sentiment> sentiments = Vars.of(Sentiment.POSITIVE, Sentiment.NEUTRAL, Sentiment.NEGATIVE); // In your view: UI.comboBox(selected, sentiments, s -> switch (s) { case POSITIVE -> "Positive"; case NEUTRAL -> "Neutral"; case NEGATIVE -> "Negative"; })- Type Parameters:
E- The type of the elements in the list.- Parameters:
selection- The property holding the current selection, which will be updated whenever the user selects a new item.items- A property list of selectable items.renderer- A function that maps each item to the text that should be displayed in the combo box.- Returns:
- A declarative builder for the
JComboBoxtype, to allow for fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> selection, sprouts.Vals<E> items) Creates a combo box UI builder node with aVarproperty as the model for the current selection and a property list of items as a dynamically sized model for the selectable items which may not be modified by the user. UsecomboBox(Var, Vars)if you want the user to be able to modify the items.- Type Parameters:
E- The type of the elements in the list.- Parameters:
selection- The property holding the current selection.items- The list of selectable items which may not be modified by the user.- Returns:
- A builder instance for the provided
JList, which enables fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> selection, sprouts.Vals<E> items, Function<E, String> renderer) Creates a declarative combo box UI based on the provided selection property, a property list of selectable items as well as a custom renderer function to display the items as the desired text in the combo box.
Here's an example of how the method can be used:
In the example above, the provided function is called for each item in the list to determine the text that should be displayed in the combo box dropdown list. Note that we are using the// In your view model: enum BloodType { A, B, AB, O } Var<Sentiment> selected = Var.of(BloodType.A); Vals<Sentiment> types = Vals.of(BloodType.A, BloodType.B, BloodType.AB, BloodType.O); // In your view: UI.comboBox(selected, types, t -> switch (t) { case A -> "Type A"; case B -> "Type B"; case AB -> "Type AB"; case O -> "Type O"; })Valsproperty type to ensure the list of items is immutable and cannot be modified by the user. If you want the user to be able to modify the items, usecomboBox(Var, Vars, Function).- Type Parameters:
E- The type of the elements in the list.- Parameters:
selection- The property holding the current selection, which will be updated whenever the user selects a new item.items- A property list of selectable items which may not be modified by the user.renderer- A function that maps each item to the text that should be displayed in the combo box.- Returns:
- A declarative builder for the
JComboBoxtype, to allow for fluent method chaining.
-
comboBox
Creates a combo box UI builder node with aVarproperty as the model for the current selection and an array of items as a fixed-size model for the selectable items.Note that the provided array may be mutated by the combo box UI component
- Type Parameters:
E- The type of the elements in the combo box.- Parameters:
var- The property holding the current selection.items- The array of selectable items.- Returns:
- A builder instance for the provided
JList, which enables fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> var, E[] items, Function<E, String> renderer) Creates a combo box UI declaration with aVarproperty as the model for the current selection and an array of items as a fixed-size model for the selectable items, as well as a lambda function which maps each combo box item to a user-friendlyStringrepresentation.Note that the provided array may be mutated by the combo box UI component.
- Type Parameters:
E- The type of the elements in the combo box.- Parameters:
var- The property holding the current selection.items- The array of selectable items.renderer- A function that maps each item to the text that should be displayed in the combo box. It is intended to make the type of entry more human readable and thereby user-friendly.- Returns:
- A builder instance for the provided
JList, which enables fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> var, sprouts.Var<sprouts.Tuple<E>> items) Creates a combo box UI builder node with aVarproperty as the model for the current selection and a tuple property of items as a selectable items model which may be modified by the user or change dynamically in your code. So whenever the tuple property changes, the combo box will be updated with the new selectable items.- Type Parameters:
E- The type of the elements in the combo box.- Parameters:
var- The property holding the current selection.items- The property holding a tuple of selectable items which can be mutated by the combo box.- Returns:
- A builder instance for the provided
JList, which enables fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> var, sprouts.Var<sprouts.Tuple<E>> items, Function<E, String> renderer) Creates a declarative combo box UI based on the provided selection property, a property of an array of selectable items and a custom renderer function to display the items as the desired text in the combo box.
Here's an example of how the method can be used:
In the example above, the provided function is called for each item in the list to determine the text that should be displayed in the combo box dropdown list. Note that changing the contents of the array in the property may not properly update the selectable options in the combo box. Instead, ensure that the// In your view model: enum Cost { CHEAP, MODERATE, EXPENSIVE } Var<Cost> selected = Var.of(Cost.CHEAP); Var<Cost[]> costs = Var.of(Cost.values()); // In your view: UI.comboBox(selected, costs, c -> switch (c) { case CHEAP -> "Cheap"; case MODERATE -> "Moderate"; case EXPENSIVE -> "Expensive"; })Var.set(Object), orVal.fireChange(Channel)method is used to update the available options in the combo box.- Type Parameters:
E- The type of the elements in the list.- Parameters:
var- The property holding the current selection, which will be updated whenever the user selects a new item.items- A property array of selectable items which can be mutated by the user.renderer- A function that maps each item to the text that should be displayed in the combo box.- Returns:
- A declarative builder for the
JComboBoxtype, to allow for fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> selectedItem, sprouts.Val<sprouts.Tuple<E>> items) Creates a combo box UI builder node with aVarproperty as the model for the current selection and a tuple property of items as a selectable items model that may change dynamically. So when the tuple in the property changes, the selectable items in the combo box will be updated accordingly.Note that the supplied tuple property may not be modified by the user. If you want the user to be able to modify the items, use
comboBox(Var, Var).- Type Parameters:
E- The type of the elements in the combo box.- Parameters:
selectedItem- The property holding the current selection.items- The property holding a tuple of selectable items which may not be modified by the user.- Returns:
- A builder instance for the provided
JList, which enables fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> selectedItem, sprouts.Val<sprouts.Tuple<E>> items, Function<E, String> renderer) Creates a declarative combo box UI based on the provided selection property, a property of an array of selectable items and a custom renderer function to display the items as the desired text in the combo box.
Here's an example of how the method can be used:
In this example the provided function is called for each item in the list to determine the text that should be displayed in the combo box dropdown list. Note that changing the contents of the array in the property may not properly update the selectable options in the combo box. Instead, ensure that the// In your view model: enum Vehicle { TRAIN, BIKE, BUS } Var<Vehicle> selected = Var.of(Vehicle.BIKE); Val<Vehicle[]> vehicles = Val.of(Vehicle.values()); // In your view: UI.comboBox(selected, vehicles, v -> switch (v) { case TRAIN -> "Train"; case BIKE -> "Bike"; case BUS -> "Bus"; })Var.set(Object), orVal.fireChange(Channel)method is used to update the available options in the combo box.- Type Parameters:
E- The type of the elements in the list.- Parameters:
selectedItem- The property holding the current selection, which will be updated whenever the user selects a new item.items- A property array of selectable items which may not be modified by the user.renderer- A function that maps each item to the text that should be displayed in the combo box.- Returns:
- A declarative builder for the
JComboBoxtype, to allow for fluent method chaining.
-
comboBox
Created a combo box UI builder node with the providedComboBoxModel.- Type Parameters:
E- The type of the elements in the combo box.- Parameters:
model- The model to be used by the combo box.- Returns:
- A builder instance for the provided
JList, which enables fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(ComboBoxModel<E> model, Function<E, String> renderer) Created a combo box UI builder node with the providedComboBoxModeland a lambda function mapping each model entry to a user-friendly human-readableStringrepresentation.- Type Parameters:
E- The type of the elements in the combo box.- Parameters:
model- The model to be used by the combo box.renderer- A function that maps each item to the text that should be displayed in the combo box. It is intended to make the type of entry more human-readable and thereby user-friendly.- Returns:
- A builder instance for the provided
JList, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJSpinnerinstance.- Type Parameters:
S- The type parameter of the concreteJSpinnersubclass to be used by the builder.- Parameters:
spinner- TheJSpinnerinstance to create a builder for. The providedJSpinnerinstance must not benull.- Returns:
- A builder instance for the provided
JSpinner, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifspinnerisnull.
-
spinner
Use this to create a builder for a newJSpinnerUI component. This is in essence a convenience method forUI.of(new JSpinner()).- Returns:
- A builder instance for a new
JSpinner, which enables fluent method chaining.
-
spinner
Use this to create a builder for the providedJSpinnerinstance with the providedSpinnerModelas the model.- Parameters:
model- TheSpinnerModelto be used by theJSpinner.- Returns:
- A builder instance for the provided
JSpinner, which enables fluent method chaining.
-
spinner
Use this factory method to create aJSpinnerbound to a property of any type. The property will be updated when the user modifies its value.- Parameters:
value- A property of any type which should be bound to this spinner.- Returns:
- A builder instance for the provided
JSpinner, which enables fluent method chaining.
-
spinner
Use this to create a builder for the providedJSpinnerinstance with the providedmin,max, defaultvalueandstepas the model. -
spinner
Use this to create a builder for the providedJSpinnerinstance with the providedmin,maxand defaultvalueas the model. -
of
Use this to create a builder for the providedJLabelinstance. -
label
Use this to create a builder for theJLabelUI component. This is in essence a convenience method forUI.of(new JLabel(text).- Parameters:
text- The text which should be displayed on the label.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
label
Use this to create a builder for theJLabelUI component. This is in essence a convenience method forUI.of(new JLabel(text, alignment)).- Parameters:
text- The text which should be displayed on the label.alignment- The horizontal alignment of the text.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
label
Use this to create a builder for theJLabelUI component.- Parameters:
text- The text which should be displayed on the label.alignment- The vertical and horizontal alignment of the text.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
label
Use this to create a builder for theJLabelUI component. This is in essence a convenience method forUI.of(new JLabel(Val<String> text).- Parameters:
text- The text property which should be bound to the label.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
label
Use this to create a builder for theJLabelUI component. This is in essence a convenience method forUI.of(new JLabel(Val<String> text, alignment).- Parameters:
text- The text property which should be bound to the label.alignment- The horizontal alignment of the text.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
label
Use this to create a UI builder for a text-less label containing and displaying an icon.- Parameters:
icon- The icon which should be placed into aJLabel.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
label
Use this to create a UI builder for a text-less label containing and displaying an icon. The icon is specified by aIconDeclarationwhich is essentially just a path to an icon resource. If the icon cannot be found, the label will be empty. Note that loaded icons are cached, so if you load the same icon multiple times, the same icon instance will be used (seeSwingTree.getIconCache()).- Parameters:
icon- The icon which should be placed into aJLabel.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
labelWithIcon
Use this to create a UI builder for a text-less label containing and displaying an icon dynamically.But note that you may not use the
IconorImageIconclasses directly, instead you must use implementations of theIconDeclarationinterface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is that traditional Swing icons are heavy objects whose loading may or may not succeed. Therefore, they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclarationinterface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.This is especially useful in the case of unit tests for your view model, where the icon may not be available at all, but you still want to test the behavior of your view model.
- Parameters:
icon- The icon property which should dynamically provide a desired icon for theJLabel.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
label
Use this to create a UI builder for a text-less label containing and displaying an icon.- Parameters:
width- The width of the icon when displayed on the label.height- The height of the icon when displayed on the label.icon- The icon which should be placed into aJLabel.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
label
Use this to create a UI builder for a text-less label containing and displaying an icon. The icon is specified by aIconDeclarationwhich is essentially just a path to an icon resource. If the icon cannot be found, the label will be empty. Note that loaded icons are cached, so if you load the same icon multiple times, the same icon instance will be used (seeSwingTree.getIconCache()).- Parameters:
width- The width of the icon when displayed on the label.height- The height of the icon when displayed on the label.icon- The icon which should be placed into aJLabel.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
boldLabel
Use this to create a UI builder for aJLabelwith bold font. This is in essence a convenience method forUI.label(String text).makeBold().- Parameters:
text- The text which should be displayed on the label.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
boldLabel
Use this to create a UI builder for a boundJLabelwith bold font. This is in essence a convenience method forUI.label(Val<String> text).makeBold().- Parameters:
text- The text property which should be displayed on the label dynamically.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
html
Use this to create a builder for aJLabeldisplaying HTML. This is in essence a convenience method forUI.of(new JLabel("<html>" + text + "</html>")).- Parameters:
text- The html text which should be displayed on the label.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
html
Use this to create a builder for aJLabeldisplaying HTML. This is in essence a convenience method forUI.of(new JLabel("<html>" + text + "</html>")).- Parameters:
text- The html text property which should be bound to the label.- Returns:
- A builder instance for the label, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJIconinstance. -
icon
Creates a builder node wrapping a newJIconinstance with the provided icon displayed on it.- Parameters:
icon- The icon which should be displayed on theJIcon.- Returns:
- A builder instance for the icon, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided icon is null.
-
icon
Creates a builder node wrapping a newJIconinstance with the icon found at the path provided by the suppliedIconDeclarationdisplayed on it. Note that the icon will be cached by theJIconinstance, so that it will not be reloaded.- Parameters:
icon- The icon which should be displayed on theJIcon.- Returns:
- A builder instance for the icon, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided icon is null.
-
icon
Creates a UI declaration for aJIconwhich is dynamically bound to the providedValproperty containing anIconDeclaration. When theIconDeclarationof the property changes, the icon displayed on theJIconwill be updated accordingly.- Parameters:
icon- The property containing theIconDeclarationwhoseIconshould be displayed on theJIcon.- Returns:
- A declarative builder for the
JIcontype, to allow for fluent method chaining.
-
icon
Creates a builder node wrapping a newJIconinstance with the provided icon scaled to the provided width and height.- Parameters:
width- The width of the icon when displayed on theJIcon.height- The height of the icon when displayed on theJIcon.icon- The icon which should be placed into aJIconfor display.- Returns:
- A builder instance for the icon, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided icon is null.
-
icon
Creates a declarative builder for theJIconcomponent with the supplied icon scaled to fit the specifiedSize, which consists of a width and height.- Parameters:
size- The size of the icon when displayed on theJIcon.icon- The icon which should be placed into aJIconfor display.- Returns:
- A builder instance for the icon, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided icon is null.
-
icon
Creates a builder node wrapping a newJIconinstance with the icon found at the path defined by the suppliedIconDeclarationdisplayed on it and scaled to the provided width and height. Note that the icon will be cached by theJIconinstance, so that it will not be reloaded.- Parameters:
width- The width of the icon when displayed on theJIcon.height- The height of the icon when displayed on theJIcon.icon- The icon which should be placed into aJIconfor display.- Returns:
- A builder instance for the icon, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided icon is null.
-
icon
Creates a declarative builder for theJIconcomponent with the icon found at the path defined by the suppliedIconDeclarationdisplayed on it and scaled to fit the providedSize, consisting of a width and height. Note that the icon will be cached by theJIconinstance, so that it will not be reloaded.- Parameters:
size- The size of the icon when displayed on theJIcon.icon- The icon which should be placed into aJIconfor display.- Returns:
- A builder instance for the icon, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided icon is null.
-
icon
Creates a builder node wrapping a newJIconinstance with the icon found at the provided path displayed on it and scaled to the provided width and height. Note that the icon will be cached by theJIconinstance, so that it will not be reloaded.- Parameters:
width- The width of the icon when displayed on theJIcon.height- The height of the icon when displayed on theJIcon.iconPath- The path to the icon which should be displayed on theJIcon.- Returns:
- A builder instance for the icon, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided icon path is null.
-
icon
Creates a declarative builder for theJIconcomponent with the icon found at the path defined by the suppliedIconDeclarationdisplayed on it and scaled to fit the providedSize, consisting of a width and height. Note that the icon will be cached by theJIconinstance, so that it will not be reloaded.- Parameters:
size- The size of the icon when displayed on theJIcon.iconPath- The path to the icon which should be displayed on theJIcon.- Returns:
- A builder instance for the icon, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided icon path is null.
-
icon
Creates a builder node wrapping a newJIconinstance with the icon found at the provided path displayed on it. Note that the icon will be cached by theJIconinstance, so that it will not be reloaded.- Parameters:
iconPath- The path to the icon which should be displayed on theJIcon.- Returns:
- A builder instance for the icon, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided icon path is null.
-
checkBox
Creates a builder node wrapping a newJCheckBoxinstance with the provided text displayed on it.- Parameters:
text- The text which should be displayed on the checkbox.- Returns:
- A builder instance for the checkbox, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided text is null.
-
checkBox
Creates a builder node wrapping a newJCheckBoxinstance where the provided text property dynamically displays its value on the checkbox.- Parameters:
text- The text property which should be bound to the checkbox.- Returns:
- A builder instance for the checkbox, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided text property is null.
-
checkBox
public static UIForCheckBox<JCheckBox> checkBox(sprouts.Val<String> text, sprouts.Var<Boolean> isChecked) Creates a builder node wrapping a newJCheckBoxinstance where the provided text property dynamically displays its value on the checkbox and the provided selection property dynamically determines whether the checkbox is selected or not.- Parameters:
text- The text property which should be bound to the checkbox. This is the text which is displayed on the checkbox.isChecked- The selection property which should be bound to the checkbox and determines whether it is selected or not.- Returns:
- A builder instance for the checkbox, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided text property is null.
-
checkBox
Creates a builder node wrapping a newJCheckBoxinstance with the provided text displayed on it and the provided selection property dynamically determining whether the checkbox is selected or not.- Parameters:
text- The text which should be displayed on the checkbox.isChecked- The selection property which should be bound to the checkbox and determines whether it is selected or not.- Returns:
- A builder instance for the checkbox, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided text is null.
-
of
Use this to create a builder for the providedJCheckBoxinstance.- Type Parameters:
B- The type parameter of the concreteJCheckBoxsubclass to be used by the builder.- Parameters:
component- TheJCheckBoxinstance to be used by the builder.- Returns:
- A builder instance for the provided
JCheckBox, which enables fluent method chaining. - Throws:
IllegalArgumentException- If the provided checkbox is null.
-
radioButton
Creates a builder node wrapping a newJRadioButtoninstance with the provided text displayed on it.- Parameters:
text- The text which should be displayed on the radio button.- Returns:
- A builder instance for the radio button, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided text is null.
-
radioButton
Creates a builder node wrapping a newJRadioButtoninstance where the provided text property dynamically displays its value on the radio button.- Parameters:
text- The text property which should be bound to the radio button.- Returns:
- A builder instance for the radio button, which enables fluent method chaining.
-
radioButton
public static UIForRadioButton<JRadioButton> radioButton(sprouts.Val<String> text, sprouts.Var<Boolean> selected) Creates a builder node wrapping a newJRadioButtoninstance where the provided text property dynamically displays its value on the radio button and the provided selection property dynamically determines whether the radio button is selected or not.- Parameters:
text- The text property which should be bound to the radio button. This is the text which is displayed on the radio button.selected- The selection property which should be bound to the radio button and determines whether it is selected or not.- Returns:
- A builder instance for the radio button, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided text property is null.
-
radioButton
public static UIForRadioButton<JRadioButton> radioButton(String text, sprouts.Var<Boolean> selected) Creates a builder node wrapping a newJRadioButtoninstance with the provided text displayed on it and the provided selection property dynamically determining whether the radio button is selected or not.- Parameters:
text- The text which should be displayed on the radio button.selected- The selection property which should be bound to the radio button and determines whether it is selected or not.- Returns:
- A builder instance for the radio button, which enables fluent method chaining.
- Throws:
IllegalArgumentException- If the provided text is null.
-
radioButton
public static <E extends Enum<E>> UIForRadioButton<JRadioButton> radioButton(E state, sprouts.Var<E> selection) Creates a builder node wrapping a newJRadioButtoninstance dynamically bound to an enum basedVarinstance which will be used to dynamically model the selection state of the wrappedJToggleButtontype by checking weather the property matches the provided enum or not.
Here's an example of how to use this method:
// In your view model: enum Size { SMALL, MEDIUM, LARGE } private Var<Size> selection = Var.of(Size.SMALL); public Var<Size> selection() { return selection; } // In your view: UI.panel() .add(UI.radioButton(Size.SMALL, vm.selection()) .add(UI.radioButton(Size.MEDIUM, vm.selection()) .add(UI.radioButton(Size.LARGE, vm.selection())Tip: For the text displayed on the radio buttons, the enums will be converted to strings using
Object.toString()method. If you want to customize how they are displayed (So that 'Size.LARGE' is displayed as 'Large' instead of 'LARGE') simply override theObject.toString()method in your enum.- Type Parameters:
E- The type of the enum which thisJToggleButtonshould represent.- Parameters:
state- The referenceEnumwhich thisJToggleButtonshould represent.selection- TheVarinstance which will be used to dynamically model the selection state of the wrappedJToggleButtontype.- Returns:
- A builder instance for the radio button, which enables fluent method chaining.
- Throws:
IllegalArgumentException- ifselectedisnull.
-
radioButton
public static <T> UIForRadioButton<JRadioButton> radioButton(String label, T state, sprouts.Var<T> selection) Creates a declarative UI builder for theJRadioButtoncomponent type which is dynamically bound to the equality of the provided state and the provided selection property. This means that the radio button will be selected if the provided state is equal to the value of the provided selection property and deselected otherwise.
A typical use case for this is to use an enum based property to model the selection state of the radio button like so:// In your view model: enum Size { SMALL, MEDIUM, LARGE } private Var<Size> selection = Var.of(Size.SMALL); public Var<Size> selection() { return selection; } // In your view: UI.panel() .add(UI.radioButton("Small", Size.SMALL, vm.selection()) .add(UI.radioButton("Medium", Size.MEDIUM, vm.selection()) .add(UI.radioButton("Large", Size.LARGE, vm.selection())- Type Parameters:
T- The type of the state object which this radio button should represent.- Parameters:
label- The text which should be displayed on the radio button.state- The reference object which this radio button should represent.selection- The property which will be used to model the selection state of the radio button.- Returns:
- A builder instance for the radio button, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJRadioButtoninstance.- Type Parameters:
R- The type of theJRadioButtoninstance which should be wrapped by the builder.- Parameters:
component- TheJRadioButtoninstance which should be wrapped by the builder.- Returns:
- A builder instance for the provided
JRadioButton, which enables fluent method chaining.
-
toggleButton
Use this to create a builder for aJToggleButtoninstance.- Returns:
- A builder instance for a new
JToggleButton, which enables fluent method chaining.
-
toggleButton
Use this to create a builder for a newJToggleButtoninstance with the provided text displayed on it.- Parameters:
text- The text which should be displayed on the toggle button.- Returns:
- A builder instance for a new
JToggleButton, which enables fluent method chaining.
-
toggleButton
Use this to create a builder for a newJToggleButtoninstance where the provided text property dynamically displays its value on the toggle button.Note that the provided text property may not be null, and it is also not permitted to contain null values, instead use an empty string instead of null.
- Parameters:
text- The text property which should be bound to the toggle button.- Returns:
- A builder instance for a new
JToggleButton, which enables fluent method chaining.
-
toggleButton
Use this to create a builder for a newJToggleButtoninstance where the provided boolean property dynamically determines whether the toggle button is selected or not.- Parameters:
isToggled- The boolean property which should be bound to the toggle button and determines whether it is selected or not.- Returns:
- A builder instance for a new
JToggleButton, which enables fluent method chaining.
-
toggleButton
public static UIForToggleButton<JToggleButton> toggleButton(String text, sprouts.Var<Boolean> isToggled) Use this to create a builder for a newJToggleButtoninstance with the provided text displayed on it and the provided boolean property dynamically determining whether the toggle button is selected or not.- Parameters:
text- The text which should be displayed on the toggle button.isToggled- The boolean property which should be bound to the toggle button and determines whether it is selected or not.- Returns:
- A builder instance for a new
JToggleButton, which enables fluent method chaining.
-
toggleButton
public static UIForToggleButton<JToggleButton> toggleButton(sprouts.Val<String> text, sprouts.Var<Boolean> isToggled) Use this to create a builder for a newJToggleButtoninstance where the provided text property dynamically displays its value on the toggle button and the provided boolean property dynamically determines whether the toggle button is selected or not.- Parameters:
text- The text property which should be bound to the toggle button. This is the text which is displayed on the toggle button.isToggled- The boolean property which should be bound to the toggle button and determines whether it is selected or not.- Returns:
- A builder instance for a new
JToggleButton, which enables fluent method chaining.
-
toggleButton
Use this to create a builder for a newJToggleButtoninstance with the providedIcondisplayed on it.- Parameters:
icon- The icon which should be displayed on the toggle button.- Returns:
- A builder instance for the provided
JToggleButton, which enables fluent method chaining.
-
toggleButton
Use this to create a builder for a newJToggleButtoninstance with anImageIcondisplayed on it and the suppliedUI.FitComponentdetermining how the icon should be fit the content bounds of the button.- Parameters:
icon- The icon which should be displayed on the toggle button.fit- TheUI.FitComponentwhich determines how the icon should be fitted into the button.- Returns:
- A builder instance for a
JToggleButton, which enables fluent method chaining.
-
toggleButton
Use this to create a builder for theJToggleButtonUI component with an icon displayed on it scaled according to the provided width and height.- Parameters:
width- The width to which the icon should be scaled to.height- The height to which the icon should be scaled to.icon- The icon to be displayed on top of the button.- Returns:
- A builder instance for a
JToggleButton, which enables fluent method chaining.
-
toggleButton
public static UIForToggleButton<JToggleButton> toggleButton(int width, int height, IconDeclaration icon) Use this to create a builder for theJToggleButtonUI component with an icon displayed on it scaled according to the provided width and height.- Parameters:
width- The width to which the icon should be scaled to.height- The height to which the icon should be scaled to.icon- TheIconDeclarationwhose icon ought to be displayed on top of the button.- Returns:
- A builder instance for a
JToggleButton, which enables fluent method chaining.
-
toggleButton
public static UIForToggleButton<JToggleButton> toggleButton(int width, int height, IconDeclaration icon, UI.FitComponent fit) Creates a declarative toggle button builder for aJToggleButtondisplaying the provided icon scaled to fit the desired size andUI.FitComponentpolicy.- Parameters:
width- The width to which the icon should be scaled to.height- The height to which the icon should be scaled to.icon- TheIconDeclarationwhose icon ought to be displayed on top of the button.fit- TheUI.FitComponentwhich determines how the icon should be fitted into the button.- Returns:
- A builder instance for a
JToggleButton, which enables fluent method chaining.
-
toggleButton
Use this to create a builder for a newJToggleButtoninstance with the icon found at the path provided by the suppliedIconDeclarationdisplayed on top of it. Note that the icon will be cached by theJToggleButtoninstance, so that it will not be reloaded.- Parameters:
icon- The icon which should be displayed on the toggle button.- Returns:
- A builder instance for the provided
JToggleButton, which enables fluent method chaining.
-
toggleButton
public static UIForToggleButton<JToggleButton> toggleButton(IconDeclaration icon, UI.FitComponent fit) -
toggleButton
public static UIForToggleButton<JToggleButton> toggleButton(Icon icon, sprouts.Var<Boolean> isToggled) Use this to create a builder for a newJToggleButtoninstance with the providedIcondisplayed on it and the provided boolean property dynamically determining whether the toggle button is selected or not.- Parameters:
icon- The icon which should be displayed on the toggle button.isToggled- The boolean property which should be bound to the toggle button and determines whether it is selected or not.- Returns:
- A builder instance for the provided
JToggleButton, which enables fluent method chaining.
-
toggleButtonWithIcon
public static UIForToggleButton<JToggleButton> toggleButtonWithIcon(sprouts.Val<IconDeclaration> icon) Use this to create a builder for a newJToggleButtoninstance where the providedIconDeclarationbased property dynamically displays the targeted image on the toggle button.Note that you may not use the
IconorImageIconclasses directly, instead you must use implementations of theIconDeclarationinterface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is that traditional Swing icons are heavy objects whose loading may or may not succeed. Therefore, they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclarationinterface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.This is especially useful in the case of unit tests for your view model, where the icon may not be available at all, but you still want to test the behavior of your view model.
- Parameters:
icon- The icon property which should be bound to the toggle button.- Returns:
- A builder instance for the provided
JToggleButton, which enables fluent method chaining.
-
toggleButtonWithIcon
public static UIForToggleButton<JToggleButton> toggleButtonWithIcon(sprouts.Val<IconDeclaration> icon, sprouts.Var<Boolean> isToggled) Use this to create a builder for a newJToggleButtoninstance where the providedIconDeclarationproperty dynamically displays its targeted icon on the toggle button and the provided boolean property dynamically determines whether the toggle button is selected or not.But note that you may not use the
IconorImageIconclasses directly, instead you must use implementations of theIconDeclarationinterface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is that traditional Swing icons are heavy objects whose loading may or may not succeed. Therefore, they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclarationinterface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.This is especially useful in the case of unit tests for your view model, where the icon may not be available at all, but you still want to test the behavior of your view model.
- Parameters:
icon- The icon property which should be bound to the toggle button.isToggled- The boolean property which should be bound to the toggle button and determines whether it is selected or not.- Returns:
- A builder instance for the provided
JToggleButton, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJToggleButtoninstance.- Type Parameters:
B- The type of theJToggleButtoninstance which should be wrapped by the builder.- Parameters:
component- TheJToggleButtoninstance which should be wrapped by the builder.- Returns:
- A builder instance for the provided
JToggleButton, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJTextFieldinstance.- Type Parameters:
F- The type of theJTextFieldinstance which should be wrapped by the builder.- Parameters:
component- TheJTextFieldinstance which should be wrapped by the builder.- Returns:
- A builder instance for the provided
JTextField, which enables fluent method chaining. - Throws:
IllegalArgumentException- If the provided text field is null.
-
textField
Use this to create a builder for a newJTextFieldinstance with the provided text displayed on it.- Parameters:
text- The text which should be displayed on the text field.- Returns:
- A builder instance for the provided
JTextField, which enables fluent method chaining.
-
textField
Use this to create a builder for a newJTextFieldinstance with the provided text property dynamically displaying its value on the text field. The property is aVal, meaning that it is read-only and may not be changed by the text field.- Parameters:
text- The text property which should be bound to the text field.- Returns:
- A builder instance for the provided
JTextField, which enables fluent method chaining.
-
textField
Use this to create a builder for a newJTextFieldinstance with the provided text property dynamically displaying its value on the text field. The property may also be modified by the user.- Parameters:
text- The text property which should be bound to the text field.- Returns:
- A builder instance for the provided
JTextField, which enables fluent method chaining.
-
textField
Use this to create a builder for a newJTextFieldUI component. This is in essence a convenience method forUI.of(new JTextField()).- Returns:
- A builder instance for a new
JTextField, which enables fluent method chaining.
-
textField
A convenience method for creating a builder for aJTextFieldwith the specifiedUI.HorizontalAlignmentconstant as the text orientation. You may also useUIForTextField.withTextOrientation(UI.HorizontalAlignment)to define the text orientation:UI.textField("may text") .withTextOrientation( UI.HorizontalAlignment.RIGHT );- Parameters:
direction- The text orientation type which should be used.- Returns:
- A builder instance for a new
JTextField, which enables fluent method chaining.
-
textField
A convenience method for creating a builder for aJTextFieldwith the specified text and text orientation. You may also useUIForAnyTextComponent.withText(String)andUIForTextField.withTextOrientation(UI.HorizontalAlignment)to define the text and text orientation:UI.textField() .withTextOrientation( UI.HorizontalAlignment.LEFT ) .withText(text);- Parameters:
orientation- Defines the orientation of the text inside the text field.
This may be one of the following constants:text- The new text to be set for the wrapped text component type.- Returns:
- A builder instance for a new
JTextField, which enables fluent method chaining.
-
textField
public static UIForTextField<JTextField> textField(UI.HorizontalAlignment textOrientation, sprouts.Var<String> text) Creates a UI builder for a text field where the text is aligned according to the providedUI.HorizontalAlignmentconstant, and the text of the text field is bound to a string property. Whenever the user modifies the text inside the text field, the value of the property will be updated accordingly. Conversely, when the state of the property is modified inside your view model through theVar.set(Object)method, the text field will be updated accordingly.You may also use
UIForTextField.withTextOrientation(UI.HorizontalAlignment)andUIForAnyTextComponent.withText(Var)to define the text orientation and text property of the text field:UI.textField() .withTextOrientation( UI.HorizontalAlignment.RIGHT ) .withText(textProperty);- Parameters:
textOrientation- The orientation of the text inside the text field.text- A string property which is used to model the text of this text field.- Returns:
- A text field UI builder for declarative UI design based on method chaining and nesting of SwingTree builder types.
-
textField
public static UIForTextField<JTextField> textField(UI.HorizontalAlignment orientation, sprouts.Val<String> text) Creates a UI builder for a text field where the text is aligned according to the providedUI.HorizontalAlignmentconstant, and the text of the text field is uni-directionally bound to a string property. Whenever the state of the property is modified inside your view model through theVar.set(Object)method, the text field will be updated accordingly.
But note that when the user modifies the text inside the text field, the value of the property will not be updated.You may also use
UIForTextField.withTextOrientation(UI.HorizontalAlignment)andUIForAnyTextComponent.withText(Val)to define the text orientation and text property of the text field:UI.textField() .withTextOrientation( UI.HorizontalAlignment.RIGHT ) .withText(readOnlyTextProperty);- Parameters:
orientation- The orientation of the text inside the text field. This is the direction in which the text is aligned.
It may be one of the following constants:text- A string property which is used to model the text of this text field uni-directionally (read-only).- Returns:
- A text field UI builder for declarative UI design based on method chaining and nesting of SwingTree builder types.
-
numericTextField
Use this to create a builder for a newJTextFieldinstance with the provided number property dynamically displaying its value on the text field. The property is aVar, meaning that it can be modified by the user.The number property will only receive values if the text field contains a valid number.
Also note that the provided property is not allowed to contain
nullvalues, as this would lead to aNullPointerExceptionbeing thrown.- Type Parameters:
N- The type of the number property which should be bound to the text field.- Parameters:
number- The number property which should be bound to the text field.- Returns:
- A builder instance for the provided
JTextField, which enables fluent method chaining.
-
numericTextField
public static <N extends Number> UIForTextField<JTextField> numericTextField(sprouts.Var<N> number, Function<N, String> formatter) Use this to create a builder for a newJTextFieldinstance with the provided number property dynamically displaying its value on the text field and a function which will be used to format the number as a string.The number property will only receive values if the text in the text field can be parsed as a number, in which case the provided formatter function will be used to convert the number to a string.
Note that the provided property is not allowed to contain
nullvalues, as this would lead to aNullPointerExceptionbeing thrown.- Type Parameters:
N- The type of the number property which should be bound to the text field.- Parameters:
number- The number property which should be bound to the text field.formatter- The function which will be used to format the number as a string.- Returns:
- A builder instance for the provided
JTextField, which enables fluent method chaining.
-
numericTextField
public static <N extends Number> UIForTextField<JTextField> numericTextField(sprouts.Var<N> number, sprouts.Var<Boolean> isValid) Use this to create a builder for a newJTextFieldinstance with the provided number property dynamically displaying its value on the text field and a boolean property which will be set totrueif the text field contains a valid number, andfalseotherwise.The number property will only receive values if the text in the text field can be parsed as a number, in which case the provided
Varwill be set totrue, otherwise it will be set tofalse.Note that the two provided properties are not permitted to contain
nullvalues, as this would lead to aNullPointerExceptionbeing thrown.- Type Parameters:
N- The type of the number property which should be bound to the text field.- Parameters:
number- The number property which should be bound to the text field.isValid- AVarwhich will be set totrueif the text field contains a valid number, andfalseotherwise.- Returns:
- A builder instance for the provided
JTextField, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifnumberisnull.IllegalArgumentException- ifisValidisnull.
-
numericTextField
public static <N extends Number> UIForTextField<JTextField> numericTextField(sprouts.Var<N> number, sprouts.Var<Boolean> isValid, Function<N, String> formatter) Use this to create a builder for a newJTextFieldinstance with the provided number property dynamically displaying its value on the text field and a boolean property which will be set totrueif the text field contains a valid number, andfalseotherwise.The number property will only receive values if the text in the text field can be parsed as a number, in which case the provided
Varwill be set totrue, otherwise it will be set tofalse.Note that the two provided properties are not permitted to contain
nullvalues, as this would lead to aNullPointerExceptionbeing thrown.- Type Parameters:
N- The type of the number property which should be bound to the text field.- Parameters:
number- The number property which should be bound to the text field.isValid- AVarwhich will be set totrueif the text field contains a valid number, andfalseotherwise.formatter- The function which will be used to format the number as a string.- Returns:
- A builder instance for the provided
JTextField, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifnumberisnull.IllegalArgumentException- ifisValidisnull.
-
of
Use this to create a builder for the providedJFormattedTextFieldinstance.- Parameters:
component- TheJFormattedTextFieldinstance which should be wrapped by the builder.- Returns:
- A builder instance for the provided
JFormattedTextField, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
formattedTextField
Use this to create a builder for a newJFormattedTextFieldinstance with the provided text displayed on it.- Parameters:
text- The text which should be displayed on the text field.- Returns:
- A builder instance for the provided
JFormattedTextField, which enables fluent method chaining.
-
formattedTextField
Use this to create a builder for a newJFormattedTextFieldinstance with the provided text property dynamically displaying its value in the text field. The property is aVal, meaning that it is read-only and may not be changed by the text field.- Parameters:
text- The text property which should be bound to the text field.- Returns:
- A builder instance for the provided
JFormattedTextField, which enables fluent method chaining.
-
formattedTextField
Use this to create a builder for a newJFormattedTextFieldinstance with the provided text property dynamically displaying its value in the formatted text field. The property may also be modified by the user.- Parameters:
text- The text property which should be bound to the formatted text field.- Returns:
- A builder instance for the provided
JFormattedTextField, which enables fluent method chaining.
-
formattedTextField
Use this to create a builder for a newJFormattedTextFieldUI component. This is in essence a convenience method forUI.of(new JFormattedTextField()).- Returns:
- A builder instance for a new
JFormattedTextField, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJPasswordFieldinstance.- Type Parameters:
F- The type of theJPasswordFieldinstance which should be wrapped by the builder.- Parameters:
passwordField- TheJPasswordFieldinstance which should be wrapped by the builder.- Returns:
- A builder instance for the provided
JPasswordField, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
passwordField
Use this to create a builder for a newJPasswordFieldinstance with the provided text as the initial password.- Parameters:
text- The initial password which should be displayed on the password field.- Returns:
- A builder instance for the provided
JPasswordField, which enables fluent method chaining.
-
passwordField
Use this to create a builder for a newJPasswordFieldinstance with the provided text property dynamically displaying its value in the password field. The property is aVal, meaning that it is read-only and may not be changed by the password field.- Parameters:
text- The text property which should be bound to the password field.- Returns:
- A builder instance for the provided
JPasswordField, which enables fluent method chaining.
-
passwordField
Use this to create a builder for a newJPasswordFieldinstance with the provided text property dynamically displaying its value in the password field. The property may also be modified by the user.- Parameters:
text- The text property which should be bound to the password field.- Returns:
- A builder instance for the provided
JPasswordField, which enables fluent method chaining.
-
passwordField
Use this to create a builder for a newJPasswordFieldUI component. This is in essence a convenience method forUI.of(new JPasswordField()).- Returns:
- A builder instance for a new
JPasswordField, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJProgressBarinstance.- Type Parameters:
P- The type of theJProgressBarinstance which should be wrapped by the builder.- Parameters:
progressBar- TheJProgressBarinstance which should be wrapped by the builder.- Returns:
- A builder instance for the provided
JProgressBar, which enables fluent method chaining. - Throws:
IllegalArgumentException- ifcomponentisnull.
-
progressBar
A factory method for creating a progress bar builder with a defaultJProgressBarimplementation.- Returns:
- A builder instance for the provided
JProgressBar, which enables fluent method chaining.
-
progressBar
Use this to create a builder for a newJProgressBarinstance with the provided minimum and maximum values.- Parameters:
min- The minimum value of the progress bar.max- The maximum value of the progress bar.- Returns:
- A builder instance for the provided
JProgressBar, which enables fluent method chaining.
-
progressBar
Use this to create a builder for a newJProgressBarinstance with the provided minimum, maximum and current value.- Parameters:
min- The minimum value of the progress bar.max- The maximum value of the progress bar.value- The current value of the progress bar.- Returns:
- A builder instance for the provided
JProgressBar, which enables fluent method chaining.
-
progressBar
public static UIForProgressBar<JProgressBar> progressBar(int min, int max, sprouts.Val<Integer> value) Use this to create a builder for a newJProgressBarinstance with the provided minimum, maximum and current value property dynamically bound to the progress bar.- Parameters:
min- The minimum value of the progress bar.max- The maximum value of the progress bar.value- The current value property of the progress bar.- Returns:
- A builder instance for the provided
JProgressBar, which enables fluent method chaining.
-
progressBar
Use this to create a builder for a newJProgressBarinstance with the provided alignment, minimum and maximum values. The alignment is aUI.Alignvalue, which may be eitherUI.Align.HORIZONTALorUI.Align.VERTICAL.- Parameters:
align- The alignment of the progress bar.min- The minimum value of the progress bar.max- The maximum value of the progress bar.- Returns:
- A builder instance for the provided
JProgressBar, which enables fluent method chaining.
-
progressBar
public static UIForProgressBar<JProgressBar> progressBar(UI.Align align, int min, int max, int value) Use this to create a builder for a newJProgressBarinstance with the provided alignment, minimum, maximum and current value. The alignment is aUI.Alignvalue, which may be eitherUI.Align.HORIZONTALorUI.Align.VERTICAL.- Parameters:
align- The alignment of the progress bar.min- The minimum value of the progress bar.max- The maximum value of the progress bar.value- The current value of the progress bar.- Returns:
- A builder instance for the provided
JProgressBar, which enables fluent method chaining.
-
progressBar
public static UIForProgressBar<JProgressBar> progressBar(UI.Align align, int min, int max, sprouts.Val<Integer> value) Use this to create a builder for a newJProgressBarinstance with the provided alignment, minimum, maximum and current value property dynamically bound to the progress bar. The alignment is aUI.Alignvalue, which may be eitherUI.Align.HORIZONTALorUI.Align.VERTICAL.- Parameters:
align- The alignment of the progress bar.min- The minimum value of the progress bar.max- The maximum value of the progress bar.value- The current value property of the progress bar.- Returns:
- A builder instance for the provided
JProgressBar, which enables fluent method chaining.
-
progressBar
public static UIForProgressBar<JProgressBar> progressBar(UI.Align align, sprouts.Val<Double> progress) Use this to create a builder for a newJProgressBarinstance with a default minimum and maximum value of 0 and 100 and the provided alignment and double based progress property (a property wrapping a double value between 0 and 1) dynamically bound to the progress bar. The alignment is aUI.Alignvalue, which may be eitherUI.Align.HORIZONTALorUI.Align.VERTICAL.- Parameters:
align- The alignment of the progress bar.progress- The current progress property of the progress bar, a property wrapping a double value between 0 and 1.- Returns:
- A builder instance for the provided
JProgressBar, which enables fluent method chaining.
-
progressBar
Use this to create a builder for a newJProgressBarinstance with a default minimum and maximum value of 0 and 100 and the provided alignment and double based progress property (a property wrapping a double value between 0 and 1) dynamically bound to the progress bar. The alignment is aUI.Alignvalue, which may be eitherUI.Align.HORIZONTALorUI.Align.VERTICAL.- Parameters:
align- The alignment of the progress bar.progress- The current progress property of the progress bar, a property wrapping a double value between 0 and 1.- Returns:
- A builder instance for the provided
JProgressBar, which enables fluent method chaining.
-
progressBar
public static UIForProgressBar<JProgressBar> progressBar(sprouts.Val<UI.Align> align, sprouts.Val<Double> progress) Use this to create a builder for a newJProgressBarinstance with a default minimum and maximum value of 0 and 100 and the provided alignment property and double based progress property (a property wrapping a double value between 0 and 1) dynamically bound to the progress bar. The alignment property wraps aUI.Alignvalue, which may be eitherUI.Align.HORIZONTALorUI.Align.VERTICAL. When any of the two properties change in your view model, the progress bar will be updated accordingly.- Parameters:
align- The alignment of the progress bar.progress- The current progress property of the progress bar, a property wrapping a double value between 0 and 1.- Returns:
- A builder instance for the provided
JProgressBar, which enables fluent method chaining.
-
of
Use this to create a builder for the providedJTextAreainstance. -
textArea
Use this to create a builder for a newJTextAreainstance with the provided text as the initial text.- Parameters:
text- The initial text which should be displayed on the text area.- Returns:
- A builder instance for the provided
JTextArea, which enables fluent method chaining.
-
textArea
Use this to create a builder for a newJTextAreainstance with the provided text property dynamically displaying its value in the text area. The property is aVal, meaning that it is read-only and may not be changed by the text area.- Parameters:
text- The text property which should be bound to the text area.- Returns:
- A builder instance for the provided
JTextArea, which enables fluent method chaining.
-
textArea
Use this to create a builder for a newJTextAreainstance with the provided text property dynamically displaying its value in the text area. The property may also be modified by the user.- Parameters:
text- The text property which should be bound to the text area.- Returns:
- A builder instance for the provided
JTextArea, which enables fluent method chaining.
-
of
-
list
Allows for the creation of a declarative UI for theJListcomponent type.- Type Parameters:
E- The type of the elements in the list.- Returns:
- A builder instance for a new
JList.
-
list
Allows for the creation of a declarative UI for a newJListinstance with a custom list model. -
list
Creates a newJListinstance builder with the provided array as a data model. This is functionally equivalent tolistOf(Object...). -
list
-
listOf
A functionally identical alias method forlist(Vals), which allows for the creation of a newJListinstance with the provided observable property list (aValsobject) as data model. When the property list changes, theJListwill be updated accordingly. -
list
Allows for the creation of a newJListinstance with 2 observable collections as data model, aVarproperty for the selection and aValsproperty list for the elements. When any of the properties change, theJListwill be updated accordingly, and conversely, when theJListselection changes, the properties will be updated accordingly.- Type Parameters:
E- The type of the elements in the list.- Parameters:
selection- TheVarproperty which should be bound to the selection of theJList.elements- TheValsproperty which should be bound to the displayed elements of theJList.- Returns:
- A builder instance for a new
JListwith the provided arguments as data model.
-
list
Allows for the creation of a newJListinstance with 2 observable collections as data model, aValproperty for the selection and aValsproperty list for the elements. When any of the properties change, theJListwill be updated accordingly, however, due to the usage of a read onlyValproperty for the selection, theJListselection will not be updated when the property changes. If you want a bidirectional binding, uselist(Var, Vals)instead.- Type Parameters:
E- The type of the elements in the list.- Parameters:
selection- TheValproperty which should be bound to the selection of theJList.elements- TheValsproperty which should be bound to the displayed elements of theJList.- Returns:
- A builder instance for a new
JListwith the providedValandValsas data models.
-
listOf
Creates a newJListinstance with the provided array as data model. This is functionally equivalent tolist(Object...). -
list
Creates a newJListinstance with the providedUI.ListViewas data model. This is functionally equivalent tolistOf(java.util.List).- Type Parameters:
E- The type parameter defining the concrete type of the list entries.- Parameters:
entries- The list of entries used for populating a newJListcomponent.- Returns:
- A builder instance for a new
JListwith the providedUI.ListViewas data model.
-
listOf
Creates a newJListinstance with the providedUI.ListViewas data model. This is functionally equivalent tolist(java.util.List).- Type Parameters:
E- The type of the elements in the list.- Parameters:
entries- The elements which should be used as model data for the newJList.- Returns:
- A builder instance for a new
JListwith the providedUI.ListViewas data model.
-
of
-
table
Creates a declarative UI builder for theJTablecomponent type.- Returns:
- A fluent builder instance for a new
JTable.
-
table
public static <E> UIForTable<JTable> table(UI.ListData dataFormat, TableListDataSource<E> dataSource) Use this to create a newJTablewith a table model whose data can be represented based on aListofLists of entries.
This method will automatically create aAbstractTableModelinstance for you.Please note that when the data of the provided data source changes (i.e. when the data source is a
Listwhich gets modified), the table model will not be updated automatically! UseUIForTable.updateTableOn(sprouts.Event)to bind an updateEventto the table model.- Type Parameters:
E- The type of the table entryObjects.- Parameters:
dataFormat- An enum which configures the modifiability of the table in a readable fashion.dataSource- TheTableMapDataSourcereturning a column major map based matrix which will be used to populate the table.- Returns:
- This builder node.
-
table
Use this to create a newJTablewith a table model whose data can be represented based on a map of column names to lists of table entries (basically a column major matrix).
This method will automatically create aAbstractTableModelinstance for you.Please note that when the data of the provided data source changes (i.e. when the data source is a
Mapwhich gets modified), the table model will not be updated automatically! UseUIForTable.updateTableOn(sprouts.Event)to bind an updateEventto the table model.- Type Parameters:
E- The type of the table entryObjects.- Parameters:
dataFormat- An enum which configures the modifiability of the table in a readable fashion.dataSource- TheTableMapDataSourcereturning a column major map-based matrix which will be used to populate the table.- Returns:
- This builder node.
-
table
public static UIForTable<JTable> table(Configurator<BasicTableModel.Builder<Object>> tableModelBuildable) Creates a newJTableinstance builder with the provided table model configuration as a basis for creating the table model in a declarative fashion.
It is expected to be used like so:
The purpose of this pattern is to remove the necessity of implementing theUI.table( m -> m .colCount( () -> data[0].size() ) .rowCount( () -> data.size() ) .getsEntryAt((col, row) -> data[col][row] ) )TableModelinterface manually, which is a rather tedious task. Instead, you can use ths fluent API provided by theBasicTableModel.Builderto create a general purpose table model for your table.- Parameters:
tableModelBuildable- A lambda function which takes in a model builder and then returns a fully configured model builder used as a basis for the table model.- Returns:
- This builder instance, to allow for further method chaining.
-
table
public static <T> UIForTable<JTable> table(Class<T> itemType, Configurator<BasicTableModel.Builder<T>> tableModelBuildable) Creates a newJTableinstance builder with the provided table model configuration as a basis for creating the table model in a declarative fashion.
It is expected to be used like so:
This API removes the necessity to implement theUI.table(Double.class, m -> m .colCount( () -> data[0].size() ) .rowCount( () -> data.size() ) .getsEntryAt((col, row) -> data[col][row] ) )TableModelinterface manually, which is a rather tedious task. Instead, you can configure a model step by step through aConfiguratorfunction receiving the fluent builder API provided by theBasicTableModel.Builder.- Type Parameters:
T- The type of the items in the table model.- Parameters:
itemType- The type of the items in the entries of the table model.tableModelBuildable- A lambda function which takes in a model builder and then returns a fully configured model builder used as a basis for the table model.- Returns:
- This builder instance, to allow for further method chaining.
-
of
Allows you to wrap a customJTableHeadertype in a declarative SwingTree UI builder.- Type Parameters:
H- The type of theJTableHeaderfor which the builder should be created.- Parameters:
header- The table header which should be wrapped by the builder.- Returns:
- A builder instance for a new
JTableHeader.
-
tableHeader
Allows you to create a declarative builder for theJTableHeaderUI component.- Returns:
- A builder instance for a new
JTableHeader.
-
of
This returns an instance of a SwingTree builder for aJFrametype.- Type Parameters:
F- The concrete type of this new frame.- Parameters:
frame- The new frame instance which ought to be part of the Swing UI.- Returns:
- A basic UI builder instance wrapping a
JFrame.
-
frame
Use this to create a builder for the suppliedJFrame.
This is in essence a convenience method forUI.of(new JFrame()) ).- Returns:
- A basic UI builder instance wrapping a
JFrame.
-
frame
Use this to create a builder for the suppliedJFramewith the supplied title.- Parameters:
title- The title for the new frame.- Returns:
- A basic UI builder instance wrapping a
JFrame.
-
of
This returns an instance of a SwingTree builder for aJDialogtype.- Type Parameters:
D- The concrete type of this new dialog.- Parameters:
dialog- The new dialog instance which ought to be part of the Swing UI.- Returns:
- A basic UI builder instance wrapping a
JDialog.
-
dialog
Use this to create a builder for the suppliedJDialog.
This is in essence a convenience method forUI.of(new JDialog()) ).- Returns:
- A basic UI builder instance wrapping a
JDialog.
-
dialog
Use this to create a builder for the suppliedJDialogwith the supplied owner.- Parameters:
owner- The owner for the new dialog.- Returns:
- A basic UI builder instance wrapping a
JDialog.
-
dialog
Use this to create a builder for the suppliedJDialogwith the supplied title.- Parameters:
title- The title for the new dialog.- Returns:
- A basic UI builder instance wrapping a
JDialog.
-
dialog
Use this to create a builder for the suppliedJDialogwith the supplied owner and title.- Parameters:
owner- The owner for the new dialog.title- The title for the new dialog.- Returns:
- A basic UI builder instance wrapping a
JDialog.
-
animate
Use this to animate the contents of a property through using anAnimatableinstance holding a transformational function for the intendedAnimationStatusbased changes and aLifeTimedefining the duration of the animation.
Here how this method may be used as part of a UI declaration:
UI.button("Login").onClick( it -> { UI.animate(vm, vm.get().withLoginAnimation()); })- Type Parameters:
T- The type of the property or property lens.- Parameters:
state- A mutable property or property lens holding an immutable item which should be updated repeatedly by theAnimationTransformationinside theAnimatable. The item may also be an immutable view model in case of MVI/MVL design patterns.animatable- A wrapper for the transformationalAnimationTransformationand theLifeTimedefining the duration of the animation.
-
animate
Use this to animate the contents of a property through using anAnimatableinstance holding a transformational function for the intendedAnimationStatusbased changes and aLifeTimedefining the duration of the animation.
Here how this method can be used as part of a UI declaration:
UI.button("Login").onClick( it -> { UI.animate(vm, LoginViewModel::withLoginAnimation); })- Type Parameters:
T- The type of the property or property lens.- Parameters:
state- A mutable property or property lens holding an immutable item which should be updated repeatedly by theAnimationTransformationinside theAnimatable. The item may also be an immutable view model in case of MVI/MVL design patterns.animatable- A function taking in the current property item and returning a wrapper for the transformationalAnimationTransformationand theLifeTimedefining the duration of the animation.
-
animateFor
Exposes an API for scheduling periodic animation updates. This is a convenience method forAnimationDispatcher.animateFor(LifeTime).
A typical usage would be:
Also seeUI.animateFor( 100, TimeUnit.MILLISECONDS ) .until( it -> it.progress() >= 0.75 && someOtherCondition() ) .go( it -> { // do something someComponent.setValue( it.progress() ); // ... someComponent.repaint(); });animate(Var, Animatable)for a more straight forward approach to animating the state of your view models and consequently also the GUI components bound to them.- Parameters:
duration- The duration of the animation. This is the time it takes for the animation to reach 100% progress.unit- The time unit of the duration.- Returns:
- An
AnimationDispatcherinstance which allows you to configure the animation.
-
animateFor
Exposes a builder API for creating and scheduling periodic animation updates. This is a convenience method forAnimationDispatcher.animateFor(LifeTime).
A typical usage would be:
Also seeUI.animateFor( 0.1, TimeUnit.MINUTES ) .until( it -> it.progress() >= 0.75 && someOtherCondition() ) .go( it -> { // do something someComponent.setBackground( new Color( 0, 0, 0, (int)(it.progress()*255) ) ); // ... someComponent.repaint(); });animate(Var, Animatable)for a more straight forward approach to animating the state of your view models and consequently also the GUI components bound to them.- Parameters:
duration- The duration of the animation. This is the time it takes for the animation to reach 100% progress.unit- The time unit of the duration.- Returns:
- An
AnimationDispatcherinstance which allows you to configure the animation.
-
animateFor
Exposes a builder API for creating and scheduling periodic animation updates. This is a convenience method forAnimationDispatcher.animateFor(LifeTime, Stride).
A typical usage would be:
Also seeUI.animateFor( 0.1, TimeUnit.MINUTES, Stride.REGRESSIVE ) .until( it -> it.progress() < 0.75 && someOtherCondition() ) .go( it -> { // do something someComponent.setBackground( new Color( 0, 0, 0, (int)(it.progress()*255) ) ); // ... someComponent.repaint(); });animate(Var, Animatable)for a more straight forward approach to animating the state of your view models and consequently also the GUI components bound to them.- Parameters:
duration- The duration of the animation. This is the time it takes for the animation to reach 100% progress.unit- The time unit of the duration.stride- The stride of the animation, which determines whether the animation progresses going forward or backwards.- Returns:
- An
AnimationDispatcherinstance which allows you to configure the animation.
-
animateFor
Exposes an API for scheduling periodic animation updates. This is a convenience method forAnimationDispatcher.animateFor(LifeTime).
A typical usage would be:
Also seeUI.animateFor( LifeTime.of(0.1, TimeUnit.MINUTES) ) .until( it -> it.progress() >= 0.75 && someOtherCondition() ) .go( it -> { // do something someComponent.setBackground( new Color( 0, 0, 0, (int)(it.progress()*255) ) ); // ... someComponent.repaint(); });animate(Var, Animatable)for a more straight forward approach to animating the state of your view models and consequently also the GUI components bound to them.- Parameters:
duration- The duration of the animation. This is the time it takes for the animation to reach 100% progress.- Returns:
- An
AnimationDispatcherinstance which allows you to configure and run the animation.
-
animateFor
Exposes an API for scheduling periodic animation updates for a specific component whoseComponent.repaint()method should be called after every animation update. This is a convenience method forAnimationDispatcher.animateFor(LifeTime).
A typical usage would be:
Also seeUI.animateFor( UI.lifeTime(0.1, TimeUnit.MINUTES), someComponent ) .until( it -> it.progress() >= 0.75 && someOtherCondition() ) .go( it -> { // do something someComponent.setBackground( new Color( 0, 0, 0, (int)(it.progress()*255) ) ); });animate(Var, Animatable)for a more straight forward approach to animating the state of your view models and consequently also the GUI components bound to them.- Parameters:
duration- The duration of the animation. This is the time it takes for the animation to reach 100% progress.component- The component which should be repainted after every animation update.- Returns:
- An
AnimationDispatcherinstance which allows you to configure and then run the animation.
-
lifeTime
A factory method for creating aLifeTimeinstance with the given duration and time unit. This is a convenience method forLifeTime.of(long, TimeUnit). TheLifeTimeinstance is an immutable value type which is used for scheduling animations, usually throughAnimationDispatcher.animateFor(LifeTime)or the convenience methodsanimateFor(long, TimeUnit),animateFor(double, TimeUnit),animateFor(LifeTime)oranimateFor(LifeTime, java.awt.Component). A typical usage would be:
You may also want to use a lifetime through anUI.animateFor( UI.lifeTime(0.1, TimeUnit.MINUTES) ) .until( it -> it.progress() >= 0.75 && someOtherCondition() ) .go( it -> { // do something });Animatablepassed toanimate(Var, Animatable)for a more straight forward approach to animating the state of your view models and consequently also the GUI components bound to them.- Parameters:
duration- The duration of the animation.unit- The time unit of the duration.- Returns:
- A
LifeTimeinstance.
-
info
Shows an info dialog with the given message.- Parameters:
message- The message to show in the dialog.
-
info
Shows an info dialog with the given message and dialog title.- Parameters:
title- The title of the dialog.message- The message to show in the dialog.
-
warn
Shows a warning dialog with the given message.- Parameters:
message- The warning message to show in the dialog.
-
warn
Shows a warning dialog with the given message and dialog title.- Parameters:
title- The title of the dialog.message- The warning message to show in the dialog.
-
error
Shows an error dialog with the given message.- Parameters:
message- The error message to show in the dialog.
-
error
Shows an error dialog with the given message and dialog title.- Parameters:
title- The title of the dialog.message- The error message to show in the dialog.
-
message
Exposes theMessageDialogAPI, an immutable builder config for creating a message dialog with a given message text. Call methods likeMessageDialog.showAsInfo(),MessageDialog.showAsWarning()orMessageDialog.showAsError()to show the dialog in the desired style.- Parameters:
text- The text to show in the dialog.- Returns:
- A builder for creating an error dialog.
-
confirm
Shows a conformation dialog with the given message and returns the user's answer in the form of aConfirmAnswerenum constant.- Parameters:
message- the message to show- Returns:
Answer.YESif the user clicked "Yes",Answer.NOif the user clicked "No",Answer.CANCELotherwise.
-
confirm
Shows a conformation dialog with the given title and message and returns the user's answer in the form of aConfirmAnswerenum constant.- Parameters:
title- the title of the dialogmessage- the message to show- Returns:
Answer.YESif the user clicked "Yes",Answer.NOif the user clicked "No",Answer.CANCELotherwise.
-
confirmation
Exposes theConfirmDialogAPI, an immutable builder config type for creating a confirmation dialog designed to ask a question. The supplied string will be used as the question to ask the user when the dialog is shown using theConfirmDialog.showAsQuestion()method.- Parameters:
toBeConfirmed- The question to ask the user.- Returns:
- A builder for creating a confirmation dialog designed to ask a question.
-
ask
Shows a dialog where the user can select a value from a list of options based on the enum type implicitly defined by the given enum based property. The selected value will be stored in said property after the user has selected a value and also returned as anOptional. If no value is selected, the returnedOptionalwill be empty and the property will not be changed.- Type Parameters:
E- The enum type.- Parameters:
question- The message to show in the dialog.selected- The enum-based property to store the selected value in.- Returns:
- The selected enum value wrapped in an
Optionalor an empty optional if the user cancelled the dialog.
-
ask
public static <E extends Enum<E>> Optional<E> ask(String title, String message, sprouts.Var<E> selected) Shows a dialog where the user can select a value from a list of options based on the enum type implicitly defined by the given enum based property. The selected value will be stored in said property after the user has selected a value.- Type Parameters:
E- The enum type.- Parameters:
title- The title of the dialog.message- The message to show in the dialog.selected- The enum based property to store the selected value in.- Returns:
- The selected enum value wrapped in an
Optionalor an empty optional if the user cancelled the dialog.
-
ask
public static <E extends Enum<E>> void ask(String title, String message, Icon icon, sprouts.Var<E> selected) Shows a dialog where the user can select a value from a list of options based on the enum type implicitly defined by the given enum based property. The selected value will be stored in said property after the user has selected a value.- Type Parameters:
E- The type parameter defining the concrete enum type.- Parameters:
title- The title of the dialog.message- The message to show in the dialog.icon- The icon to show in the dialog.selected- The enum-based property to store the selected value in.
-
choice
Exposes theOptionsDialogAPI for creating a question dialog that allows the user to select a value from an array of provided enum values.- Type Parameters:
E- The enum type.- Parameters:
offer- The message to show in the dialog.options- The array of enum values to show in the dialog.- Returns:
- A builder for creating a question dialog with a set of selectable enum values based on the provided array of enum values.
-
choice
Exposes theOptionsDialogAPI for creating a question dialog that allows the user to select and set a value from the provided enum based property.- Type Parameters:
E- The enum type.- Parameters:
offer- The message to show in the dialog.selectable- The enum-based property to store the selected value in.- Returns:
- A builder for creating a question dialog with a set of selectable enum values based on the provided array of enum values.
-
show
Use this to quickly launch a UI component in aJFramewindow at the center of the screen.
Warning: This method should only be invoked from the Event Dispatch Thread (EDT). You may encounter unexpected behavior if you call this method from another thread.
Useshow(Function)instead to ensure that the UI is created on the EDT.- Parameters:
component- The component to show in the window.
-
show
Use this to quickly launch a UI component in a titledJFramewindow at the center of the screen.
Warning: This method should only be invoked from the Event Dispatch Thread (EDT). You may encounter unexpected behavior if you call this method from another thread.
Useshow(String, Function)instead to ensure that the UI is created on the EDT.- Parameters:
title- The title of the window.component- The component to show in the window.
-
show
Use this to quickly launch a UI component in aJFramewindow at the center of the screen.
Warning: This method should only be invoked from the Event Dispatch Thread (EDT). You may encounter unexpected behavior if you call this method from another thread.
Useshow(Function)instead to ensure that the UI is created on the EDT.- Type Parameters:
C- The type of the component to show in the window.- Parameters:
ui- The SwingTree UI to show in the window.
-
show
Use this to quickly launch a UI component in a titledJFramewindow at the center of the screen.
Warning: This method should only be invoked from the Event Dispatch Thread (EDT). You may encounter unexpected behavior if you call this method from another thread.
Useshow(String, Function)instead to ensure that the UI is created on the EDT.- Type Parameters:
C- The type of the component to show in the window.- Parameters:
title- The title of the window.ui- The SwingTree UI to show in the window.
-
show
Use this to quickly launch a UI component in aJFramewindow at the center of the screen using a function receiving theJFrameand returning the component to be shown.- Parameters:
uiSupplier- The component supplier which receives the currentJFrameand returns the component to be shown.
-
show
Use this to quickly launch a UI component in a titledJFramewindow at the center of the screen using a function receiving theJFrameand returning the component to be shown.- Parameters:
title- The title of the window.uiSupplier- The component supplier which receives the currentJFrameand returns the component to be shown.
-
showUsing
Use this to quickly launch a UI component with a custom event processor inJFramewindow at the center of the screen.- Parameters:
eventProcessor- the event processor to use for the UI built inside theSupplierlambda.uiSupplier- The component supplier which builds the UI and supplies the component to be shown.
-
showUsing
public static void showUsing(EventProcessor eventProcessor, String title, Function<JFrame, Component> uiSupplier) Use this to quickly launch a UI component with a custom event processor in a titledJFramewindow at the center of the screen.- Parameters:
eventProcessor- the event processor to use for the UI built inside theSupplierlambda.title- The title of the window.uiSupplier- The component supplier which builds the UI and supplies the component to be shown.
-
use
Sets aStyleSheetwhich will be applied to all SwingTree UIs defined in the subsequent lambda scope. This method allows to switch between different style sheets.You can switch to a style sheet like so:
use(new MyCustomStyeSheet(), ()-> UI.panel("fill") .add( "shrink", UI.label( "Username:" ) ) .add( "grow, pushx", UI.textField("User1234..42") ) .add( label( "Password:" ) ) .add( "grow, pushx", UI.passwordField("child-birthday") ) .add( "span", UI.button("Login!").onClick( it -> {...} ) ) );- Type Parameters:
T- The type of the result of the given scope.- Parameters:
styleSheet- The style sheet to be used for all subsequent UI building operations.scope- A lambda scope in which the style sheet is active for all subsequent UI building operations.- Returns:
- the result of the given scope, usually a
JComponentor SwingTree UI.
-
use
Sets theEventProcessorto be used for all subsequent UI building operations. This method allows to switch between different event processing strategies. In particular, theEventProcessor.DECOUPLEDis recommended to be used for proper decoupling of the UI thread from the application logic.You can switch to the decoupled event processor like so:
use(EventProcessor.DECOUPLED, ()-> UI.panel("fill") .add( "shrink", UI.label( "Username:" ) ) .add( "grow, pushx", UI.textField("User1234..42") ) .add( label( "Password:" ) ) .add( "grow, pushx", UI.passwordField("child-birthday") ) .add( "span", UI.button("Login!").onClick( it -> {...} ) ) );- Type Parameters:
T- The type of the value returned by the given scope.- Parameters:
processor- The event processor to be used for all subsequent UI building operationsscope- The scope of the event processor to be used for all subsequent UI building operations. The value returned by the given scope is returned by this method.- Returns:
- The value returned by the given scope.
-
findIcon
Loads anImageIconfrom the resource folder, the classpath, a local file or from cache if it has already been loaded. If no icon could be found, an empty optional is returned.
Note that this method will also returnSvgIconinstances, if the icon is an SVG image.
Also, checkoutSwingTree.getIconCache()to see where the icons are cached.- Parameters:
path- The path to the icon. It can be a classpath resource or a file path.- Returns:
- An optional containing the icon if it could be found, an empty optional otherwise.
- Throws:
NullPointerException- ifpathisnull.
-
findIcon
Loads anImageIconfrom the resource folder, the classpath, a local file or from cache if it has already been loaded. If no icon could be found, an empty optional is returned.
Note that this method will also returnSvgIconinstances, if the icon is an SVG image.
Also, checkoutSwingTree.getIconCache()to see where the icons are cached.- Parameters:
declaration- The icon declaration, a value object defining the path to the icon.- Returns:
- An optional containing the icon if it could be found, an empty optional otherwise.
- Throws:
NullPointerException- ifdeclarationisnull.
-
scaleIconTo
-
findSvgIcon
Loads anSvgIconfrom the resource folder, the classpath, a local file or from cache if it has already been loaded. If no icon could be found, an empty optional is returned.
Also, checkoutSwingTree.getIconCache()to see where the icons are cached.- Parameters:
path- The path to the icon. It can be a classpath resource or a file path.- Returns:
- An optional containing the
SvgIconif it could be found, an empty optional otherwise. - Throws:
NullPointerException- ifpathisnull.
-
findSvgIcon
Loads anSvgIconfrom the resource folder, the classpath, a local file or from cache if it has already been loaded. If no icon could be found, an empty optional is returned.
Also, checkoutSwingTree.getIconCache()to see where the icons are cached.- Parameters:
declaration- The icon declaration, a value object defining the path to the icon.- Returns:
- An optional containing the
SvgIconif it could be found, an empty optional otherwise. - Throws:
NullPointerException- ifdeclarationisnull.
-