Java Code Examples for javafx.scene.layout.Region#setBackground()

The following examples show how to use javafx.scene.layout.Region#setBackground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JFXTextAreaSkin.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
    super.layoutChildren(x, y, w, h);

    final double height = getSkinnable().getHeight();
    linesWrapper.layoutLines(x, y, w, h, height, promptText == null ? 0 : promptText.getLayoutBounds().getHeight() + 3);
    errorContainer.layoutPane(x, height + linesWrapper.focusedLine.getHeight(), w, h);
    linesWrapper.updateLabelFloatLayout();


    if (invalid) {
        invalid = false;
        // set the default background of text area viewport to white
        Region viewPort = (Region) scrollPane.getChildrenUnmodifiable().get(0);
        viewPort.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT,
            CornerRadii.EMPTY,
            Insets.EMPTY)));
        // reapply css of scroll pane in case set by the user
        viewPort.applyCss();
        errorContainer.invalid(w);
        // focus
        linesWrapper.invalid();
    }
}
 
Example 2
Source File: JFXTextAreaSkinAndroid.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
    super.layoutChildren(x, y, w, h);

    final double height = getSkinnable().getHeight();
    linesWrapper.layoutLines(x, y, w, h, height, promptText == null ? 0 : promptText.getLayoutBounds().getHeight() + 3);
    errorContainer.layoutPane(x, height + linesWrapper.focusedLine.getHeight(), w, h);
    linesWrapper.updateLabelFloatLayout();


    if (invalid) {
        invalid = false;
        // set the default background of text area viewport to white
        Region viewPort = (Region) scrollPane.getChildrenUnmodifiable().get(0);
        viewPort.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT,
            CornerRadii.EMPTY,
            Insets.EMPTY)));
        // reapply css of scroll pane in case set by the user
        viewPort.applyCss();
        errorContainer.invalid(w);
        // focus
        linesWrapper.invalid();
    }
}
 
Example 3
Source File: JFXTextAreaSkinBisqStyle.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
    super.layoutChildren(x, y, w, h);

    final double height = getSkinnable().getHeight();
    final double width = getSkinnable().getWidth();
    linesWrapper.layoutLines(x - 2, y - 2, width, h, height, promptText == null ? 0 : promptText.getLayoutBounds().getHeight() + 3);
    errorContainer.layoutPane(x, height + linesWrapper.focusedLine.getHeight(), width, h);
    linesWrapper.updateLabelFloatLayout();

    if (invalid) {
        invalid = false;
        // set the default background of text area viewport to white
        Region viewPort = (Region) scrollPane.getChildrenUnmodifiable().get(0);
        viewPort.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT,
                CornerRadii.EMPTY,
                Insets.EMPTY)));
        // reapply css of scroll pane in case set by the user
        viewPort.applyCss();
        errorContainer.invalid(w);
        // focus
        linesWrapper.invalid();
    }
}
 
Example 4
Source File: DemoPane.java    From FxDock with Apache License 2.0 5 votes vote down vote up
private Node createColorNode(String c)
{
	int rgb = Hex.parseInt(c, 0);
	Region r = new Region();
	r.setBackground(FX.background(FX.rgb(rgb)));
	return r;
}
 
Example 5
Source File: FxIconBuilder.java    From FxDock with Apache License 2.0 5 votes vote down vote up
/** creates a rectangle filled with the current fill color */
public void fill(double x, double y, double w, double h)
{
	Region r = new Region();
	r.setManaged(false);
	r.resizeRelocate(x + xorigin, y + yorigin, w, h);
	r.setBackground(FX.background(fill));
	
	elements.add(r);
}
 
Example 6
Source File: DropOp.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public void addRect(Node ref, double x, double y, double w, double h)
{
	BoundingBox screenr = new BoundingBox(x, y, w, h);
	Bounds b = ref.localToScreen(screenr);
	b = target.screenToLocal(b);
	
	Region r = new Region();
	r.relocate(b.getMinX(), b.getMinY());
	r.resize(b.getWidth(), b.getHeight());
	r.setBackground(FX.background(Color.color(0, 0, 0, 0.3)));
	
	add(r);
}
 
Example 7
Source File: DropOp.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public void addOutline(Node ref, double x, double y, double w, double h)
{
	BoundingBox screenr = new BoundingBox(x, y, w, h);
	Bounds b = ref.localToScreen(screenr);
	b = target.screenToLocal(b);
	
	Region r = new Region();
	r.relocate(b.getMinX(), b.getMinY());
	r.resize(b.getWidth(), b.getHeight());
	r.setBackground(FX.background(Color.color(0, 0, 0, 0.1)));
	
	add(r);
}
 
Example 8
Source File: JFXNodeUtils.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
public static void updateBackground(Background newBackground, Region nodeToUpdate, Paint fill) {
    if (newBackground != null && !newBackground.getFills().isEmpty()) {
        final BackgroundFill[] fills = new BackgroundFill[newBackground.getFills().size()];
        for (int i = 0; i < newBackground.getFills().size(); i++) {
            BackgroundFill bf = newBackground.getFills().get(i);
            fills[i] = new BackgroundFill(fill, bf.getRadii(), bf.getInsets());
        }
        nodeToUpdate.setBackground(new Background(fills));
    }
}
 
