Button
Buttons are an essential way to interact with and navigate through an app, and should clearly communicate what action will occur after the user taps them
Examples
To adapt the component to the style of the application it is often necessary to change its colors.

Full Button

Make the button the width of the screen.
Button shapes

Modify the button edges.
Sizes

Change the buttons sizes.
Button image

Add an image to the button.
Do not forget to create a folder called "images" inside /src/main/resources and save the bt_info.png image inside it [images].
Events
Handling events with addPressListener() :
Behind the Class
Attributes
Type
Name
Description
boolean
Button.CENTRALIZE
Center image and text on the button.
Methods
Type
Name
Description
Constructor
Button( )
Creates a simple button
Constructor
Button(Image img)
Creates a simple button with the referred image
Constructor
Button(Image img, byte border)
Creates a button with the referreds image and border
Constructor
Button(String text)
Creates a button with the referred text
Constructor
Button(String text, byte border)
Creates a button with the referreds text and border
Constructor
Button(String text, Image img, int textPosition, int gap)
Creates a button with the referred text and image
Image
getImage( )
Return the button image
String
getText( )
Return the button text
Boolean
isPressed( )
Return true if button is pressed
void
press(boolean pressed)
If true, press the button
void
setBorder(byte border)
Set the button border style
void
setImage(Image img)
Set the button image
void
setPressedColor(int newColor)
Return the button text
void
setText(String text)
Set the button text
void
simulatePress( )
Press and depress the button
References
See also our quick tutorial video on creating buttons.
See the Java Docs for more information.
Last updated
Was this helpful?