3

Why can't add a padding left to the image inside the #todo button ?

enter image description here

.button {           
    -fx-background-size: 18 18;
    -fx-background-repeat: no-repeat;       
    -fx-background-position:left;   
    -fx-padding:20;
    /* same as -fx-label-padding:20; */
}

#todo {
    -fx-background-image: url("../images/Knob Add.png");
}
3
  • As I've observed CSS ref, it is API... If you have suggestions, you can file an RFE in jfx-jira. Commented May 31, 2013 at 11:11
  • @AlexanderKirov well, first time with jira, javafx-jira.kenai.com/browse/RT-30842 , wonder if I'm doing it right. Commented May 31, 2013 at 11:29
  • All right. Waiting for developers answer Commented May 31, 2013 at 11:31

1 Answer 1

3

Don't use backgrounds to add images to your button, instead set a graphic on the button.

#todo .button {           
    -fx-padding: 20px;
    -fx-graphic: url("http://icons.iconarchive.com/icons/martz90/circle-addon1/16/text-plus-icon.png"); 
     /* Icon License: CC Attribution-Noncommercial-No Derivate 3.0 http://www.iconarchive.com/show/circle-addon1-icons-by-martz90/text-plus-icon.html*/
}

paddedtodo

Background information on Backgrounds and Margins

Backgrounds cover the entire background of a region, including the padded area, so you can't position a background using padding. Backgrounds are also a lot trickier than style with css and configure than graphics (as you found out...). You could get some approximation of what you want by setting -fx-background-position property and also adjusting your padding to allow for the background area of your background image so that your button text content doesn't overwrite the background. But it is fiddly and not worth it when it can be done in a much more straightforward way using a graphic.

I recall some conversation among developers about adding a margin property. If such a property were added, the background would not spill into the margin but be encapsulated by it. Such a property is not in Java 7 though,

Related Question

JavaFX - create custom button with image

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.