Set Control Id and use it in css
/*
* Copyright (c) 2011, 2012 Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//package neonsign;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.effect.Blend;
import javafx.scene.effect.BlendMode;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.InnerShadow;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Main extends Application {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
double width = 600;
double height = 300;
Pane root = new Pane();
Scene scene = new Scene(root, width, height);
Rectangle rect = new Rectangle (width, height);
rect.getStyleClass().add("myrect");
Text text = new Text();
text.setId("fancytext");
text.setStyle("#fancytext {-fx-fill: white;-fx-font: 120px Harlow; }");
text.setX(20);
text.setY(150);
Blend blend = new Blend();
blend.setMode(BlendMode.MULTIPLY);
DropShadow ds = new DropShadow();
ds.setColor(Color.rgb(254, 235, 66, 0.3));
ds.setOffsetX(5);
ds.setOffsetY(5);
ds.setRadius(5);
ds.setSpread(0.2);
blend.setBottomInput(ds);
DropShadow ds1 = new DropShadow();
ds1.setColor(Color.web("#f13a00"));
ds1.setRadius(20);
ds1.setSpread(0.2);
Blend blend2 = new Blend();
blend2.setMode(BlendMode.MULTIPLY);
InnerShadow is = new InnerShadow();
is.setColor(Color.web("#feeb42"));
is.setRadius(9);
is.setChoke(0.8);
blend2.setBottomInput(is);
InnerShadow is1 = new InnerShadow();
is.setColor(Color.web("#f13a00"));
is.setRadius(5);
is.setChoke(0.4);
blend2.setTopInput(is1);
Blend blend1 = new Blend();
blend1.setMode(BlendMode.MULTIPLY);
blend1.setBottomInput(ds1);
blend1.setTopInput(blend2);
blend.setTopInput(blend1);
text.setEffect(blend);
TextField textField = new TextField();
textField.setText("Neon Sign");
text.textProperty().bind(textField.textProperty());
textField.setPrefColumnCount(40);
textField.setLayoutX(50);
textField.setLayoutY(260);
root.getChildren().addAll(rect,text,textField);
primaryStage.setScene(scene);
// scene.getStylesheets().add(Main.class.getResource("brickStyle.css").toExternalForm());
primaryStage.show();
}
}
Related examples in the same category
1. | Using CSS to style the border | | |
2. | Connect to CSS Style Sheet in same Package | | |
3. | Connect to CSS Style Sheet in another Package | | |
4. | Set CSS style | | |
5. | -fx-stroke: green; | | |
6. | -fx-stroke-width: 5; | | |
7. | -fx-stroke-dash-array: 12 2 4 2; | | |
8. | -fx-stroke-dash-offset: 6; | | |
9. | -fx-stroke-line-cap: butt; | | |
10. | -fx-background-color: transparent; | | |
11. | -fx-border-color: white; | | |
12. | -fx-background-radius: 30; | | |
13. | -fx-border-radius: 30; | | |
14. | -fx-text-fill: white; | | |
15. | -fx-font-weight: bold; | | |
16. | -fx-font-size: 14px; | | |
17. | -fx-padding: 10 20 10 20; | | |
18. | Chart -fx-background-color: rgba(0,168,355,0.05); | | |
19. | Chart -fx-border-color: rgba(0,16,35,0.5) rgba(0,68,55,0.6) transparent rgba(0,68,55,0.7); | | |
20. | Set css file to Scene | | |
21. | Use addAll() to attach several stylesheets. | | |
22. | Sample application that shows the use of CSS with the different layout panes provided by the JavaFX layout API. | | |
23. | -fx-fill: red; | | |