I wrote code in JavaFX and used CSS for setting styles for the above issue. The following code made borders for an AnchorPane that are 2 pixels wide:
AnchorP
Sir, Do you strictly require CSS
for this? java
can do it, using Shape
and Border
s
Nikitoslav.java
public class Nikitoslav extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Pane g = new Pane();
g.setBackground(new Background(new BackgroundFill(Color.YELLOW,
null, null)));
g.relocate(20, 20);
BorderStroke bs = new BorderStroke(Color.RED, Color.RED, Color.RED, Color.RED,//the paint around th four corners
BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID,
null, BorderStroke.THIN, null);
g.setBorder(new Border(bs));
Path p = new Path();
p.getElements().addAll(new MoveTo(1, 0),new HLineTo(0),new VLineTo(4), new HLineTo(4), new VLineTo(0),
//creating a rectangle
new HLineTo(3)
);
g.setShape(p);
g.setPrefSize(300, 300);
primaryStage.setScene(new Scene(new Group(g),500,500));
primaryStage.show();
g.setPrefSize(400, 400);
}
public static void main(String[] args) {
launch(args);
}
@Override
public void init() throws Exception {
// TODO Auto-generated method stub
super.init();
}
@Override
public void stop() throws Exception {
// TODO Auto-generated method stub
super.stop();
}
}
With this you don't need nested Background
s or an array of Background
s-(guess that will improve performance)
To explain my code, well, i created my Border
s using the BorderStroke
which Paint
fills for top-right-bottom-left respectively, specified the type of Color and style, after i created an open rectangle with the PathElements
. From the x axis i started from 1 then to 0 the drew a vertical line to 4, the length of the rectangle and drew the bottom width also 4and drew from a vertical line from length 4 to 0 then drew from width 4 to 3 and left points 2 being the hole
Hope it helps