Example usage for javafx.scene.text Text setFont

List of usage examples for javafx.scene.text Text setFont

Introduction

In this page you can find the example usage for javafx.scene.text Text setFont.

Prototype

public final void setFont(Font value) 

Source Link

Usage

From source file:de.micromata.mgc.javafx.FXGuiUtils.java

/**
 * Computes the required height of a text for a given font and a wrapping width. Wrapping width defines when a text
 * needs to be wrapped if its {@link Label#wrapTextProperty()} is true.
 * /*from  w  w  w  . ja  v a2s.c  o m*/
 * @param font font of the label.
 * @param text text to render.
 * @param wrappingWidth wrapping width.
 * @return height.
 */
public static double computeTextHeight(Font font, String text, double wrappingWidth) {
    final Text helper = new Text();
    helper.setText(text);
    helper.setFont(font);

    helper.setWrappingWidth((int) wrappingWidth);
    return helper.getLayoutBounds().getHeight();
}

From source file:Main.java

static Node boxBlur() {
    Text t = new Text();
    t.setText("Blurry Text!");
    t.setFill(Color.RED);/*from   ww w  .  j av a2s  .com*/
    t.setFont(Font.font("null", FontWeight.BOLD, 36));
    t.setX(10);
    t.setY(40);

    BoxBlur bb = new BoxBlur();
    bb.setWidth(5);
    bb.setHeight(5);
    bb.setIterations(3);

    t.setEffect(bb);
    t.setTranslateX(300);
    t.setTranslateY(100);

    return t;
}

From source file:Main.java

static Node bloom() {
    Group g = new Group();

    Rectangle r = new Rectangle();
    r.setX(10);/*w w  w .j av a 2 s .c om*/
    r.setY(10);
    r.setWidth(160);
    r.setHeight(80);
    r.setFill(Color.DARKBLUE);

    Text t = new Text();
    t.setText("Bloom!");
    t.setFill(Color.YELLOW);
    t.setFont(Font.font("null", FontWeight.BOLD, 36));
    t.setX(25);
    t.setY(65);

    g.setCache(true);
    //g.setEffect(new Bloom());
    Bloom bloom = new Bloom();
    bloom.setThreshold(1.0);
    g.setEffect(bloom);
    g.getChildren().add(r);
    g.getChildren().add(t);
    g.setTranslateX(350);
    return g;
}

From source file:Main.java

static Node lighting() {
    Light.Distant light = new Light.Distant();
    light.setAzimuth(-135.0f);//from ww  w  . j  a va  2s .  c  om

    Lighting l = new Lighting();
    l.setLight(light);
    l.setSurfaceScale(5.0f);

    Text t = new Text();
    t.setText("JavaFX\nLighting!");
    t.setFill(Color.RED);
    t.setFont(Font.font("null", FontWeight.BOLD, 70));
    t.setX(500.0f);
    t.setY(100.0f);
    t.setTextOrigin(VPos.TOP);

    t.setEffect(l);

    t.setTranslateX(0);
    t.setTranslateY(320);

    return t;
}

From source file:Main.java

static Node distantLight() {
    Light.Distant light = new Light.Distant();
    light.setAzimuth(-135.0f);//  w ww  .j ava 2s  .c o m
    light.setElevation(30.0f);

    Lighting l = new Lighting();
    l.setLight(light);
    l.setSurfaceScale(5.0f);

    final Text t = new Text();
    t.setText("Distant Light");
    t.setFill(Color.RED);
    t.setFont(Font.font("null", FontWeight.BOLD, 70));
    t.setX(10.0f);
    t.setY(50.0f);
    t.setTextOrigin(VPos.TOP);

    t.setEffect(l);

    final Rectangle r = new Rectangle();
    r.setFill(Color.BLACK);

    Group g = new Group();
    g.getChildren().add(r);
    g.getChildren().add(t);

    g.setTranslateY(460);

    return g;
}

From source file:com.cooksys.postmaster.PostmasterModelSingleton.java

