Package swingtree
Class RenderAs<C extends JComponent,E,T extends E>
java.lang.Object
swingtree.RenderAs<C,E,T>
- Type Parameters:
C
- The type of the component which is used to render the cell.E
- The type of the value of the cell.T
- The type of the value of the cell.
This class models the API of the
RenderBuilder
which allows you to
specify how a cell should be rendered.
Most likely you will want to call asText(Function)
on this as most cells are rendered as simple texts.
An example would be a combo box containing enum values, which
you don't want to render as the enum name (all capital letters), but rather as a
more human-readable string.-
Method Summary
Modifier and TypeMethodDescriptionas
(Configurator<CellDelegate<C, T>> valueInterpreter) Specify a lambda which receives aCellDelegate
instance for you to customize its renderer.asComponent
(Function<CellDelegate<C, T>, Component> renderer) Specify a lambda which receives aCellDelegate
instance and return aComponent
which is then used to render the cell.Specify a lambda which receives aCellDelegate
instance and return aString
which is then used to render the cell.render
(BiConsumer<CellDelegate<C, T>, Graphics2D> renderer) Specify a lambda which receives aCellDelegate
instance as well as aGraphics
instance and then renders the cell.
-
Method Details
-
as
Specify a lambda which receives aCellDelegate
instance for you to customize its renderer. This is the most generic way to customize the rendering of a cell, as you can choose between vastly different ways of rendering:.when( MyEnum.class ) .as( cell -> { // do component based rendering: cell.setRenderer( new JLabel( "Hello World" ) ); // or do graphics rendering directly: cell.setRenderer( g -> { // draw something g.drawString( "Hello World", 0, 0 ); }); })
- Parameters:
valueInterpreter
- A lambda which customizes the provided cell.- Returns:
- The builder API allowing method chaining.
-
asComponent
Specify a lambda which receives aCellDelegate
instance and return aComponent
which is then used to render the cell..when( MyEnum.class ) .asComponent( cell -> new JLabel( "Hello World" ) )
- Parameters:
renderer
- A function which returns aComponent
which is then used to render the cell.- Returns:
- The builder API allowing method chaining.
-
asText
Specify a lambda which receives aCellDelegate
instance and return aString
which is then used to render the cell..when( MyEnum.class ) .asText( cell -> "Hello World" )
- Parameters:
renderer
- A function which returns aString
which is then used to render the cell.- Returns:
- The builder API allowing method chaining.
-
render
Specify a lambda which receives aCellDelegate
instance as well as aGraphics
instance and then renders the cell..when( MyEnum.class ) .render( (cell, g) -> { // draw something g.drawString( "Hello World", 0, 0 ); })
- Parameters:
renderer
- A function which receives aCellDelegate
instance as well as aGraphics
instance and then renders the cell.- Returns:
- The builder API allowing method chaining.
-