C CSS Samples (Release 8) (original) (raw)

This appendix lists code for the following JavaFX samples:

For the descriptions of this source files, see Skinning JavaFX Applications with CSS.

DownloadButton.java

/*

import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import javafx.stage.Stage; import uicontrolcss.StyleStage.SceneCreator;

/** *

}

DownloadButtonStyle1.css

/*

/* Document : controlStyle */

.button { -fx-text-fill: #e4f3fc; -fx-font: bold 20pt "Tahoma"; -fx-padding: 10; -fx-color: #2d4b8e }

.button:hover{ -fx-color: #395bae; }

DownloadButtonStyle2.css

/*

/* Document : controlStyleLong */

.button { -fx-text-fill: #e4f3fc; -fx-font: bold 20pt "Tahoma"; -fx-padding: 10; -fx-color: #2d4b8e }

.button:hover{ -fx-color: #395bae; }

.button1 { -fx-font: 20pt "Verdana"; -fx-text-fill: #5086bb; -fx-padding: 10; -fx-background-color: linear-gradient(#cbd0d7, white); -fx-background-radius: 23; -fx-border-radius: 23; -fx-border-color: #767676;

}

.button1:hover { -fx-background-color: linear-gradient(white, #cbd0d7); }

.button2 { -fx-background-color: #a0b616; -fx-text-fill: white; -fx-font: bold 22pt "Courier New"; -fx-padding: 10; -fx-background-radius: 10; -fx-border-radius: 10; -fx-border-style: dotted; -fx-border-color: #67644e; -fx-border-width: 2; }

.button2:pressed { -fx-scale-x: 0.8; -fx-scale-y: 0.8; }

StyleStage.java

/*

import javafx.beans.Observable; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.beans.value.ObservableValue; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.ToggleButton; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.HBox; import javafx.stage.Stage; import javafx.stage.WindowEvent;

/** *

}

class StylePanel extends HBox {

public StringProperty selected = new SimpleStringProperty();

ToggleGroup stylesheetToggleGroup = new ToggleGroup();

public StylePanel() {
    super(5);

    StyleButton defaultStylesheetButton = new StyleButton("Default", null);
    defaultStylesheetButton.setSelected(true);
    defaultStylesheetButton.setToggleGroup(stylesheetToggleGroup);

    setPadding(new Insets(0, 0, 30, 0));
    setAlignment(Pos.BOTTOM_LEFT);
    getChildren().addAll(defaultStylesheetButton);
}

public void add(String name, String styleSheetName) {
    StyleButton styleButton = new StyleButton(name, styleSheetName);
    styleButton.setToggleGroup(stylesheetToggleGroup);
    getChildren().addAll(styleButton);
}

class StyleButton extends ToggleButton {

    public StyleButton(String text, final String styleSheetName) {
        super(text);
        selectedProperty().addListener((Observable ov) -> {
            selected.set(styleSheetName);
        });
    }
}

}

UIControlCSS.java

/*

import javafx.application.Application; import javafx.beans.binding.Bindings; import javafx.collections.FXCollections; import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.geometry.Orientation; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.control.ProgressIndicator; import javafx.scene.control.RadioButton; import javafx.scene.control.ScrollPane; import javafx.scene.control.Separator; import javafx.scene.control.Slider; import javafx.scene.control.TextField; import javafx.scene.control.ToggleGroup; import javafx.scene.control.Tooltip; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; import uicontrolcss.StyleStage.SceneCreator;

/** *

}

controlStyle1.css

/*

/* Document : controlStyle1 */

.root{ -fx-font-size: 14pt; -fx-font-family: "Tahoma"; -fx-base: #DFB951; -fx-background: #A78732; -fx-focus-color: #B6A678; }

.button1{ -fx-text-fill: #006464; -fx-background-color: #DFB951; -fx-border-radius: 20; -fx-background-radius: 20; -fx-padding: 5; }

.button2{ -fx-text-fill: #c10000; -fx-background-color: #DFB951; -fx-border-radius: 20; -fx-background-radius: 20; -fx-padding: 5; }

.slider{ -fx-border-color: white; -fx-border-style: dashed; -fx-border-width: 2; }

controlStyle2.css

/*

/* Document : controlStyle2 */

.root{ -fx-font-size: 16pt; -fx-font-family: "Courier New"; -fx-base: rgb(132, 145, 47); -fx-background: rgb(225, 228, 203); }

.button{ -fx-text-fill: rgb(49, 89, 23); -fx-border-color: rgb(49, 89, 23); -fx-border-radius: 5; -fx-padding: 3 6 6 6; }

.borders{ -fx-border-color: rgb(103, 100, 78); -fx-border-style: dotted; -fx-border-width: 1.5; -fx-border-insets: -5; }