public static PostmasterModelSingleton getInstance() {
    if (_instance == null) {
        try {//from   ww  w .  j  av a 2 s.  co  m
            //see if we can read the object from the file first
            FileInputStream fileInputStream = new FileInputStream(POSTMASTER_DATA_FILE);
            ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
            _instance = (PostmasterModelSingleton) objectInputStream.readObject();

            //fill in transient variables from their serializable counterparts
            _instance.createTransientPropertyInstances();

            for (ParsedHttpRequest request : _instance.requestList) {
                _instance.incomingMessagesList.add(request.getRequestLine());
            }

            int index = 0;
            for (ParsedHttpResponse response : _instance.responseList) {
                Text defaultResponseText = new Text(response.getName());
                if (index == _instance.defaultResponseIndex) {
                    defaultResponseText.setFont(Font.font(null, FontWeight.BOLD, 12));
                }
                _instance.savedResponsesList.add(defaultResponseText);
                index++;
            }

            _instance.messageConsole.set(_instance.messageConsoleSerializable);

        } catch (FileNotFoundException ex) {
            //File does not exist, so create a new instance
            _instance = new PostmasterModelSingleton();
        } catch (IOException | ClassNotFoundException ex) {
            //for these exceptions, just create a new instance
            Logger.getLogger(PostmasterModelSingleton.class.getName()).log(Level.SEVERE, null, ex);
            _instance = new PostmasterModelSingleton();
        }
    }

    return _instance;
}

From source file:Main.java

static Node motionBlur() {
    Text t = new Text();
    t.setX(20.0f);// w w w  .jav  a 2s.  c om
    t.setY(80.0f);
    t.setText("Motion Blur");
    t.setFill(Color.RED);
    t.setFont(Font.font("null", FontWeight.BOLD, 60));

    MotionBlur mb = new MotionBlur();
    mb.setRadius(15.0f);
    mb.setAngle(45.0f);

    t.setEffect(mb);

    t.setTranslateX(520);
    t.setTranslateY(100);

    return t;
}

From source file:Main.java

static Node perspective() {
    Group g = new Group();
    PerspectiveTransform pt = new PerspectiveTransform();
    pt.setUlx(10.0f);//from   ww  w. j  av a2  s  .c  o  m
    pt.setUly(10.0f);
    pt.setUrx(210.0f);
    pt.setUry(40.0f);
    pt.setLrx(210.0f);
    pt.setLry(60.0f);
    pt.setLlx(10.0f);
    pt.setLly(90.0f);

    g.setEffect(pt);
    g.setCache(true);

    Rectangle r = new Rectangle();
    r.setX(10.0f);
    r.setY(10.0f);
    r.setWidth(280.0f);
    r.setHeight(80.0f);
    r.setFill(Color.DARKBLUE);

    Text t = new Text();
    t.setX(20.0f);
    t.setY(65.0f);
    t.setText("Perspective");
    t.setFill(Color.RED);
    t.setFont(Font.font("null", FontWeight.BOLD, 36));

    g.getChildren().add(r);
    g.getChildren().add(t);
    return g;
}

From source file:Main.java

static Node innerShadow() {
    InnerShadow is = new InnerShadow();
    is.setOffsetX(2.0f);/* ww w . j  ava  2  s .  c o m*/
    is.setOffsetY(2.0f);

    Text t = new Text();
    t.setEffect(is);
    t.setX(20);
    t.setY(100);
    t.setText("Inner Shadow");
    t.setFill(Color.RED);
    t.setFont(Font.font("null", FontWeight.BOLD, 80));

    t.setTranslateX(300);
    t.setTranslateY(300);

    return t;
}

From source file:Main.java

static Node displacementMap() {
    int w = 220;// ww w .ja  v a2  s  .  c om
    int h = 100;
    FloatMap map = new FloatMap();
    map.setWidth(w);
    map.setHeight(h);

    for (int i = 0; i < w; i++) {
        double v = (Math.sin(i / 50.0 * Math.PI) - 0.5) / 40.0;
        for (int j = 0; j < h; j++) {
            map.setSamples(i, j, 0.0f, (float) v);
        }
    }

    Group g = new Group();
    DisplacementMap dm = new DisplacementMap();
    dm.setMapData(map);

    Rectangle r = new Rectangle();
    r.setX(20.0f);
    r.setY(20.0f);
    r.setWidth(w);
    r.setHeight(h);
    r.setFill(Color.BLUE);

    g.getChildren().add(r);

    Text t = new Text();
    t.setX(40.0f);
    t.setY(80.0f);
    t.setText("Wavy Text");
    t.setFill(Color.YELLOW);
    t.setFont(Font.font("null", FontWeight.BOLD, 36));

    g.getChildren().add(t);

    g.setEffect(dm);
    g.setCache(true);

    g.setTranslateX(400);
    g.setTranslateY(200);

    return g;
}