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, as it is not intended to be used outside of 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
-
Method Summary
Modifier and TypeMethodDescriptionstatic Animator
animateFor
(double duration, TimeUnit unit) Exposes a builder API for creating and scheduling periodic animation updates.static Animator
animateFor
(double duration, TimeUnit unit, Stride stride) Exposes a builder API for creating and scheduling periodic animation updates.static Animator
animateFor
(long duration, TimeUnit unit) Exposes an API for scheduling periodic animation updates.static Animator
animateFor
(LifeTime duration) Exposes an API for scheduling periodic animation updates.static Animator
animateFor
(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 aJLabel
with bold font.static UIForLabel<JLabel>
Use this to create a UI builder for a boundJLabel
with bold font.box()
Use this to create a builder for aJBox
instance, 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 aMigLayout
as 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 aMigLayout
as 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 aMigLayout
as 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 aMigLayout
as 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 aMigLayout
as 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 aMigLayout
as 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 aMigLayout
as its layout manager.box
(LayoutConstraint attr, String colConstraints, String rowConstraints) static UIForButton<JButton>
button()
Use this to create a builder for theJButton
UI component without any text displayed on top.static UIForButton<JButton>
Use this to create a builder for theJButton
UI 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 theJButton
UI 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 theJButton
UI 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 theJButton
UI 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 theJButton
UI component with the provided text displayed on top.static UIForButton<JButton>
Use this to create a builder for theJButton
UI component with an icon displayed on top.static UIForButton<JButton>
Use this to create a builder for theJButton
UI component with a default icon as well as a hover icon displayed on top.static UIForButton<JButton>
Use this to create a builder for theJButton
UI 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 theJButton
UI component with an icon displayed on top.static UIForButton<JButton>
Create a builder for theJButton
UI 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 theJButton
UI component with an icon displayed on top.static UIForButton<JButton>
button
(IconDeclaration icon, IconDeclaration onHover) Use this to create a builder for theJButton
UI 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 theJButton
UI 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 theJButton
UI component with an icon displayed on top.static UIForButton<JButton>
buttonWithIcon
(sprouts.Val<IconDeclaration> icon) Use this to create a builder for theJButton
UI component with a dynamically displayed icon on top.static UIForCheckBox<JCheckBox>
Creates a builder node wrapping a newJCheckBox
instance with the provided text displayed on it.static UIForCheckBox<JCheckBox>
Creates a builder node wrapping a newJCheckBox
instance 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 newJCheckBox
instance where the provided text property dynamically displays its value on the checkbox.static UIForCheckBox<JCheckBox>
Creates a builder node wrapping a newJCheckBox
instance 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 aJCheckBoxMenuItem
without text displayed on top of the menu button.checkBoxMenuItem
(String text) A factory method to create aJCheckBoxMenuItem
with the provided text displayed on the menu button.checkBoxMenuItem
(String text, Icon icon) A factory method to create aJCheckBoxMenuItem
with 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 aJCheckBoxMenuItem
with 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 aJCheckBoxMenuItem
bound 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 aJCheckBoxMenuItem
bound 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 aJCheckBoxMenuItem
bound 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 theOptionsDialog
API 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 theOptionsDialog
API for creating a question dialog that allows the user to select and set a value from the provided enum based property.static UI.Color
color
(double r, double g, double b) Creates a newColor
object from the specified red, green and blue values.static UI.Color
color
(double r, double g, double b, double a) Creates a newColor
object from the specified red, green, blue and alpha values.static UI.Color
color
(int r, int g, int b) Creates a newColor
object from the specified red, green and blue values.static UI.Color
color
(int r, int g, int b, int a) Creates a newColor
object from the specified red, green, blue and alpha values.static UI.Color
Tries 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 theJComboBox
component type.static <E> UIForCombo<E,
JComboBox<E>> comboBox
(E... items) Use this to declare a UI builder for theJComboBox
component 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 newJComboBox
instance with the provided list of elements as selectable items.static <E> UIForCombo<E,
JComboBox<E>> Use this to declare a builder for a newJComboBox
instance 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 providedComboBoxModel
and a lambda function mapping each model entry to a user-friendly human-readableString
representation.static <E> UIForCombo<E,
JComboBox<E>> comboBox
(sprouts.Vals<E> items) Use this to create a builder for a newJComboBox
instance 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 theJComboBox
component 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 newJComboBox
instance 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 aVar
property 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 aVar
property 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-friendlyString
representation.static <E extends Enum<E>>
UIForCombo<E,JComboBox<E>> Use this to create a builder for a newJComboBox
instance 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 aVar
property 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<E[]> items) Creates a combo box UI builder node with aVar
property as the model for the current selection and an array property of items as a selectable items model of variable length.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.Vals<E> items) Creates a combo box UI builder node with aVar
property 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<E[]> items) Creates a combo box UI builder node with aVar
property as the model for the current selection and an array property of items as a selectable items model of variable length.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 aVar
property 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 newJComboBox
instance with the provided properties list object as selectable (and mutable) items.static <E> UIForCombo<E,
JComboBox<E>> Creates a declarative UI builder for theJComboBox
component 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 theJComboBox
type 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 theJComboBox
type 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) 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 ConfirmAnswer
Shows a conformation dialog with the given message and returns the user's answer in the form of aConfirmAnswer
enum constant.static ConfirmAnswer
Shows a conformation dialog with the given title and message and returns the user's answer in the form of aConfirmAnswer
enum constant.static ConfirmDialog
confirmation
(String toBeConfirmed) Exposes theConfirmDialog
API, 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 suppliedJDialog
with the supplied owner.static UIForJDialog<JDialog>
Use this to create a builder for the suppliedJDialog
with the supplied owner and title.static UIForJDialog<JDialog>
Use this to create a builder for the suppliedJDialog
with the supplied title.static UIForEditorPane<JEditorPane>
Use this to create a builder for a newJEditorPane
UI component.static void
Shows an error dialog with the given message.static void
Shows an error dialog with the given message and dialog title.Loads anImageIcon
from the resource folder, the classpath, a local file or from cache if it has already been loaded.findIcon
(IconDeclaration declaration) Loads anImageIcon
from the resource folder, the classpath, a local file or from cache if it has already been loaded.findSvgIcon
(String path) Loads anSvgIcon
from the resource folder, the classpath, a local file or from cache if it has already been loaded.findSvgIcon
(IconDeclaration declaration) Loads anSvgIcon
from the resource folder, the classpath, a local file or from cache if it has already been loaded.static UI.Font
Returns theFont
that thefontString
argument describes.static UIForFormattedTextField
Use this to create a builder for a newJFormattedTextField
UI component.static UIForFormattedTextField
formattedTextField
(String text) Use this to create a builder for a newJFormattedTextField
instance with the provided text displayed on it.static UIForFormattedTextField
formattedTextField
(sprouts.Val<String> text) Use this to create a builder for a newJFormattedTextField
instance with the provided text property dynamically displaying its value in the text field.static UIForFormattedTextField
formattedTextField
(sprouts.Var<String> text) Use this to create a builder for a newJFormattedTextField
instance 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 suppliedJFrame
with the supplied title.static UIForLabel<JLabel>
Use this to create a builder for aJLabel
displaying HTML.static UIForLabel<JLabel>
Use this to create a builder for aJLabel
displaying HTML.Creates a builder node wrapping a newJIcon
instance 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 newJIcon
instance with the provided icon scaled to the provided width and height.icon
(int width, int height, IconDeclaration icon) Creates a builder node wrapping a newJIcon
instance with the icon found at the path defined by the suppliedIconDeclaration
displayed on it and scaled to the provided width and height.Creates a builder node wrapping a newJIcon
instance with the icon found at the provided path displayed on it.Creates a builder node wrapping a newJIcon
instance with the provided icon displayed on it.icon
(IconDeclaration icon) Creates a builder node wrapping a newJIcon
instance with the icon found at the path provided by the suppliedIconDeclaration
displayed on it.static void
Shows an info dialog with the given message.static void
Shows 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 theJLabel
UI component.static UIForLabel<JLabel>
label
(String text, UI.Alignment alignment) Use this to create a builder for theJLabel
UI component.static UIForLabel<JLabel>
label
(String text, UI.HorizontalAlignment alignment) Use this to create a builder for theJLabel
UI 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 theJLabel
UI component.static UIForLabel<JLabel>
label
(sprouts.Val<String> text, UI.HorizontalAlignment alignment) Use this to create a builder for theJLabel
UI 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 LifeTime
A factory method for creating aLifeTime
instance with the given duration and time unit.list()
Allows for the creation of a declarative UI for theJList
component type.list
(E... elements) Creates a newJList
instance builder with the provided array as data model.Allows for the creation of a declarative UI for a newJList
instance with a custom list model.list
(sprouts.Val<E> selection, sprouts.Vals<E> elements) Allows for the creation of a newJList
instance with 2 observable collections as data model, aVal
property for the selection and aVals
property list for the elements.list
(sprouts.Vals<E> elements) Allows for the creation of a newJList
instance with the provided observable property list (aVals
object) as data model.list
(sprouts.Var<E> selection, sprouts.Vals<E> elements) Allows for the creation of a newJList
instance with 2 observable collections as data model, aVar
property for the selection and aVals
property list for the elements.listOf
(E... elements) Creates a newJList
instance with the provided array as data model.listOf
(sprouts.Vals<E> elements) A functionally identical alias method forlist(Vals)
, which allows for the creation of a newJList
instance with the provided observable property list (aVals
object) as data model.menu()
A convenient factory method for creating a declarative builder object for a plainJMenu
component.A convenient factory method for creating a declarative builder object for aJMenu
component initialized with the provided text.A convenient factory method for creating a declarative builder object for aJMenu
component bound to the supplied text property.static UIForMenuItem<JMenuItem>
menuItem()
A convenient factory method for creating a declarative builder object for a theJMenuItem
component type.
Menu items are usually passed toJMenu
s orJPopupMenu
s like so:static UIForMenuItem<JMenuItem>
This factory method creates aJMenu
with the provided text displayed on the menu button.static UIForMenuItem<JMenuItem>
Use this factory method to create aJMenuItem
with 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 aJMenuItem
with the provided text and default icon based on the providedIconDeclaration
.static UIForMenuItem<JMenuItem>
This factory method creates aJMenuItem
with the provided text property bound to the menu item.static UIForMenuItem<JMenuItem>
A factory method for creating aJMenuItem
with 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 aJMenuItem
with an icon and the supplied text property uni-directionally bound to the menu item.static MessageDialog
Exposes theMessageDialog
API, 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 newJTextField
instance 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 newJTextField
instance 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 newJTextField
instance with the provided number property dynamically displaying its value on the text field and a boolean property which will be set totrue
if the text field contains a valid number, andfalse
otherwise.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 newJTextField
instance with the provided number property dynamically displaying its value on the text field and a boolean property which will be set totrue
if the text field contains a valid number, andfalse
otherwise.static <A extends JTextArea>
UIForTextArea<A>of
(A area) Use this to create a builder for the providedJTextArea
instance.of
(B component) Use this to create a builder for the providedJBox
instance, 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 aJDialog
type.static <F extends JTextField>
UIForTextField<F>of
(F component) Use this to create a builder for the providedJTextField
instance.static <H extends UI.TableHeader>
UIForTableHeader<H>of
(H header) Allows you to wrap a customJTableHeader
type in a declarative SwingTree UI builder.of
(I icon) Use this to create a builder for the providedJIcon
instance.static UIForFormattedTextField
of
(JFormattedTextField component) Use this to create a builder for the providedJFormattedTextField
instance.Use this to create a builder for a concreteJList
component type instance.static <L extends JLabel>
UIForLabel<L>of
(L label) Use this to create a builder for the providedJLabel
instance.of
(M component) Use this to create a builder for the providedJMenu
instance.static <P extends JPanel>
UIForPanel<P>of
(P component) Use this to create a builder for the providedJPanel
type.static <R extends JRadioButton>
UIForRadioButton<R>of
(R component) Use this to create a builder for the providedJRadioButton
instance.static <S extends JSeparator>
UIForSeparator<S>of
(S separator) This returns an instance of aUIForSeparator
builder responsible for building aJSeparator
by exposing helpful utility methods for it.static <M extends JMenuItem>
UIForMenuItem<M>of
(MenuBuilder<M> builder) If you are using builders for customJMenuItem
components, implement this to allow theUI
API 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 theUI
API 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 theJComponent
class.static UIForPanel<JPanel>
panel()
Use this to create a builder for a newJPanel
UI component with aMigLayout
as its layout manager.static UIForPanel<JPanel>
Use this to create a builder for theJPanel
UI component.static UIForPanel<JPanel>
Use this to create a builder for theJPanel
UI component.static UIForPanel<JPanel>
Use this to create a builder for a newJPanel
UI component with aMigLayout
as its layout manager and the provided constraints.static UIForPanel<JPanel>
panel
(net.miginfocom.layout.LC attr) Use this to create a builder for theJPanel
UI component.static UIForPanel<JPanel>
Use this to create a builder for a newJPanel
UI component with aMigLayout
as its layout manager and the provided constraints.static UIForPanel<JPanel>
Use this to create a builder for a newJPanel
UI component with aMigLayout
as its layout manager and the provided constraints.static UIForPanel<JPanel>
panel
(sprouts.Val<LayoutConstraint> attr) Use this to create a builder for theJPanel
UI component with a dynamically updated set ofMigLayout
constraints/attributes.static UIForPanel<JPanel>
panel
(LayoutConstraint attr) Use this to create a builder for theJPanel
UI component.static UIForPanel<JPanel>
panel
(LayoutConstraint attr, String colConstraints) Use this to create a builder for theJPanel
UI component.static UIForPanel<JPanel>
panel
(LayoutConstraint attr, String colConstraints, String rowConstraints) Use this to create a builder for a newJPanel
UI component with aMigLayout
as its layout manager and the provided constraints.static UIForPasswordField<JPasswordField>
Use this to create a builder for a newJPasswordField
UI component.static UIForPasswordField<JPasswordField>
passwordField
(String text) Use this to create a builder for a newJPasswordField
instance with the provided text as the initial password.static UIForPasswordField<JPasswordField>
passwordField
(sprouts.Val<String> text) Use this to create a builder for a newJPasswordField
instance 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 newJPasswordField
instance 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 theJPopupMenu
UI component.static UIForProgressBar<JProgressBar>
A factory method for creating a progress bar builder with a defaultJProgressBar
implementation.static UIForProgressBar<JProgressBar>
progressBar
(int min, int max) Use this to create a builder for a newJProgressBar
instance 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 newJProgressBar
instance 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 newJProgressBar
instance 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 newJProgressBar
instance 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 newJProgressBar
instance 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 newJProgressBar
instance 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 newJProgressBar
instance 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 newJProgressBar
instance 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 newJProgressBar
instance 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 newJRadioButton
instance dynamically bound to an enum basedVar
instance which will be used to dynamically model the selection state of the wrappedJToggleButton
type by checking weather the property matches the provided enum or not.static UIForRadioButton<JRadioButton>
radioButton
(String text) Creates a builder node wrapping a newJRadioButton
instance with the provided text displayed on it.static UIForRadioButton<JRadioButton>
radioButton
(String text, sprouts.Var<Boolean> selected) Creates a builder node wrapping a newJRadioButton
instance 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 theJRadioButton
component 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 newJRadioButton
instance 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 newJRadioButton
instance 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 plainJRadioButtonMenuItem
instance.static <E extends Enum<E>>
UIForRadioButtonMenuItem<JRadioButtonMenuItem>radioButtonMenuItem
(E state, sprouts.Var<E> property) A factory method to create aJRadioButtonMenuItem
bound 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 aJRadioButtonMenuItem
with the provided text displayed on the menu button.radioButtonMenuItem
(String text, Icon icon) A factory method to create aJRadioButtonMenuItem
with 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 aJRadioButtonMenuItem
with 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 aJRadioButtonMenuItem
bound 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 aJRadioButtonMenuItem
bound 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 aJRadioButtonMenuItem
with some custom text and a boolean property, dynamically determining whether the radio button based menu item is selected or not.static UIForScrollPane<JScrollPane>
Use this to create a builder for a newJScrollPane
UI component.static UIForScrollPanels<JScrollPanels>
Use this to create a builder for a newJScrollPanels
UI component.static UIForScrollPanels<JScrollPanels>
scrollPanels
(UI.Align align) Use this to create a builder for a newJScrollPanels
UI component.static UIForScrollPanels<JScrollPanels>
scrollPanels
(UI.Align align, Dimension size) Use this to create a builder for a newJScrollPanels
UI component.static UIForSeparator<JSeparator>
This returns an instance of aUIForSeparator
builder responsible for building aJSeparator
by exposing helpful utility methods for it.static UIForSeparator<JSeparator>
Use this to create a swing tree builder node for theJSeparator
whose alignment is dynamically determined based on a provided property.static UIForSeparator<JSeparator>
This returns an instance of aUIForSeparator
builder responsible for building aJSeparator
by exposing helpful utility methods for it.static void
Use this to quickly launch a UI component in aJFrame
window at the center of the screen.
Warning: This method should only be invoked from the Event Dispatch Thread (EDT).static void
Use this to quickly launch a UI component in a titledJFrame
window at the center of the screen.
Warning: This method should only be invoked from the Event Dispatch Thread (EDT).static void
static <C extends JComponent>
voidshow
(String title, UIForAnySwing<?, C> ui) Use this to quickly launch a UI component in a titledJFrame
window at the center of the screen.static void
static <C extends JComponent>
voidshow
(UIForAnySwing<?, C> ui) Use this to quickly launch a UI component in aJFrame
window at the center of the screen.static void
Use this to quickly launch a UI component with a custom event processor in a titledJFrame
window at the center of the screen.static void
showUsing
(EventProcessor eventProcessor, Function<JFrame, Component> uiSupplier) Use this to quickly launch a UI component with a custom event processor inJFrame
window at the center of the screen.static UIForSlider<JSlider>
Use this to create a builder for a newJSlider
instance 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 newJSlider
instance 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 newJSlider
instance 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 UIForSlider<JSlider>
Creates a slider with the specified alignment and the specified minimum, maximum, and dynamic value.static UIForSlider<JSlider>
Creates a slider with the specified alignment and the specified minimum, maximum, and dynamic value property.static UIForSpinner<JSpinner>
spinner()
Use this to create a builder for a newJSpinner
UI component.static UIForSpinner<JSpinner>
spinner
(int value, int min, int max) Use this to create a builder for the providedJSpinner
instance with the providedmin
,max
and defaultvalue
as the model.static UIForSpinner<JSpinner>
spinner
(int value, int min, int max, int step) Use this to create a builder for the providedJSpinner
instance with the providedmin
,max
, defaultvalue
andstep
as the model.static UIForSpinner<JSpinner>
spinner
(SpinnerModel model) Use this to create a builder for the providedJSpinner
instance with the providedSpinnerModel
as the model.static UIForSpinner<JSpinner>
spinner
(sprouts.Var<?> value) Use this factory method to create aJSpinner
bound to a property of any type.static UIForSplitButton<JSplitButton>
splitButton
(String text) Use this to buildJSplitButton
s with custom text displayed ont top.static <E extends Enum<E>>
UIForSplitButton<JSplitButton>splitButton
(sprouts.Var<E> selection) Use this to buildJSplitButton
s where the selectable options are represented by anEnum
type.static <E extends Enum<E>>
UIForSplitButton<JSplitButton>splitButton
(sprouts.Var<E> selection, sprouts.Event clickEvent) Use this to buildJSplitButton
s where the selectable options are represented by anEnum
type, and the click event is handles by anEvent
instance.Use this to add entries to theJSplitButton
by passingSplitItem
instances toUIForSplitButton
builder like so:Use this to add property bound entries to theJSplitButton
by passingSplitItem
instances toUIForSplitButton
builder like so:static UIForSplitPane<JSplitPane>
Use this to create a builder for a newJSplitPane
instance 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 newJSplitPane
instance 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 theJSplitButton
by passingSplitItem
instances toUIForSplitButton
builder like so:static Tab
static Tab
tab
(JComponent component) static Tab
A factory method producing aTab
instance with the providedtitle
property which can dynamically change the title of the tab button.static Tab
tab
(UIForAnySwing<?, ?> builder) static UIForTabbedPane<JTabbedPane>
Use this to create a builder for a newJTabbedPane
UI component.static UIForTabbedPane<JTabbedPane>
tabbedPane
(sprouts.Val<Integer> selectedIndex) Use this to create a builder for a newJTabbedPane
UI component with the providedselectedIndex
property which should be determined the tab selection of theJTabbedPane
dynamically.static UIForTabbedPane<JTabbedPane>
tabbedPane
(sprouts.Var<Integer> selectedIndex) Use this to create a builder for a newJTabbedPane
UI component with the providedselectedIndex
property which should determine the tab selection of theJTabbedPane
dynamically.static UIForTabbedPane<JTabbedPane>
tabbedPane
(UI.OverflowPolicy tabsPolicy) Use this to create a builder for a newJTabbedPane
UI component with the providedUI.OverflowPolicy
applied to the tab buttons (seeJTabbedPane.setTabLayoutPolicy(int)
).static UIForTabbedPane<JTabbedPane>
tabbedPane
(UI.Side tabsSide) Use this to create a builder for a newJTabbedPane
UI component with the providedUI.Side
applied 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 newJTabbedPane
UI component with the providedUI.OverflowPolicy
andUI.Side
applied to the tab buttons (seeJTabbedPane.setTabLayoutPolicy(int)
andJTabbedPane.setTabPlacement(int)
).static UIForTable<JTable>
table()
Creates a declarative UI builder for theJTable
component type.static <T> UIForTable<JTable>
table
(Class<T> itemType, Configurator<BasicTableModel.Builder<T>> tableModelBuildable) Creates a newJTable
instance 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 newJTable
instance 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) Use this to create a newJTable
with a table model whose data can be represented based on a list of lists of entries.static <E> UIForTable<JTable>
table
(UI.MapData dataFormat, TableMapDataSource<E> dataSource) Use this to create a newJTable
with 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 theJTableHeader
UI component.static UIForTextArea<JTextArea>
Use this to create a builder for a newJTextArea
instance with the provided text as the initial text.static UIForTextArea<JTextArea>
Use this to create a builder for a newJTextArea
instance with the provided text property dynamically displaying its value in the text area.static UIForTextArea<JTextArea>
Use this to create a builder for a newJTextArea
instance with the provided text property dynamically displaying its value in the text area.static UIForTextField<JTextField>
Use this to create a builder for a newJTextField
UI component.static UIForTextField<JTextField>
Use this to create a builder for a newJTextField
instance with the provided text displayed on it.static UIForTextField<JTextField>
Use this to create a builder for a newJTextField
instance with the provided text property dynamically displaying its value on the text field.static UIForTextField<JTextField>
Use this to create a builder for a newJTextField
instance 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 aJTextField
with the specifiedUI.HorizontalAlignment
constant as the text orientation.static UIForTextField<JTextField>
textField
(UI.HorizontalAlignment orientation, String text) A convenience method for creating a builder for aJTextField
with 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.HorizontalAlignment
constant, 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.HorizontalAlignment
constant, 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 newJTextPane
UI component.static UIForToggleButton<JToggleButton>
Use this to create a builder for aJToggleButton
instance.static UIForToggleButton<JToggleButton>
toggleButton
(int width, int height, ImageIcon icon) Use this to create a builder for theJToggleButton
UI 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 theJToggleButton
UI 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 aJToggleButton
displaying the provided icon scaled to fit the desired size andUI.FitComponent
policy.static UIForToggleButton<JToggleButton>
toggleButton
(String text) Use this to create a builder for a newJToggleButton
instance 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 newJToggleButton
instance 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 newJToggleButton
instance with the providedIcon
displayed on it.static UIForToggleButton<JToggleButton>
toggleButton
(Icon icon, sprouts.Var<Boolean> isToggled) Use this to create a builder for a newJToggleButton
instance with the providedIcon
displayed 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) static UIForToggleButton<JToggleButton>
toggleButton
(sprouts.Val<String> text) Use this to create a builder for a newJToggleButton
instance 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 newJToggleButton
instance 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 newJToggleButton
instance 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 newJToggleButton
instance with the icon found at the path provided by the suppliedIconDeclaration
displayed 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 newJToggleButton
instance where the providedIconDeclaration
based 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 newJToggleButton
instance where the providedIconDeclaration
property 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 newJToolBar
instance.static UIForToolBar<JToolBar>
static UIForToolBar<JToolBar>
static <T> T
use
(StyleSheet styleSheet, Supplier<T> scope) Sets aStyleSheet
which will be applied to all SwingTree UIs defined in the subsequent lambda scope.static <T> T
use
(EventProcessor processor, Supplier<T> scope) Sets theEventProcessor
to be used for all subsequent UI building operations.static void
Shows a warning dialog with the given message.static void
Shows a warning dialog with the given message and dialog title.
-
Constructor Details
-
UIFactoryMethods
public UIFactoryMethods()
-
-
Method Details
-
color
Creates a newColor
object 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 newColor
object 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 newColor
object 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 newColor
object 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 theFont
that thefontString
argument describes. To ensure that this method returns the desired Font, format thefontString
parameter 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"
, and pointsize is 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 fontname containing a trailing decimal value should not be used in the fontname only 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
fontString
is not formed with 3 components, e.g. such thatstyle
orpointsize
fields are not present infontString
, andfontname
also contains a character determined to be the separator character then these characters where they appear as intended to be part offontname
may instead be interpreted as separators so the font name may not be properly recognised.The default size is 12 and the default style is PLAIN. If
str
does not specify a valid size, the returnedFont
has a size of 12. IffontString
does not specify a valid style, the returned Font has a style of PLAIN. If you do not specify a valid font name in thefontString
argument, 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. IffontString
isnull
, a newFont
is returned with the family name "Dialog", a size of 12 and a PLAIN style.- Parameters:
fontString
- the name of the font, ornull
- Returns:
- the
Font
object thatfontString
describes. - Throws:
NullPointerException
- iffontString
isnull
-
of
This returns an instance of a generic swing tree builder for anything extending theJComponent
class.- 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 providedJPanel
type.
This method is typically used to enable declarative UI design for customJPanel
based 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 customJPanel
type 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 concreteJPanel
type to be wrapped.- Parameters:
component
- TheJPanel
instance 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
- ifcomponent
isnull
.
-
panel
Use this to create a builder for a newJPanel
UI component with aMigLayout
as 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 theJPanel
UI 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 theMigLayout
constructor as first argument.- Returns:
- A builder instance for a new
JPanel
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifattr
isnull
.- See Also:
-
panel
Use this to create a builder for theJPanel
UI 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 theMigLayout
constructor as first argument.colConstraints
- The layout which will be passed to theMigLayout
constructor 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 newJPanel
UI component with aMigLayout
as 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 theJPanel
UI component. This is in essence a convenience method forUI.of(new JPanel()).withLayout(attr)
.- Parameters:
attr
- The layout attributes which will be passed to theMigLayout
constructor as first argument.- Returns:
- A builder instance for a new
JPanel
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifattr
isnull
.- See Also:
-
panel
Use this to create a builder for theJPanel
UI 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 theMigLayout
constructor as first argument.colConstraints
- The layout which will be passed to theMigLayout
constructor 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 newJPanel
UI component with aMigLayout
as 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 aLayoutConstraint
constants.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 theJPanel
UI 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 entireMigLayout
in the form of aLC
instance.- Returns:
- A builder instance for a new
JPanel
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifattr
isnull
.- See Also:
-
panel
Use this to create a builder for a newJPanel
UI component with aMigLayout
as 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 newJPanel
UI component with aMigLayout
as 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 aLC
instance.colConstraints
- The column constraints in the form of aString
instance.rowConstraints
- The row constraints in the form of aString
instance.- Returns:
- A builder instance for a new
JPanel
, which enables fluent method chaining. - See Also:
-
panel
Use this to create a builder for theJPanel
UI component with a dynamically updated set ofMigLayout
constraints/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 theMigLayout
constructor as first argument.- Returns:
- A builder instance for a new
JPanel
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifattr
isnull
.- See Also:
-
of
Use this to create a builder for the providedJBox
instance, 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.
JBox
type 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
JBox
based 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 customJBox
type is added to the components tree, like so:
UI.show( UI.panel() .add( new MyCustomBox() ) .add(..more stuff..) );
- Type Parameters:
B
- THe type parameter defining the concreteJBox
type.- Parameters:
component
- The box component type for which a builder should be created.- Returns:
- A builder for the provided box component.
- Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
box
Use this to create a builder for aJBox
instance, 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.
JBox
type 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 theJBox
type with aJPanel
usingUI.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 aMigLayout
as its layout manager. This is conceptually the same as a transparentJPanel
without any insets and aMigLayout
constructed using the provided constraints.- Parameters:
attr
- The layout attributes which will be passed to theMigLayout
constructor as first argument.- Returns:
- A builder instance for a new
JBox
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifattr
isnull
.- See Also:
-
box
Use this to create a builder for aJBox
, conceptually the same as a transparentJPanel
without any insets and aMigLayout
constructed using the provided constraints.
Please note that theJBox
type 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 theMigLayout
constructor as first argument.colConstraints
- The layout which will be passed to theMigLayout
constructor 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 aMigLayout
as 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 theJBox
type with aJPanel
usingUI.panel(attr, colConstraints, rowConstraints).makeNonOpaque()
Please note that theJBox
type 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 aMigLayout
as its layout manager. This is conceptually the same as a transparentJPanel
without any insets and aMigLayout
constructed using the provided constraints.
Please note that theJBox
type 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 allows you to pass aLayoutConstraint
constants as the layout attributes, which is an instance typically chosen from theUI
class 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(..)
JBox
with aMigLayout
as 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 theMigLayout
constructor as first argument.- Returns:
- A builder instance for a transparent
JBox
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifattr
isnull
.- 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 aMigLayout
as its layout manager. This is conceptually the same as a transparentJPanel
without any insets and aMigLayout
constructed using the provided constraints.
Please note that theJBox
type 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 allows you to pass a
LayoutConstraint
constants as the layout attributes, which is an instance typically chosen from theUI
class 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, "[shrink]6[grow]") .add(..) .add(..)
JBox
with aMigLayout
as 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 theMigLayout
constructor as first argument.colConstraints
- The layout which will be passed to theMigLayout
constructor 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 transparentJPanel
without any insets and aMigLayout
constructed 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 theJBox
type 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 aLayoutConstraint
constants.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 aMigLayout
as its layout manager.
Please note that theJBox
type 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 theMigLayout
constructor as first argument.- Returns:
- A builder instance for a transparent
JBox
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifattr
isnull
.- 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 aMigLayout
as its layout manager. This is conceptually the same as a transparentJPanel
without any insets and aMigLayout
constructed using the provided constraints. This is essentially a convenience method which may also be expressed as:
UI.of(new JBox(new MigLayout(attr, colConstraints)))
Please note that theJBox
type 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 aLayoutConstraint
constants.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 transparentJPanel
without any insets and aMigLayout
constructed 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 theJBox
type 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 aLayoutConstraint
constants.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 aMigLayout
as its layout manager. This is conceptually the same as a transparentJPanel
without any insets and aMigLayout
constructed using the provided constraints. This method allows you to dynamically determine theLayoutConstraint
constants of theMigLayout
instance, by passing aVal
property which will be observed and its value passed to theMigLayout
constructor 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 theMigLayout
constructor as first argument.- Returns:
- A builder instance for a new
JBox
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifattr
isnull
.- See Also:
-
of
If you are using builders for your customJComponent
, implement this to allow theUI
API 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 customJComponent
types.- Returns:
- A basic UI builder instance wrapping any
JComponent
.
-
of
If you are using builders for customJMenuItem
components, implement this to allow theUI
API to call theSwingBuilder.build()
method for you. -
of
Use this to create a swing tree builder node for theJPopupMenu
UI component.- Type Parameters:
P
- The concrete type of this new component.- Parameters:
popup
- The newJPopupMenu
instance 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 theJPopupMenu
UI 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 aUIForSeparator
builder responsible for building aJSeparator
by exposing helpful utility methods for it.- Type Parameters:
S
- The concrete type of this new component.- Parameters:
separator
- The newJSeparator
instance which ought to be part of the Swing UI.- Returns:
- A
UIForSeparator
UI builder instance which wraps theJSeparator
and exposes helpful methods.
-
separator
This returns an instance of aUIForSeparator
builder responsible for building aJSeparator
by exposing helpful utility methods for it. This is in essence a convenience method forUI.of(new JSeparator())
.- Returns:
- A
UIForSeparator
UI builder instance which wraps theJSeparator
and exposes helpful methods.
-
separator
This returns an instance of aUIForSeparator
builder responsible for building aJSeparator
by 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
UIForSeparator
UI builder instance which wraps theJSeparator
and exposes helpful methods.
-
separator
Use this to create a swing tree builder node for theJSeparator
whose 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
UIForSeparator
UI builder instance which wraps theJSeparator
and exposes helpful methods.
-
of
This returns aJButton
swing 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
JButton
builder instance.
-
button
Use this to create a builder for theJButton
UI 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 theJButton
UI 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 theJButton
UI 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 theJButton
UI 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 theJButton
UI 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 theJButton
UI component with an icon displayed on top. The icon is determined based on the providedIconDeclaration
instance 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 theJButton
UI component with an icon displayed on top. The icon is determined based on the providedIconDeclaration
instance 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 theJButton
UI 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 theJButton
UI component with an icon displayed on top which should be scaled to the provided dimensions. The icon is determined based on the providedIconDeclaration
instance 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 theJButton
UI component with a dynamically displayed icon on top.Note that you may not use the
Icon
orImageIcon
classes directly, instead you must use implementations of theIconDeclaration
interface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclaration
interface, 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 case of unit tests for you view model, where the icon may not be available at all, but you still want to test the behaviour 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 theJButton
UI 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 theJButton
UI component with a default icon as well as a hover icon displayed on top. The icons are determined based on the providedIconDeclaration
instances 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.- Returns:
- A builder instance for a
JButton
, which enables fluent method chaining.
-
button
Use this to create a builder for theJButton
UI 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 theJButton
UI 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 providedIconDeclaration
instances which is conceptually merely a resource paths 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 theJButton
UI 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 theJButton
UI component with a default, an on-hover and an on-press icon displayed on top. The icons are determined based on the providedIconDeclaration
instances 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 theJSplitButton
UI 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 buildJSplitButton
s with custom text displayed ont top. TheJSplitButton
wrapped by the returned builder can be populated withJMenuItem
s 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 buildJSplitButton
s where the selectable options are represented by anEnum
type, and the click event is handles by anEvent
instance.
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 (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 theEnum
representing the selectable options.- Parameters:
selection
- TheVar
which holds the currently selectedEnum
value. This will be updated when the user selects a new value.clickEvent
- TheEvent
which 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) Use this to buildJSplitButton
s where the selectable options are represented by anEnum
type.
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 (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 theEnum
representing the selectable options.- Parameters:
selection
- TheVar
which holds the currently selectedEnum
value. This will be updated when the user selects a new value.- Returns:
- A UI builder instance wrapping a
JSplitButton
.
-
splitItem
Use this to add entries to theJSplitButton
by passingSplitItem
instances toUIForSplitButton
builder like so:
You can also use theUI.splitButton("Button") .add(UI.splitItem("first")) .add(UI.splitItem("second")) .add(UI.splitItem("third"))
SplitItem
wrapper class to wrap useful action lambdas for the split item.- Parameters:
text
- The text displayed on theJMenuItem
exposed by theJSplitButton
sJPopupMenu
.- Returns:
- A new
SplitItem
wrapping a simpleJMenuItem
.
-
splitItem
Use this to add property bound entries to theJSplitButton
by passingSplitItem
instances toUIForSplitButton
builder like so:
You can also use theUI.splitButton("Button") .add(UI.splitItem(viewModel.getFirstButtonName())) .add(UI.splitItem(viewModel.getSecondButtonName())) .add(UI.splitItem(viewModel.getThirdButtonName()))
SplitItem
wrapper class to wrap useful action lambdas for the split item.- Parameters:
text
- The text property to dynamically display text on theJMenuItem
exposed by theJSplitButton
sJPopupMenu
.- Returns:
- A new
SplitItem
wrapping a simpleJMenuItem
.
-
splitRadioItem
Use this to add radio item entries to theJSplitButton
by passingSplitItem
instances toUIForSplitButton
builder like so:
You can also use theUI.splitButton("Button") .add(UI.splitRadioItem("first")) .add(UI.splitRadioItem("second")) .add(UI.splitRadioItem("third"))
SplitItem
wrapper class to wrap useful action lambdas for the split item.- Parameters:
text
- The text displayed on theJRadioButtonMenuItem
exposed by theJSplitButton
sJPopupMenu
.- Returns:
- A new
SplitItem
wrapping a simpleJRadioButtonMenuItem
.
-
of
Creates a UI builder for a customJTabbedPane
type.- Type Parameters:
P
- The pane type parameter.- Parameters:
pane
- TheJTabbedPane
type which should be used wrapped.- Returns:
- This instance, to allow for method chaining.
-
tabbedPane
Use this to create a builder for a newJTabbedPane
UI component. This is in essence a convenience method forUI.of(new JTabbedPane())
. In order 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 newJTabbedPane
UI component with the providedUI.Side
applied 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(Position.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
- iftabsPosition
isnull
.
-
tabbedPane
public static UIForTabbedPane<JTabbedPane> tabbedPane(UI.Side tabsSide, UI.OverflowPolicy tabsPolicy) Use this to create a builder for a newJTabbedPane
UI component with the providedUI.OverflowPolicy
andUI.Side
applied to the tab buttons (seeJTabbedPane.setTabLayoutPolicy(int)
andJTabbedPane.setTabPlacement(int)
). In order to add tabs to this builder use the tab object returned bytab(String)
like so:UI.tabbedPane(Position.LEFT, 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.SCROLL
orUILayoutConstants.WRAP(int)
.- Returns:
- A builder instance wrapping a new
JTabbedPane
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- iftabsPosition
ortabsPolicy
arenull
.
-
tabbedPane
Use this to create a builder for a newJTabbedPane
UI component with the providedUI.OverflowPolicy
applied 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(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.SCROLL
orUILayoutConstants.WRAP(int)
.- Returns:
- A builder instance wrapping a new
JTabbedPane
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- iftabsPolicy
isnull
.
-
tabbedPane
Use this to create a builder for a newJTabbedPane
UI component with the providedselectedIndex
property which should be determined the tab selection of theJTabbedPane
dynamically. 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 aVal
property 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
- ifselectedIndex
isnull
.
-
tabbedPane
Use this to create a builder for a newJTabbedPane
UI component with the providedselectedIndex
property which should determine the tab selection of theJTabbedPane
dynamically. 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
- ifselectedIndex
isnull
.
-
tab
Use this to add tabs to aJTabbedPane
by passingTab
instances toUIForTabbedPane
builder 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
Tab
instance containing everything needed to be added to aJTabbedPane
. - Throws:
IllegalArgumentException
- iftitle
isnull
.
-
tab
A factory method producing aTab
instance with the providedtitle
property which can dynamically change the title of the tab button. Use this to add tabs to aJTabbedPane
by passingTab
instances toUIForTabbedPane
builder 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
Tab
instance containing everything needed to be added to aJTabbedPane
. - Throws:
IllegalArgumentException
- iftitle
isnull
.
-
tab
Use this to add tabs to aJTabbedPane
by passingTab
instances toUIForTabbedPane
builder 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
Tab
instance containing everything needed to be added to aJTabbedPane
. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
tab
Use this to add tabs to aJTabbedPane
by passingTab
instances toUIForTabbedPane
builder 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
Tab
instance containing everything needed to be added to aJTabbedPane
. - Throws:
IllegalArgumentException
- ifbuilder
isnull
.
-
of
Use this to create a builder for the providedJMenu
instance.- Type Parameters:
M
- The concrete type of the menu.- Parameters:
component
- TheJMenu
component 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
- ifcomponent
isnull
.
-
of
Use this to create a builder for the providedJMenuItem
instance.- Type Parameters:
M
- The type parameter of the concrete menu item component.- Parameters:
component
- TheJMenuItem
component 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
- ifcomponent
isnull
.
-
of
A factory method to wrap the providedJRadioButtonMenuItem
instance in a SwingTree UI builder.- Type Parameters:
M
- The type of theJRadioButtonMenuItem
instance to be wrapped.- Parameters:
radioMenuItem
- TheJRadioButtonMenuItem
instance to be wrapped.- Returns:
- A builder instance for the provided
JRadioButtonMenuItem
, which enables fluent method chaining.
-
radioButtonMenuItem
A factory method to create a plainJRadioButtonMenuItem
instance.
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 aJRadioButtonMenuItem
with 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 aJRadioButtonMenuItem
bound 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 wrappedJRadioButtonMenuItem
dynamically.- 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 aJRadioButtonMenuItem
with 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 aJRadioButtonMenuItem
bound 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 wrappedJRadioButtonMenuItem
dynamically.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 aJRadioButtonMenuItem
bound 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 aVar
property 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
- ifstate
orproperty
arenull
.
-
radioButtonMenuItem
public static UIForRadioButtonMenuItem<JRadioButtonMenuItem> radioButtonMenuItem(String text, sprouts.Var<Boolean> isSelected) A factory method to create aJRadioButtonMenuItem
with 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 aJRadioButtonMenuItem
with 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 -> {..} ))
String
andboolean
properties 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 providedJCheckBoxMenuItem
instance in a SwingTree UI builder.- Type Parameters:
M
- The type of theJCheckBoxMenuItem
instance to be wrapped.- Parameters:
checkBoxMenuItem
- TheJCheckBoxMenuItem
instance to be wrapped.- Returns:
- A builder instance for the provided
JCheckBoxMenuItem
, which enables fluent method chaining.
-
checkBoxMenuItem
A factory method to create aJCheckBoxMenuItem
without 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 aJCheckBoxMenuItem
with 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 aJCheckBoxMenuItem
bound 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 wrappedJCheckBoxMenuItem
dynamically.- Returns:
- A builder instance for the provided
JCheckBoxMenuItem
, which enables fluent method chaining.
-
checkBoxMenuItem
A factory method to create aJCheckBoxMenuItem
with 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 aJCheckBoxMenuItem
with 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 determines 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 aJCheckBoxMenuItem
bound 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 wrappedJCheckBoxMenuItem
dynamically.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 aJCheckBoxMenuItem
bound 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 wrappedJCheckBoxMenuItem
dynamically.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 providedJToolBar
instance. Using method chaining you can populate theJToolBar
by 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 theJToolBar
instance to be wrapped.- Parameters:
component
- TheJToolBar
instance to be wrapped.- Returns:
- A builder instance for the provided
JToolBar
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
toolBar
Use this to create a builder for a newJToolBar
instance. Use method chaining to add buttons or other components to aJToolBar
by passing them toUIForToolBar
builder 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
- ifcomponent
isnull
.
-
toolBar
A factory method for creating aJToolBar
instance where the providedUI.Align
enum defines the orientation of theJToolBar
.- Parameters:
align
- TheUI.Align
enum which defines the orientation of theJToolBar
.- Returns:
- A builder instance for the provided
JToolBar
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifalign
isnull
.
-
toolBar
A factory method for creating aJToolBar
instance where the providedVal
property dynamically defines the orientation of theJToolBar
- Parameters:
align
- TheVal
property which dynamically defines the orientation of theJToolBar
.- Returns:
- A builder instance for the provided
JToolBar
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifalign
isnull
.
-
of
Use this to create a builder for the providedJScrollPane
component.- Type Parameters:
P
- The type parameter defining the concrete scroll pane type.- Parameters:
component
- TheJScrollPane
component which should be represented by the returned builder.- Returns:
- A
UIForScrollPane
builder representing the provided component. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
scrollPane
Use this to create a builder for a newJScrollPane
UI 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.
-
of
Use this to create a builder for the providedJScrollPanels
component.- Type Parameters:
P
- The type parameter defining the concrete scroll panels type.- Parameters:
component
- TheJScrollPanels
component which should be represented by the returned builder.- Returns:
- A
UIForScrollPanels
builder representing the provided component. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
scrollPanels
Use this to create a builder for a newJScrollPanels
UI 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 newJScrollPanels
UI 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(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 newJScrollPanels
UI 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(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 providedJSplitPane
instance.- Type Parameters:
P
- The type of theJSplitPane
instance.- Parameters:
component
- TheJSplitPane
instance to create a builder for.- Returns:
- A builder instance for the provided
JSplitPane
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
splitPane
Use this to create a builder for a newJSplitPane
instance 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 theJSplitPane
split bar is aligned vertically or horizontally.- Returns:
- A builder instance for the provided
JSplitPane
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifalign
isnull
.
-
splitPane
Use this to create a builder for a newJSplitPane
instance 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, anIllegalArgumentException
will be thrown.- Parameters:
align
- The alignment determining if theJSplitPane
split bar is aligned vertically or horizontally.- Returns:
- A builder instance for the provided
JSplitPane
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifalign
isnull
.
-
of
Use this to create a builder for the providedJEditorPane
instance.- Type Parameters:
P
- The type of theJEditorPane
instance.- Parameters:
component
- TheJEditorPane
instance to create a builder for.- Returns:
- A builder instance for the provided
JEditorPane
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
editorPane
Use this to create a builder for a newJEditorPane
UI 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 providedJTextPane
instance.- Type Parameters:
P
- The type of theJTextPane
instance.- Parameters:
component
- TheJTextPane
instance to create a builder for.- Returns:
- A builder instance for the provided
JTextPane
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
textPane
Use this to create a builder for a newJTextPane
UI 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 providedJSlider
instance.- Type Parameters:
S
- The type of theJSlider
instance.- Parameters:
component
- TheJSlider
instance to create a builder for.- Returns:
- A builder instance for the provided
JSlider
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
slider
Use this to create a builder for a newJSlider
instance based on tbe provided alignment type determining if the slider will be aligned vertically or horizontally.- Parameters:
align
- The alignment determining if theJSlider
aligns vertically or horizontally.- Returns:
- A builder instance for the provided
JSlider
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifalign
isnull
.- See Also:
-
slider
Use this to create a builder for a newJSlider
instance based on the provided alignment property which dynamically determines if the property is aligned vertically or horizontally.- Parameters:
align
- The alignment property determining if theJSlider
aligns vertically or horizontally.- Returns:
- A builder instance for the provided
JSlider
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- if thealign
property isnull
.- See Also:
-
slider
Use this to create a builder for a newJSlider
instance based on tbe provided alignment type, min slider value and max slider value.- Parameters:
align
- The alignment determining if theJSlider
aligns 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
- ifalign
isnull
.- See Also:
-
slider
Creates a slider with the specified alignment and the specified minimum, maximum, and initial values.- Parameters:
align
- The alignment determining if theJSlider
aligns 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
- ifalign
isnull
.- See Also:
-
slider
public static UIForSlider<JSlider> slider(UI.Align align, int min, int max, sprouts.Val<Integer> 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 onlyVal
type, which means that when the user moves the slider, the property will not be updated.
If you want bidirectional binding, useslider(UI.Align, int, int, Var)
instead of this method.- Parameters:
align
- The alignment determining if theJSlider
aligns 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
- ifalign
isnull
.- See Also:
-
slider
public static UIForSlider<JSlider> slider(UI.Align align, int min, int max, sprouts.Var<Integer> 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)
).- Parameters:
align
- The alignment determining if theJSlider
aligns 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
- ifalign
isnull
.- See Also:
-
of
Use this to create a builder for the providedJComboBox
instance.
This is useful when you want to write declarative UI with a customJComboBox
type. Also seecomboBox()
for a more convenient way to create a newJComboBox
instance. -
comboBox
Use this to create a UI builder for a theJComboBox
component type. This is similar toUI.of(new JComboBox())
. -
comboBox
Use this to declare a UI builder for theJComboBox
component 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
- ifcomponent
isnull
.
-
comboBox
Use this create a UI declaration for theJComboBox
component type with the provided array of elements as selectable items and a lambda function converting each item into a user-friendlyString
representation.
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-friendlyString
representation.- Returns:
- A builder instance for the new
JComboBox
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
comboBoxWithUnmodifiable
Use this to declare a UI builder for theJComboBox
type 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
- ifcomponent
isnull
.
-
comboBoxWithUnmodifiable
public static <E> UIForCombo<E,JComboBox<E>> comboBoxWithUnmodifiable(E[] items, Function<E, String> renderer) Use this to declare a UI builder for theJComboBox
type with the provided array of elements as selectable items which may not be modified by the user. Use this create a UI declaration for theJComboBox
component type with the provided array of elements as selectable but unmodifiable items and a lambda function converting each item into a user-friendlyString
representation.- 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.- Returns:
- A builder instance for the new
JComboBox
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
comboBox
Use this to create a builder for a newJComboBox
instance 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 theJComboBox
and theJComboBox
will 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 newJComboBox
instance 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 theJComboBox
and theJComboBox
will 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 friendlyString
representation.- Returns:
- A builder instance for the new
JComboBox
, which enables fluent method chaining.
-
comboBox
Use this to declare a builder for a newJComboBox
instance 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
- ifcomponent
isnull
.
-
comboBox
Use this to declare a builder for a newJComboBox
instance 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
JComboBox
type, to allow for fluent method chaining.
-
comboBoxWithUnmodifiable
Use this to create a builder for a newJComboBox
instance with the providedUI.List
of 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
JComboBox
type, to allow for fluent method chaining.
-
comboBox
Creates a combo box UI builder node with aVar
property 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
JComboBox
type, to allow for fluent method chaining.
-
comboBox
Use this to create a builder for a newJComboBox
instance with the provided properties list object as selectable (and mutable) items.- Type Parameters:
E
- The type of the elements in the list.- Parameters:
items
- TheVars
properties of elements to be selectable in theJComboBox
.- Returns:
- A declarative builder for the provided
JComboBox
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Vars<E> items, Function<E, String> renderer) Creates a declarative UI builder for theJComboBox
component 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
JComboBox
type, to allow for fluent method chaining.
-
comboBox
Use this to create a builder for a newJComboBox
instance 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 theJComboBox
component 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 -> ... )
Vals
property 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
JComboBox
type, 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 aVar
property 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
JComboBox
type, 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 aVar
property 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"; })
Vals
property 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
JComboBox
type, to allow for fluent method chaining.
-
comboBox
Creates a combo box UI builder node with aVar
property 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 aVar
property 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-friendlyString
representation.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
Creates a combo box UI builder node with aVar
property as the model for the current selection and an array property of items as a selectable items model of variable length.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 property holding an array 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<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
JComboBox
type, to allow for fluent method chaining.
-
comboBox
public static <E> UIForCombo<E,JComboBox<E>> comboBox(sprouts.Var<E> selectedItem, sprouts.Val<E[]> items) Creates a combo box UI builder node with aVar
property as the model for the current selection and an array property of items as a selectable items model of variable length.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:
selectedItem
- The property holding the current selection.items
- The property holding an array 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<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
JComboBox
type, 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 providedComboBoxModel
and a lambda function mapping each model entry to a user-friendly human-readableString
representation.- 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 providedJSpinner
instance.- Type Parameters:
S
- The type parameter of the concreteJSpinner
subclass to be used by the builder.- Parameters:
spinner
- TheJSpinner
instance to create a builder for. The providedJSpinner
instance must not benull
.- Returns:
- A builder instance for the provided
JSpinner
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifspinner
isnull
.
-
spinner
Use this to create a builder for a newJSpinner
UI 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 providedJSpinner
instance with the providedSpinnerModel
as the model.- Parameters:
model
- TheSpinnerModel
to be used by theJSpinner
.- Returns:
- A builder instance for the provided
JSpinner
, which enables fluent method chaining.
-
spinner
Use this factory method to create aJSpinner
bound 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 providedJSpinner
instance with the providedmin
,max
, defaultvalue
andstep
as the model. -
spinner
Use this to create a builder for the providedJSpinner
instance with the providedmin
,max
and defaultvalue
as the model. -
of
Use this to create a builder for the providedJLabel
instance. -
label
Use this to create a builder for theJLabel
UI 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 theJLabel
UI 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 theJLabel
UI 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 theJLabel
UI 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 theJLabel
UI 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 aIconDeclaration
which 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
Icon
orImageIcon
classes directly, instead you must use implementations of theIconDeclaration
interface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclaration
interface, 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 case of unit tests for you view model, where the icon may not be available at all, but you still want to test the behaviour 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 aIconDeclaration
which 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 aJLabel
with 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 boundJLabel
with 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 aJLabel
displaying 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 aJLabel
displaying 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 providedJIcon
instance. -
icon
Creates a builder node wrapping a newJIcon
instance 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 newJIcon
instance with the icon found at the path provided by the suppliedIconDeclaration
displayed on it. Note that the icon will be cached by theJIcon
instance, 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 builder node wrapping a newJIcon
instance 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 aJIcon
for 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 newJIcon
instance with the icon found at the path defined by the suppliedIconDeclaration
displayed on it and scaled to the provided width and height. Note that the icon will be cached by theJIcon
instance, 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 aJIcon
for 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 newJIcon
instance 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 theJIcon
instance, 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 builder node wrapping a newJIcon
instance with the icon found at the provided path displayed on it. Note that the icon will be cached by theJIcon
instance, 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 newJCheckBox
instance 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 newJCheckBox
instance 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 newJCheckBox
instance 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 newJCheckBox
instance 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 providedJCheckBox
instance.- Type Parameters:
B
- The type parameter of the concreteJCheckBox
subclass to be used by the builder.- Parameters:
component
- TheJCheckBox
instance 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 newJRadioButton
instance 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 newJRadioButton
instance 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 newJRadioButton
instance 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 newJRadioButton
instance 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 newJRadioButton
instance dynamically bound to an enum basedVar
instance which will be used to dynamically model the selection state of the wrappedJToggleButton
type 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 thisJToggleButton
should represent.- Parameters:
state
- The referenceEnum
which thisJToggleButton
should represent.selection
- TheVar
instance which will be used to dynamically model the selection state of the wrappedJToggleButton
type.- Returns:
- A builder instance for the radio button, which enables fluent method chaining.
- Throws:
IllegalArgumentException
- ifselected
isnull
.
-
radioButton
public static <T> UIForRadioButton<JRadioButton> radioButton(String label, T state, sprouts.Var<T> selection) Creates a declarative UI builder for theJRadioButton
component 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 providedJRadioButton
instance.- Type Parameters:
R
- The type of theJRadioButton
instance which should be wrapped by the builder.- Parameters:
component
- TheJRadioButton
instance 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 aJToggleButton
instance.- Returns:
- A builder instance for a new
JToggleButton
, which enables fluent method chaining.
-
toggleButton
Use this to create a builder for a newJToggleButton
instance 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 newJToggleButton
instance 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 newJToggleButton
instance 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 newJToggleButton
instance 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 newJToggleButton
instance 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 newJToggleButton
instance with the providedIcon
displayed 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
-
toggleButton
Use this to create a builder for theJToggleButton
UI component with an icon displayed on it scaled according to the provided width and height.- 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
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 theJToggleButton
UI component with an icon displayed on it scaled according to the provided width and height.- Parameters:
width
- The width the icon should be scaled to.height
- The height the icon should be scaled to.icon
- TheIconDeclaration
whose 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 aJToggleButton
displaying the provided icon scaled to fit the desired size andUI.FitComponent
policy.- Parameters:
width
- The width the icon should be scaled to.height
- The height the icon should be scaled to.icon
- TheIconDeclaration
whose icon ought to be displayed on top of the button.fit
- TheUI.FitComponent
which 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 newJToggleButton
instance with the icon found at the path provided by the suppliedIconDeclaration
displayed on top of it. Note that the icon will be cached by theJToggleButton
instance, 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 newJToggleButton
instance with the providedIcon
displayed 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 newJToggleButton
instance where the providedIconDeclaration
based property dynamically displays the targeted image on the toggle button.Note that you may not use the
Icon
orImageIcon
classes directly, instead you must use implementations of theIconDeclaration
interface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclaration
interface, 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 case of unit tests for you view model, where the icon may not be available at all, but you still want to test the behaviour 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 newJToggleButton
instance where the providedIconDeclaration
property 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
Icon
orImageIcon
classes directly, instead you must use implementations of theIconDeclaration
interface, which merely models the resource location of the icon, but does not load the whole icon itself.The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should use the
IconDeclaration
interface, 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 case of unit tests for you view model, where the icon may not be available at all, but you still want to test the behaviour 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 providedJToggleButton
instance.- Type Parameters:
B
- The type of theJToggleButton
instance which should be wrapped by the builder.- Parameters:
component
- TheJToggleButton
instance 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 providedJTextField
instance.- Type Parameters:
F
- The type of theJTextField
instance which should be wrapped by the builder.- Parameters:
component
- TheJTextField
instance 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 newJTextField
instance 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 newJTextField
instance 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 newJTextField
instance 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 newJTextField
UI 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 aJTextField
with the specifiedUI.HorizontalAlignment
constant 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 aJTextField
with 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.HorizontalAlignment
constant, 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.HorizontalAlignment
constant, 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 newJTextField
instance 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
null
values, as this would lead to aNullPointerException
being 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 newJTextField
instance 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
null
values, as this would lead to aNullPointerException
being 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 newJTextField
instance with the provided number property dynamically displaying its value on the text field and a boolean property which will be set totrue
if the text field contains a valid number, andfalse
otherwise.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
Var
will be set totrue
, otherwise it will be set tofalse
.Note that the two provided properties are not permitted to contain
null
values, as this would lead to aNullPointerException
being 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
- AVar
which will be set totrue
if the text field contains a valid number, andfalse
otherwise.- Returns:
- A builder instance for the provided
JTextField
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifnumber
isnull
.IllegalArgumentException
- ifisValid
isnull
.
-
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 newJTextField
instance with the provided number property dynamically displaying its value on the text field and a boolean property which will be set totrue
if the text field contains a valid number, andfalse
otherwise.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
Var
will be set totrue
, otherwise it will be set tofalse
.Note that the two provided properties are not permitted to contain
null
values, as this would lead to aNullPointerException
being 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
- AVar
which will be set totrue
if the text field contains a valid number, andfalse
otherwise.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
- ifnumber
isnull
.IllegalArgumentException
- ifisValid
isnull
.
-
of
Use this to create a builder for the providedJFormattedTextField
instance.- Parameters:
component
- TheJFormattedTextField
instance which should be wrapped by the builder.- Returns:
- A builder instance for the provided
JFormattedTextField
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
formattedTextField
Use this to create a builder for a newJFormattedTextField
instance 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 newJFormattedTextField
instance 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 newJFormattedTextField
instance 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 newJFormattedTextField
UI 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 providedJPasswordField
instance.- Type Parameters:
F
- The type of theJPasswordField
instance which should be wrapped by the builder.- Parameters:
passwordField
- TheJPasswordField
instance which should be wrapped by the builder.- Returns:
- A builder instance for the provided
JPasswordField
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
passwordField
Use this to create a builder for a newJPasswordField
instance 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 newJPasswordField
instance 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 newJPasswordField
instance 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 newJPasswordField
UI 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 providedJProgressBar
instance.- Type Parameters:
P
- The type of theJProgressBar
instance which should be wrapped by the builder.- Parameters:
progressBar
- TheJProgressBar
instance which should be wrapped by the builder.- Returns:
- A builder instance for the provided
JProgressBar
, which enables fluent method chaining. - Throws:
IllegalArgumentException
- ifcomponent
isnull
.
-
progressBar
A factory method for creating a progress bar builder with a defaultJProgressBar
implementation.- Returns:
- A builder instance for the provided
JProgressBar
, which enables fluent method chaining.
-
progressBar
Use this to create a builder for a newJProgressBar
instance 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 newJProgressBar
instance 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 newJProgressBar
instance 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 newJProgressBar
instance with the provided alignment, minimum and maximum values. The alignment is aUI.Align
value, which may be eitherUI.Align.HORIZONTAL
orUI.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 newJProgressBar
instance with the provided alignment, minimum, maximum and current value. The alignment is aUI.Align
value, which may be eitherUI.Align.HORIZONTAL
orUI.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 newJProgressBar
instance with the provided alignment, minimum, maximum and current value property dynamically bound to the progress bar. The alignment is aUI.Align
value, which may be eitherUI.Align.HORIZONTAL
orUI.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 newJProgressBar
instance 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.Align
value, which may be eitherUI.Align.HORIZONTAL
orUI.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 newJProgressBar
instance 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.Align
value, which may be eitherUI.Align.HORIZONTAL
orUI.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 newJProgressBar
instance 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.Align
value, which may be eitherUI.Align.HORIZONTAL
orUI.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 providedJTextArea
instance. -
textArea
Use this to create a builder for a newJTextArea
instance 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 newJTextArea
instance 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 newJTextArea
instance 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 theJList
component 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 newJList
instance with a custom list model. -
list
Creates a newJList
instance builder with the provided array as data model. This is functionally equivalent tolistOf(Object...)
. -
list
-
listOf
A functionally identical alias method forlist(Vals)
, which allows for the creation of a newJList
instance with the provided observable property list (aVals
object) as data model. When the property list changes, theJList
will be updated accordingly. -
list
Allows for the creation of a newJList
instance with 2 observable collections as data model, aVar
property for the selection and aVals
property list for the elements. When any of the properties change, theJList
will be updated accordingly, and conversely, when theJList
selection changes, the properties will be updated accordingly.- Type Parameters:
E
- The type of the elements in the list.- Parameters:
selection
- TheVar
property which should be bound to the selection of theJList
.elements
- TheVals
property which should be bound to the displayed elements of theJList
.- Returns:
- A builder instance for a new
JList
with the provided arguments as data model.
-
list
Allows for the creation of a newJList
instance with 2 observable collections as data model, aVal
property for the selection and aVals
property list for the elements. When any of the properties change, theJList
will be updated accordingly, however, due to the usage of a read onlyVal
property for the selection, theJList
selection 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
- TheVal
property which should be bound to the selection of theJList
.elements
- TheVals
property which should be bound to the displayed elements of theJList
.- Returns:
- A builder instance for a new
JList
with the providedVal
andVals
as data models.
-
listOf
Creates a newJList
instance with the provided array as data model. This is functionally equivalent tolist(Object...)
. -
list
Creates a newJList
instance with the providedUI.List
as data model. This is functionally equivalent tolistOf(java.util.List)
. -
listOf
Creates a newJList
instance with the providedUI.List
as data model. This is functionally equivalent tolist(java.util.List)
. -
of
-
table
Creates a declarative UI builder for theJTable
component 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 newJTable
with a table model whose data can be represented based on a list of lists of entries.
This method will automatically create aAbstractTableModel
instance for you.Please note that when the data of the provided data source changes (i.e. when the data source is a
List
which gets modified), the table model will not be updated automatically! UseUIForTable.updateTableOn(sprouts.Event)
to bind an updateEvent
to the table model.- Type Parameters:
E
- The type of the table entryObject
s.- Parameters:
dataFormat
- An enum which configures the modifiability of the table in a readable fashion.dataSource
- TheTableMapDataSource
returning a column major map based matrix which will be used to populate the table.- Returns:
- This builder node.
-
table
Use this to create a newJTable
with 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 aAbstractTableModel
instance for you.Please note that when the data of the provided data source changes (i.e. when the data source is a
Map
which gets modified), the table model will not be updated automatically! UseUIForTable.updateTableOn(sprouts.Event)
to bind an updateEvent
to the table model.- Type Parameters:
E
- The type of the table entryObject
s.- Parameters:
dataFormat
- An enum which configures the modifiability of the table in a readable fashion.dataSource
- TheTableMapDataSource
returning 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 newJTable
instance 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] ) )
TableModel
interface manually, which is a rather tedious task. Instead, you can use ths fluent API provided by theBasicTableModel.Builder
to create a general purpose table model for your table.- Parameters:
tableModelBuildable
- A lambda function which takes in 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 newJTable
instance 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] ) )
TableModel
interface manually, which is a rather tedious task. Instead, you can configure a model step by step through aConfigurator
function receiving the fluent builder API provided by theBasicTableModel.Builder
.- Parameters:
tableModelBuildable
- A lambda function which takes in 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 customJTableHeader
type in a declarative SwingTree UI builder.- Type Parameters:
H
- The type of theJTableHeader
for 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 theJTableHeader
UI component.- Returns:
- A builder instance for a new
JTableHeader
.
-
of
This returns an instance of a SwingTree builder for aJFrame
type.- 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 suppliedJFrame
with 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 aJDialog
type.- 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 suppliedJDialog
with 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 suppliedJDialog
with 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 suppliedJDialog
with 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
.
-
animateFor
Exposes an API for scheduling periodic animation updates. This is a convenience method forAnimator.animateFor(LifeTime)
.
A typical usage would be:UI.animateFor( 100, TimeUnit.MILLISECONDS ) .until( it -> it.progress() >= 0.75 && someOtherCondition() ) .go( it -> { // do something someComponent.setValue( it.progress() ); // ... someComponent.repaint(); });
- 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
Animator
instance which allows you to configure the animation.
-
animateFor
Exposes a builder API for creating and scheduling periodic animation updates. This is a convenience method forAnimator.animateFor(LifeTime)
.
A typical usage would be:UI.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(); });
- 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
Animator
instance which allows you to configure the animation.
-
animateFor
Exposes a builder API for creating and scheduling periodic animation updates. This is a convenience method forAnimator.animateFor(LifeTime, Stride)
.
A typical usage would be:UI.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(); });
- 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
Animator
instance which allows you to configure the animation.
-
animateFor
Exposes an API for scheduling periodic animation updates. This is a convenience method forAnimator.animateFor(LifeTime)
.
A typical usage would be:UI.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(); });
- Parameters:
duration
- The duration of the animation. This is the time it takes for the animation to reach 100% progress.- Returns:
- An
Animator
instance which allows you to configure 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 forAnimator.animateFor(LifeTime)
.
A typical usage would be:UI.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) ) ); });
- 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
Animator
instance which allows you to configure the animation.
-
lifeTime
A factory method for creating aLifeTime
instance with the given duration and time unit. This is a convenience method forLifeTime.of(long, TimeUnit)
. TheLifeTime
instance is an immutable value type which is used for scheduling animations, usually throughAnimator.animateFor(LifeTime)
or the convenience methodsanimateFor(long, TimeUnit)
,animateFor(double, TimeUnit)
,animateFor(LifeTime)
oranimateFor(LifeTime, java.awt.Component)
. A typical usage would be:UI.animateFor( UI.lifeTime(0.1, TimeUnit.MINUTES) ) .until( it -> it.progress() >= 0.75 && someOtherCondition() ) .go( it -> { // do something });
- Parameters:
duration
- The duration of the animation.unit
- The time unit of the duration.- Returns:
- A
LifeTime
instance.
-
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 theMessageDialog
API, 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 aConfirmAnswer
enum constant.- Parameters:
message
- the message to show- Returns:
Answer.YES
if the user clicked "Yes",Answer.NO
if the user clicked "No",Answer.CANCEL
otherwise.
-
confirm
Shows a conformation dialog with the given title and message and returns the user's answer in the form of aConfirmAnswer
enum constant.- Parameters:
title
- the title of the dialogmessage
- the message to show- Returns:
Answer.YES
if the user clicked "Yes",Answer.NO
if the user clicked "No",Answer.CANCEL
otherwise.
-
confirmation
Exposes theConfirmDialog
API, 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 returnedOptional
will 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
Optional
or 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
Optional
or 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 theOptionsDialog
API 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 theOptionsDialog
API 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 aJFrame
window 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 titledJFrame
window 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 aJFrame
window 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 titledJFrame
window 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 aJFrame
window at the center of the screen using a function receiving theJFrame
and returning the component to be shown.- Parameters:
uiSupplier
- The component supplier which receives the currentJFrame
and returns the component to be shown.
-
show
Use this to quickly launch a UI component in a titledJFrame
window at the center of the screen using a function receiving theJFrame
and returning the component to be shown.- Parameters:
title
- The title of the window.uiSupplier
- The component supplier which receives the currentJFrame
and returns the component to be shown.
-
showUsing
Use this to quickly launch a UI component with a custom event processor inJFrame
window at the center of the screen.- Parameters:
eventProcessor
- the event processor to use for the UI built inside theSupplier
lambda.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 titledJFrame
window at the center of the screen.- Parameters:
eventProcessor
- the event processor to use for the UI built inside theSupplier
lambda.title
- The title of the window.uiSupplier
- The component supplier which builds the UI and supplies the component to be shown.
-
use
Sets aStyleSheet
which 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
JComponent
or SwingTree UI.
-
use
Sets theEventProcessor
to be used for all subsequent UI building operations. This method allows to switch between different event processing strategies. In particular, theEventProcessor.DECOUPLED
is 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 anImageIcon
from 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 returnSvgIcon
instances, 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
- ifpath
isnull
.
-
findIcon
Loads anImageIcon
from 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 returnSvgIcon
instances, 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
- ifdeclaration
isnull
.
-
findSvgIcon
Loads anSvgIcon
from 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
SvgIcon
if it could be found, an empty optional otherwise. - Throws:
NullPointerException
- ifpath
isnull
.
-
findSvgIcon
Loads anSvgIcon
from 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
SvgIcon
if it could be found, an empty optional otherwise. - Throws:
NullPointerException
- ifdeclaration
isnull
.
-