Class TextStyleBuilder Stay organized with collections Save and categorize content based on your preferences.
Page Summary
TextStyleBuilder is used to create TextStyle objects and configure text properties like name, color, and size.
The
build()method finalizes the configuration and returns a TextStyle object.Methods like
setColor(),setFontName(), andsetFontSize()allow setting specific text style attributes.These setter methods return the TextStyleBuilder itself, enabling method chaining.
A builder used to createText objects. It allows configuration of the text'sproperties such as name, color, and size.
The following example shows how to create a text style using the builder. For a more completeexample, refer to the documentation forText.
// Creates a new text style that uses 26-point, blue, Ariel font.consttextStyleBuilder=Charts.newTextStyle().setColor('#0000FF').setFontName('Ariel').setFontSize(26);conststyle=textStyleBuilder.build();
Methods
| Method | Return type | Brief description |
|---|---|---|
build() | Text | Builds and returns a text style configuration object that was built using this builder. |
set | Text | Sets the color of the text style. |
set | Text | Sets the font name of the text style. |
set | Text | Sets the font size of the text style. |
Detailed documentation
build()
Builds and returns a text style configuration object that was built using this builder.
// Creates a new text style that uses 26-point blue font.consttextStyleBuilder=Charts.newTextStyle().setColor('#0000FF').setFontSize(26);conststyle=textStyleBuilder.build();
Return
Text — A text style object built using this builder.
setColor(cssValue)
Sets the color of the text style.
// Creates a new text style that uses blue font.consttextStyleBuilder=Charts.newTextStyle().setColor('#0000FF');conststyle=textStyleBuilder.build();
Parameters
| Name | Type | Description |
|---|---|---|
css | String | The CSS value for the color (such as"blue" or"#00f"). |
Return
Text — This builder, useful for chaining.
setFontName(fontName)
Sets the font name of the text style.
// Creates a new text style that uses Ariel font.consttextStyleBuilder=Charts.newTextStyle().setFontName('Ariel');conststyle=textStyleBuilder.build();
Parameters
| Name | Type | Description |
|---|---|---|
font | String | The font name to use for the text style. |
Return
Text — This builder, useful for chaining.
setFontSize(fontSize)
Sets the font size of the text style.
// Creates a new text style that uses 26-point font.consttextStyleBuilder=Charts.newTextStyle().setFontSize(26);conststyle=textStyleBuilder.build();
Parameters
| Name | Type | Description |
|---|---|---|
font | Number | The font size in pixels to use for the text style. |
Return
Text — This builder, useful for chaining.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.