Example 9
Source File: PercentageTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    barColor = tile.getBarColor();

    barBackground = new Region();
    barBackground.setBackground(new Background(new BackgroundFill(tile.getBarBackgroundColor(), new CornerRadii(0.0, 0.0, 0.025, 0.025, true), Insets.EMPTY)));

    barClip = new Rectangle();

    bar = new Rectangle();
    bar.setFill(tile.getBarColor());
    bar.setStroke(null);
    bar.setClip(barClip);

    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    valueText = new Text(String.format(locale, formatString, ((tile.getValue() - minValue) / range * 100)));
    valueText.setFill(tile.getValueColor());
    Helper.enableNode(valueText, tile.isValueVisible());

    unitText = new Text(tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    Helper.enableNode(unitText, !tile.getUnit().isEmpty());

    valueUnitFlow = new TextFlow(valueText, unitText);
    valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);

    description = new Label(tile.getDescription());
    description.setAlignment(tile.getDescriptionAlignment());
    description.setWrapText(true);
    description.setTextFill(tile.getTextColor());
    Helper.enableNode(description, !tile.getDescription().isEmpty());

    percentageText = new Text();
    percentageText.setFill(tile.getBarColor());

    percentageUnitText = new Text("%");
    percentageUnitText.setFill(tile.getBarColor());

    maxValueRect = new Rectangle();
    maxValueRect.setFill(tile.getThresholdColor());

    maxValueText = new Text();
    maxValueText.setFill(tile.getBackgroundColor());

    maxValueUnitText = new Text(tile.getUnit());
    maxValueUnitText.setFill(tile.getBackgroundColor());

    getPane().getChildren().addAll(barBackground, bar, titleText, valueUnitFlow, description, percentageText, percentageUnitText, maxValueRect, maxValueText, maxValueUnitText);
}
 
Example 10
Source File: PercentageTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    barColor = tile.getBarColor();

    barBackground = new Region();
    barBackground.setBackground(new Background(new BackgroundFill(tile.getBarBackgroundColor(), new CornerRadii(0.0, 0.0, 0.025, 0.025, true), Insets.EMPTY)));

    barClip = new Rectangle();

    bar = new Rectangle();
    bar.setFill(tile.getBarColor());
    bar.setStroke(null);
    bar.setClip(barClip);

    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    valueText = new Text(String.format(locale, formatString, ((tile.getValue() - minValue) / range * 100)));
    valueText.setFill(tile.getValueColor());
    Helper.enableNode(valueText, tile.isValueVisible());

    unitText = new Text(tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    Helper.enableNode(unitText, !tile.getUnit().isEmpty());

    valueUnitFlow = new TextFlow(valueText, unitText);
    valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);

    description = new Label(tile.getDescription());
    description.setAlignment(tile.getDescriptionAlignment());
    description.setWrapText(true);
    description.setTextFill(tile.getTextColor());
    Helper.enableNode(description, !tile.getDescription().isEmpty());

    percentageText = new Text();
    percentageText.setFill(tile.getBarColor());

    percentageUnitText = new Text("%");
    percentageUnitText.setFill(tile.getBarColor());

    maxValueRect = new Rectangle();
    maxValueRect.setFill(tile.getThresholdColor());
    Helper.enableNode(maxValueRect, tile.getMaxValueVisible());

    maxValueText = new Text();
    maxValueText.setFill(tile.getBackgroundColor());
    Helper.enableNode(maxValueText, tile.getMaxValueVisible());

    maxValueUnitText = new Text(tile.getUnit());
    maxValueUnitText.setFill(tile.getBackgroundColor());
    Helper.enableNode(maxValueUnitText, tile.getMaxValueVisible());

    getPane().getChildren().addAll(barBackground, bar, titleText, valueUnitFlow, description, percentageText, percentageUnitText, maxValueRect, maxValueText, maxValueUnitText);
}
 
Example 11
Source File: TileTextKpiSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    barBackground = new Region();
    barBackground.setBackground(new Background(new BackgroundFill(gauge.getBarBackgroundColor(), new CornerRadii(0.0, 0.0, 0.025, 0.025, true), Insets.EMPTY)));

    barClip = new Rectangle();

    bar = new Rectangle();
    bar.setFill(gauge.getBarColor());
    bar.setStroke(null);
    bar.setClip(barClip);

    titleText = new Text();
    titleText.setFill(gauge.getTitleColor());
    Helper.enableNode(titleText, !gauge.getTitle().isEmpty());

    valueText = new Text();
    valueText.setFill(gauge.getValueColor());
    Helper.enableNode(valueText, gauge.isValueVisible());

    unitText = new Text(gauge.getUnit());
    unitText.setFill(gauge.getUnitColor());
    Helper.enableNode(unitText, !gauge.getUnit().isEmpty());

    percentageText = new Text();
    percentageText.setFill(gauge.getBarColor());

    percentageUnitText = new Text("%");
    percentageUnitText.setFill(gauge.getBarColor());

    maxValueRect = new Rectangle();
    maxValueRect.setFill(gauge.getThresholdColor());

    maxValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMaxValue()));
    maxValueText.setFill(gauge.getBackgroundPaint());

    maxValueUnitText = new Text(gauge.getUnit());
    maxValueUnitText.setFill(gauge.getBackgroundPaint());

    pane = new Pane(barBackground, bar, titleText, valueText, unitText, percentageText, percentageUnitText, maxValueRect, maxValueText, maxValueUnitText);
    pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(PREFERRED_WIDTH * 0.025), new BorderWidths(gauge.getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), new CornerRadii(PREFERRED_WIDTH * 0.025), Insets.EMPTY)));

    getChildren().setAll(pane);
}