JavaFX - css adding background image with transparency

21,665

Solution 1

I use -fx-background-color:transparent to set pngs on my Buttons and transparency works. Try this.

Solution 2

-fx-opacity: 0.5;

Add this to your ID in fx css file

Share:
21,665

Related videos on Youtube

baxbear
Author by

baxbear

Hmm, nope.

Updated on July 02, 2020

Comments

  • baxbear
    baxbear almost 4 years

    I want to add an image (png) this way:

    #leftCorner {
      -fx-background-image: url("images/backgroundTrain2.png");
      -fx-background-repeat: stretch;
      -fx-background-size: 150.0 71.0;
      -fx-background-position: center center;
    }
    

    the problem is that I loose the transparency of the white part of the image. Can somebody tell me what I can do that it stays transparent?

    enter image description here

    thats the picture i try to add as background

  • Aakash
    Aakash over 10 years
    I checked your image it doesnt have transparency, check once in photoshop if possible.
  • baxbear
    baxbear over 10 years
    thx - seems like i failed - ps.: I dont have photoshop - made this with mspaint and thought when I save it as png the white part is automatically transparent
  • Aakash
    Aakash over 10 years
    No MSPaint is "over"smart, it will fill up png transparent parts with white...if not photoshop then use gimp for preparing such pngs :)

Related