javafx 2 - Set border size -


i want make border of borderpane more round , bold.

i tested code:

bpi.setstyle("-fx-background-color: linear-gradient(to bottom, #f2f2f2, #d4d4d4);"                 + " -fx-border: 12px solid; -fx-border-color: white; -fx-background-radius: 15.0;"                 + " -fx-border-radius: 15.0"); 

i result:

enter image description here

how can fix this?

why current approach doesn't work

don't use -fx-border (it doesn't exist in javafx css).

though there other fx-border-* attributes such -fx-border-color, -fx-border-width , -fx-border-radius, wouldn't recommend them either.

suggested approach

instead, use combination of layered attributes:

  • -fx-background-color
  • -fx-background-insets
  • -fx-background-radius

you can find documentation on these css attribute features in javafx css reference guide.

although using -fx-background-* attributes border seems strange:

  1. it way of borders in default javafx modena.css stylesheet handled.
  2. in experience, when borders rounded, applying borders in way simpler , gives better results using -fx-border-* attributes.

sample code

for instance, here example fxml file applies standard modena.css style attribute values "button things" borderpane. (modena.css comes java 8).

buttonlike

you can copy , paste fxml , css, load them in scenebuilder see looks like.

button-like.css

.button-like {   -fx-background-color:         -fx-shadow-highlight-color,         -fx-outer-border,         -fx-inner-border,         -fx-body-color;   -fx-background-insets: 0 0 -1 0, 0, 1, 2;   -fx-background-radius: 3px, 3px, 2px, 1px; } 

button-like.fxml

<?xml version="1.0" encoding="utf-8"?>  <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.paint.*?> <?scenebuilder-stylesheet button-like.css?>  <anchorpane id="anchorpane" maxheight="-infinity" maxwidth="-infinity"             minheight="-infinity" minwidth="-infinity" prefheight="131.0"             prefwidth="196.0" xmlns:fx="http://javafx.com/fxml/1"             xmlns="http://javafx.com/javafx/2.2">   <children>     <borderpane layoutx="48.0" layouty="26.0" prefheight="79.0" prefwidth="100.0"                 styleclass="button-like"      />   </children> </anchorpane> 

note

you wouldn't want apply above exact style in application styling borderpane, not "button thing". using same styling not button confuse user. sample approach should demonstrate general idea on layering backgrounds achieve style want.

additional example

this example uses same fxml layout file defined above, different stylesheet achieve different style.

imageicon

anchorpane {   -fx-background-color: #232732; }  .button-like {   -fx-outer-border: white;   -fx-body-color: linear-gradient(to bottom, #fafafa, #eaeaea);   -fx-background-color:         -fx-outer-border,         -fx-body-color;   -fx-background-insets: 0, 6;   -fx-background-radius: 6px, 0px;   -fx-background-image: url('http://icons.iconarchive.com/icons/appicns/simplified-app/64/appicns-chrome-icon.png');   -fx-background-repeat: no-repeat;   -fx-background-position: center; }  /** icon license: free non-commercial use. icon license commercial usage: not allowed icon source: http://appicns.com */ 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -