0

Is there a way to show only the (say) bottom and right borders of a rectangle? Is the rectangle width/height based on the centerlines of the border strokes? Am I conflating css border with the rectangle's strokes or are they in fact the same thing?

My bigger problem in context:

A partial screenshot:

enter image description here

In the lower half of of the picture there are two independent "week-lines"/"calendars". Each little square represents a day. There are 5 per column, representing Mo Tu We Th Fr of the same week. There are roughly four columns (representing weeks) per month.

I would like to introduce a small gap between months. If the month changes over a weekend, the corresponding gap would just be a thin vertical line. Otherwise it would have a "step" in it.

Each day's square is a Rectangle on its own little StackPane in its own cell of a GridPane. (I can change the contents of the cells in the GridPane if I really have to, as long as I can still color each cell's interior freely.) The Rectangle sizes are set on construction. Here is a code fragment showing what I tried (This runs for each cell):

StringBuilder stylebuilder = new StringBuilder("-fx-border-width: 1; -fx-border-color: white; -fx-border-style: hidden;");
Month month = date.getMonth();
if(month != date.plusDays(1).getMonth()){
    stylebuilder.append("-fx-border-bottom-style: solid;");
}
if(month != date.plusWeeks(1).getMonth()){
    stylebuilder.append("-fx-border-right-style: solid;");
}
if(month != date.minusDays(1).getMonth()){
    stylebuilder.append("-fx-border-top-style: solid;");
}
if(month != date.minusWeeks(1).getMonth()){
    stylebuilder.append("-fx-border-left-style: solid;");
}
rectangle.setStyle(stylebuilder.toString());

Any advice would be appreciated.

Museful
  • 6,711
  • 5
  • 42
  • 68
  • With strokes I am of the opinion you are talking about the border strokes. Is it? – ItachiUchiha Oct 30 '15 at 11:00
  • @ItachiUchiha Yes, I'll try to clarify the question. – Museful Oct 30 '15 at 11:02
  • Doesn't using `-fx-border-width: 0, 1, 1, 0;` solve your problem? – ItachiUchiha Oct 30 '15 at 11:05
  • @ItachiUchiha I can't even get a rectangle to show any border at all. I just tried `-fx-fill: white ; -fx-border-style: solid; -fx-border-width: 1 1 1 1; -fx-border-color: black;` and all I get is a white borderless rectangle. Maybe I should make a separate question about that with complete code for reproducing it. – Museful Oct 30 '15 at 11:14
  • You can add the complete code in this question as well. – ItachiUchiha Oct 30 '15 at 11:22
  • 1
    Try using a "nested background" approach to implement the borders. See, e.g. http://stackoverflow.com/questions/32892646/adding-borders-to-gridpane-javafx – James_D Oct 30 '15 at 11:24
  • @ItachiUchiha Please see [here](http://stackoverflow.com/questions/33434882/can-a-rectangle-be-styled-to-show-a-border). I am unable to style a rectangle to show any border at all. – Museful Oct 30 '15 at 11:26

1 Answers1

0

I was indeed conflating strokes with borders. Any Shape (and therefore any Rectangle) has strokes, not borders.

enter image description here

The solution was to do away with the rectangles, background-color the panes, and inset the background to get the boundaries:

pane.setMinSize(cellSize, cellSize);
pane.setPrefSize(cellSize, cellSize);
pane.setMaxSize(cellSize, cellSize);
Month month = date.getMonth();
insets = new Insets(
        month != date.minusDays(1).getMonth() ? monthSepWidth/2 : 0,
        month != date.plusWeeks(1).getMonth() ? monthSepWidth/2 : 0,
        month != date.plusDays(1).getMonth()  ? monthSepWidth/2 : 0,
        month != date.minusWeeks(1).getMonth() ? monthSepWidth/2 : 0
);
pane.setBackground(new Background(new BackgroundFill(color,CornerRadii.EMPTY,insets)));
Museful
  • 6,711
  • 5
  • 42
  • 68