Alberto acepsut
Alberto acepsut

Reputation: 2022

How to add an image to a button?

I have followed the FX 2 tutorial in order to add a .png image to a button, but I didn't succeed.

The pointer.png is in package icons: in controller class I have try this

@Override
public void initialize(URL url, ResourceBundle rb) {

    Image pointer = new Image(getClass().getResourceAsStream("C:\\Users\\utente\\Desktop\\Java\\NewProjectX\\src\\icons\\Pointer.png"));
    togglebuttonPointer.setGraphic(new ImageView(pointer));

but it doesn't work.

Any help really appreciated.

Upvotes: 0

Views: 179

Answers (1)

zhujik
zhujik

Reputation: 6574

try

Image pointer = new Image(getClass().getResourceAsStream("/icons/Pointer.png"));

Upvotes: 1

Related Questions