下面列出了javafx.scene.control.Label#setFont ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Pane getParamPane(final PluginParametersNode node) {
if (node.getChildren().isEmpty()) {
return null;
}
if (currentChild == -1) {
warningLabel = new Label(message);
warningLabel.setFont(Font.font(Font.getDefault().getFamily(), FontPosture.ITALIC, fontSize));
warningLabel.setWrapText(true);
warningLabel.setAlignment(Pos.CENTER);
final HBox warning = new HBox(warningIcon, warningLabel);
warning.setStyle("-fx-border-color: red");
return new VBox(warning);
}
final Pane paramPane = super.getParamPane(node);
final SimpleDoubleProperty updated = new SimpleDoubleProperty();
updated.bind(Bindings.max(maxParamWidth, paramPane.widthProperty()));
maxParamWidth = updated;
warningLabel.prefWidthProperty().bind(maxParamWidth);
return paramPane;
}
public ProcessController(){
VBox vBox = new VBox();
vBox.setAlignment(Pos.BASELINE_CENTER);
vBox.setMinWidth(300);
vBox.setBackground(new Background(new BackgroundFill(Color.rgb(250, 250, 250), CornerRadii.EMPTY, Insets.EMPTY)));
ProgressIndicator progressIndicator = new ProgressIndicator();
progressIndicator.setStyle(CommUtils.STYLE_TRANSPARENT);
int circleSize = 75;
progressIndicator.setMinWidth(circleSize);
progressIndicator.setMinHeight(circleSize);
Label topLab = new Label("正在识别图片,请稍等.....");
topLab.setFont(Font.font(18));
vBox.setSpacing(10);
vBox.setPadding(new Insets(20, 0, 20, 0));
vBox.getChildren().add(progressIndicator);
vBox.getChildren().add(topLab);
Scene scene = new Scene(vBox, Color.TRANSPARENT);
setScene(scene);
initStyle(StageStyle.TRANSPARENT);
CommUtils.initStage(this);
}
private Parent buildUI() {
fc = new FileChooser();
fc.getExtensionFilters().clear();
ExtensionFilter jpgFilter = new ExtensionFilter("JPG, JPEG images", "*.jpg", "*.jpeg", "*.JPG", ".JPEG");
fc.getExtensionFilters().add(jpgFilter);
fc.setSelectedExtensionFilter(jpgFilter);
fc.setTitle("Select a JPG image");
lstLabels = new ListView<>();
lstLabels.setPrefHeight(200);
Button btnLoad = new Button("Select an Image");
btnLoad.setOnAction(e -> validateUrlAndLoadImg());
HBox hbBottom = new HBox(10, btnLoad);
hbBottom.setAlignment(Pos.CENTER);
loadedImage = new ImageView();
loadedImage.setFitWidth(300);
loadedImage.setFitHeight(250);
Label lblTitle = new Label("Label image using TensorFlow");
lblTitle.setFont(Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 40));
VBox root = new VBox(10,lblTitle, loadedImage, new Label("Results:"), lstLabels, hbBottom);
root.setAlignment(Pos.TOP_CENTER);
return root;
}
public Parent createContent() {
final ColorPicker colorPicker = new ColorPicker(Color.GREEN);
final Label coloredText = new Label("Colors");
Font font = new Font(53);
coloredText.setFont(font);
final Button coloredButton = new Button("Colored Control");
Color c = colorPicker.getValue();
coloredText.setTextFill(c);
coloredButton.setStyle(createRGBString(c));
colorPicker.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
Color newColor = colorPicker.getValue();
coloredText.setTextFill(newColor);
coloredButton.setStyle(createRGBString(newColor));
}
});
VBox outerVBox = new VBox(coloredText, coloredButton, colorPicker);
outerVBox.setAlignment(Pos.CENTER);
outerVBox.setSpacing(20);
outerVBox.setMaxSize(VBox.USE_PREF_SIZE, VBox.USE_PREF_SIZE);
return outerVBox;
}
public Profile (String profileMessageText1, String profileMessageText2)
{
grid.setPadding (new Insets (10, 40, 10, 30));
grid.setHgap (10);
grid.setVgap (5);
String[] tokens = profileMessageText1.split ("\\s+");
int row = 1;
for (String token : tokens)
{
Label label = new Label (token);
label.setFont (labelFont);
grid.add (label, 1, row++);
if (token.startsWith ("PREFIX(") && token.endsWith (")"))
{
prefix = token.substring (7, token.length () - 1);
label.setFont (boldFont);
}
}
dialog.setTitle ("Profile");
dialog.getDialogPane ().getButtonTypes ().addAll (btnTypeOK);
dialog.getDialogPane ().setContent (grid);
}
public Church(Main.Location loc, StrangeBridge strangeBridge) {
super(CHURCH, loc, strangeBridge);
Label label = new Label();
label.textProperty().bind(mealsServed.asString());
label.setFont(Font.font("Impact", 12 * Main.SCALE));
label.setTranslateX(-8 * Main.SCALE);
label.setTranslateY(3 * Main.SCALE);
getChildren().add(label);
}
private void addSpaceFiller() {
Label lbl = new Label("{}");
lbl.setFont(Font.font(15));
editorsPane.getChildren().add(lbl);
Separator sep = new Separator(Orientation.HORIZONTAL);
sep.setOpaqueInsets(new Insets(lbl.getHeight() / 2));
sep.setPrefWidth(numEditorsPerRow * tfPrefWidth - lbl.getWidth() - 10);
editorsPane.getChildren().add(sep);
}
protected BorderPane createCalendarMonthLabelPane() {
monthYearLabel = new Label();
monthYearLabel.getStyleClass().add(SPINNER_LABEL);
monthYearLabel.setFont(Font.font(ROBOTO, FontWeight.BOLD, 13));
monthYearLabel.setTextFill(DEFAULT_COLOR);
BorderPane monthContainer = new BorderPane();
monthContainer.setMinHeight(50);
monthContainer.setCenter(monthYearLabel);
monthContainer.setPadding(new Insets(2, 12, 2, 12));
return monthContainer;
}
public static final void adjustTextSize(final Label TEXT, final double MAX_WIDTH, double fontSize) {
final String FONT_NAME = TEXT.getFont().getName();
while (TEXT.getLayoutBounds().getWidth() > MAX_WIDTH && fontSize > 0) {
fontSize -= 0.005;
TEXT.setFont(new Font(FONT_NAME, fontSize));
}
}
private static Label text(Resolution res, ColorMatrix matrix, int col) {
Label l = new Label(Integer.toString(getLuma(matrix, col)));
l.setFont(font(res.height / 54));
l.setTextFill(gray(matrix.fromLumaCode(matrix.YMIN * 4)));
l.setTextAlignment(TextAlignment.CENTER);
l.setAlignment(Pos.CENTER);
l.setPrefSize(getW(res.width, col), getLabelH(res.height));
return l;
}
private Label initNewLabelColumn(String text) {
Label label = new Label();
// label.setMaxWidth(Double.MAX_VALUE);
// label.setMinHeight(Double.MAX_VALUE);
// label.setAlignment(Pos.CENTER);
label.setFont(new Font(12));
GridPane.setMargin(label, new Insets(0, 0, 0, 5));
label.setText(text);
return label;
}
private Label newAreaLabel(final String item_name)
{
final Label label = new Label(item_name);
label.setBorder(border);
label.setAlignment(Pos.CENTER);
label.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
label.setFont(font);
GridPane.setHgrow(label, Priority.ALWAYS);
GridPane.setVgrow(label, Priority.ALWAYS);
return label;
}
public Node create() {
if (font == null) {
return new ImageView();
}
Label label = new Label();
label.getStyleClass().add("image-label-" + fontSuffix);
label.setFont(font);
if (color != null)
label.setTextFill(color);
label.setText(namedChar.getChar() + "");
return label;
}
private void afterConstructor() {
root.setStyle("-fx-background-color:-fx-control-inner-background;-fx-border-color:black;-fx-border-width:1px;");
final Button btnClose = new Button("x");
btnClose.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
setShowing(false);
}
});
final Label lblTitle = new Label(notificationTitle);
lblTitle.setFont(Font.font(15));
lblTitle.setStyle("-fx-text-fill:white");
final BorderPane borderPaneTitle = new BorderPane(null, null, btnClose, null, lblTitle);
if (isErrorNotification) {
borderPaneTitle.setStyle("-fx-background-color:red;");
} else {
borderPaneTitle.setStyle("-fx-background-color:-fx-accent;");
}
borderPaneTitle.setPadding(new Insets(5));
VBox.setVgrow(borderPaneTitle, Priority.NEVER);
root.getChildren().add(borderPaneTitle);
final Label lblText = new Label(notificationText);
lblText.setWrapText(true);
final StackPane stackPaneContent = new StackPane(lblText);
stackPaneContent.setAlignment(Pos.TOP_LEFT);
stackPaneContent.setPadding(borderPaneTitle.getPadding());
root.getChildren().add(stackPaneContent);
final double width = 360;
root.setPrefWidth(width);
root.setMaxWidth(width);
}
public Church(Main.Location loc) {
super(CHURCH, loc);
Label label = new Label();
label.textProperty().bind(mealsServed.asString());
label.setFont(Font.font("Impact", 12 * Main.SCALE));
label.setTranslateX(-8 * Main.SCALE);
label.setTranslateY(3 * Main.SCALE);
getChildren().add(label);
}
public BasicView() {
items.setHgap(5.0);
items.setVgap(10.0);
items.setPadding(new Insets(10));
PlayerService.getInstance().getService().ifPresent(service -> {
if (service.isReady()) {
updateProductDetails(service);
} else {
service.readyProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if (newValue) {
updateProductDetails(service);
service.readyProperty().removeListener(this);
}
}
});
}
});
Label lblHealth = new Label("", MaterialDesignIcon.HEALING.graphic());
lblHealth.textProperty().bind(Bindings.concat("Current Health: ", player.healthProperty()));
lblHealth.setFont(Font.font(24.0));
lblHealth.textFillProperty().bind(Bindings.when(player.healthProperty().lessThanOrEqualTo(0)).then(Color.RED).otherwise(Color.BLUE));
Button fight = new Button("Fight!");
fight.setGraphic(new Icon(MaterialDesignIcon.POWER));
fight.setOnAction(e -> player.dealDamage());
fight.disableProperty().bind(player.healthProperty().lessThanOrEqualTo(0));
getApplication().addLayerFactory(LAYER_INVENTORY, () -> {
Label lblHealthPotions = new Label("", MaterialDesignIcon.HEALING.graphic());
lblHealthPotions.textProperty().bind(Bindings.concat("Health Potions: ", player.ownedHealthPotionsProperty()));
Button btnHealthPotions = new Button("consume");
btnHealthPotions.disableProperty().bind(player.ownedHealthPotionsProperty().lessThanOrEqualTo(0).or(player.healthProperty().isEqualTo(Player.MAX_HEALTH)));
btnHealthPotions.setOnAction(e -> player.consumeHealthPotion());
HBox.setHgrow(lblHealthPotions, Priority.ALWAYS);
HBox healthPotions = new HBox(10.0, lblHealthPotions, btnHealthPotions);
healthPotions.setAlignment(Pos.TOP_RIGHT);
Label lblWoodenShield = new Label("Wooden Shield", MaterialDesignIcon.LOCAL_BAR.graphic());
lblWoodenShield.textFillProperty().bind(Bindings.when(player.woodenShieldOwnedProperty()).then(Color.BLUEVIOLET).otherwise(Color.LIGHTGRAY));
HBox woodenShield = new HBox(10.0, lblWoodenShield);
woodenShield.setAlignment(Pos.CENTER_LEFT);
VBox inventory = new VBox(15.0, healthPotions, woodenShield);
inventory.setAlignment(Pos.CENTER_LEFT);
return new SidePopupView(inventory, Side.RIGHT, true);
});
setOnShowing(e -> {
Button btnInventory = MaterialDesignIcon.SHOPPING_BASKET.button(e2 -> {
getApplication().showLayer(LAYER_INVENTORY);
});
getApplication().getAppBar().getActionItems().add(btnInventory);
});
VBox controls = new VBox(15.0, lblHealth, fight);
controls.setAlignment(Pos.TOP_CENTER);
controls.setPadding(new Insets(15.0, 5.0, 0.0, 5.0));
setCenter(controls);
setBottom(items);
}
@Override
public Node getNode(
PageActionManager actionmanager,
CPageData inputdata,
Window parentwindow,
TabPane[] parenttabpanes,
CollapsibleNode nodetocollapsewhenactiontriggered) {
if (this.datareference != null) {
this.inputvalue = getExternalContent(inputdata, datareference);
}
FlowPane thispane = new FlowPane();
Label thislabel = new Label(label);
thislabel.setFont(Font.font(thislabel.getFont().getName(), FontPosture.ITALIC, thislabel.getFont().getSize()));
thislabel.setMinWidth(120);
thislabel.setWrapText(true);
thislabel.setMaxWidth(120);
thispane.setRowValignment(VPos.TOP);
thispane.getChildren().add(thislabel);
boolean readonly = false;
if (!this.isactive)
readonly = true;
if (!this.iseditable)
readonly = true;
// ---------------------------- ACTIVE FIELD
// ------------------------------------
if (!readonly) {
decimalfield = new TextField();
this.formatvalidator = new BigDecimalFormatValidator(precision, scale);
decimalfield.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldvalue, String newvalue) {
String valueafterformatting = formatvalidator.valid(newvalue);
if (valueafterformatting == null)
decimalfield.setText(oldvalue);
if (valueafterformatting != null)
decimalfield.setText(valueafterformatting);
}
});
if (this.inputvalue != null)
decimalfield.setText(formatfordecimal.format(inputvalue));
// if (this.inputvalue!=null) decimalfield.setText(formatfordecimal.format(new
// LockableBigDecimal(false,inputvalue)));
if (alternatefielddisplay == null) {
thispane.getChildren().add(this.decimalfield);
} else {
thispane.getChildren().add(alternatefielddisplay);
}
} else {
// ---------------------------- INACTIVE FIELD
// ------------------------------------
if (this.decimalformatter != null) {
alternatefielddisplay = this.decimalformatter.getWidget(new LockableBigDecimal(false, inputvalue));
thispane.getChildren().add(alternatefielddisplay);
} else {
thispane.getChildren()
.add(CTextField
.getReadOnlyTextArea(actionmanager,
(inputvalue != null ? formatfordecimal.format(inputvalue) : ""), precision + 2)
.getNode());
}
}
return thispane;
}
@Override
public Node getNode(
PageActionManager actionmanager,
CPageData inputdata,
Window parentwindow,
TabPane[] parenttabpanes,
CollapsibleNode nodetocollapsewhenactiontriggered) {
if (this.datareference != null) {
this.inputvalue = getExternalContent(inputdata, datareference);
}
FlowPane thispane = new FlowPane();
Label thislabel = new Label(label);
thislabel.setFont(Font.font(thislabel.getFont().getName(), FontPosture.ITALIC, thislabel.getFont().getSize()));
thislabel.setMinWidth(120);
thislabel.setWrapText(true);
thislabel.setMaxWidth(120);
thispane.setRowValignment(VPos.TOP);
thispane.getChildren().add(thislabel);
boolean readonly = false;
if (!this.isactive)
readonly = true;
if (!this.iseditable)
readonly = true;
// ---------------------------- ACTIVE FIELD
// ------------------------------------
if (!readonly) {
integerfield = new TextField();
integerfield.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldvalue, String newvalue) {
if (newvalue.length() > 0) {
try {
new Integer(newvalue);
} catch (NumberFormatException e) {
integerfield.setText(oldvalue);
}
} else {
integerfield.setText("0");
}
}
});
if (this.inputvalue != null)
integerfield.setText(inputvalue.toString());
thispane.getChildren().add(this.integerfield);
} else {
// ---------------------------- INACTIVE FIELD
// ------------------------------------
thispane.getChildren()
.add(CTextField
.getReadOnlyTextArea(actionmanager, (inputvalue != null ? inputvalue.toString() : ""), 15)
.getNode());
}
return thispane;
}
@Override
public void start(Stage stage) throws Exception {
loadData();
tree = new J48();
tree.buildClassifier(data);
noClassificationChart = buildChart("No Classification (click to add new data)", buildSingleSeries());
clusteredChart = buildChart("Clustered", buildClusteredSeries());
realDataChart = buildChart("Real Data (+ Decision Tree classification for new data)", buildLabeledSeries());
noClassificationChart.setOnMouseClicked(e -> {
Axis<Number> xAxis = noClassificationChart.getXAxis();
Axis<Number> yAxis = noClassificationChart.getYAxis();
Point2D mouseSceneCoords = new Point2D(e.getSceneX(), e.getSceneY());
double x = xAxis.sceneToLocal(mouseSceneCoords).getX();
double y = yAxis.sceneToLocal(mouseSceneCoords).getY();
Number xValue = xAxis.getValueForDisplay(x);
Number yValue = yAxis.getValueForDisplay(y);
reloadSeries(xValue, yValue);
});
Label lblDecisionTreeTitle = new Label("Decision Tree generated for the Iris dataset:");
Text txtTree = new Text(tree.toString());
String graph = tree.graph();
SwingNode sw = new SwingNode();
SwingUtilities.invokeLater(() -> {
TreeVisualizer treeVisualizer = new TreeVisualizer(null, graph, new PlaceNode2());
treeVisualizer.setPreferredSize(new Dimension(600, 500));
sw.setContent(treeVisualizer);
});
Button btnRestore = new Button("Restore original data");
Button btnSwapColors = new Button("Swap clustered chart colors");
StackPane spTree = new StackPane(sw);
spTree.setPrefWidth(300);
spTree.setPrefHeight(350);
VBox vbDecisionTree = new VBox(5, lblDecisionTreeTitle, new Separator(), spTree,
new HBox(10, btnRestore, btnSwapColors));
btnRestore.setOnAction(e -> {
loadData();
reloadSeries();
});
btnSwapColors.setOnAction(e -> swapClusteredChartSeriesColors());
lblDecisionTreeTitle.setTextFill(Color.DARKRED);
lblDecisionTreeTitle.setFont(Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, FontPosture.ITALIC, 16));
txtTree.setTranslateX(100);
txtTree.setFont(Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, FontPosture.ITALIC, 14));
txtTree.setLineSpacing(1);
txtTree.setTextAlignment(TextAlignment.LEFT);
vbDecisionTree.setTranslateY(20);
vbDecisionTree.setTranslateX(20);
GridPane gpRoot = new GridPane();
gpRoot.add(realDataChart, 0, 0);
gpRoot.add(clusteredChart, 1, 0);
gpRoot.add(noClassificationChart, 0, 1);
gpRoot.add(vbDecisionTree, 1, 1);
stage.setScene(new Scene(gpRoot));
stage.setTitle("Íris dataset clustering and visualization");
stage.show();
}
public ReplayStage (Session session, Path path, Preferences prefs, Screen screen)
{
this.prefs = prefs;
final Label label = session.getHeaderLabel ();
label.setFont (new Font ("Arial", 20));
label.setPadding (new Insets (10, 10, 10, 10)); // trbl
boolean showTelnet = prefs.getBoolean ("ShowTelnet", false);
boolean showExtended = prefs.getBoolean ("ShowExtended", false);
final HBox checkBoxes = new HBox ();
checkBoxes.setSpacing (15);
checkBoxes.setPadding (new Insets (10, 10, 10, 10)); // trbl
checkBoxes.getChildren ().addAll (showTelnetCB, show3270ECB);
SessionTable sessionTable = new SessionTable ();
CommandPane commandPane =
new CommandPane (sessionTable, CommandPane.ProcessInstruction.DoProcess);
// commandPane.setScreen (session.getScreen ());
commandPane.setScreen (screen);
setTitle ("Replay Commands - " + path.getFileName ());
ObservableList<SessionRecord> masterData = session.getDataRecords ();
FilteredList<SessionRecord> filteredData = new FilteredList<> (masterData, p -> true);
ChangeListener<? super Boolean> changeListener =
(observable, oldValue, newValue) -> change (sessionTable, filteredData);
showTelnetCB.selectedProperty ().addListener (changeListener);
show3270ECB.selectedProperty ().addListener (changeListener);
if (true) // this sucks - remove it when java works properly
{
showTelnetCB.setSelected (true); // must be a bug
show3270ECB.setSelected (true);
}
showTelnetCB.setSelected (showTelnet);
show3270ECB.setSelected (showExtended);
SortedList<SessionRecord> sortedData = new SortedList<> (filteredData);
sortedData.comparatorProperty ().bind (sessionTable.comparatorProperty ());
sessionTable.setItems (sortedData);
displayFirstScreen (session, sessionTable);
setOnCloseRequest (e -> Platform.exit ());
windowSaver = new WindowSaver (prefs, this, "Replay");
if (!windowSaver.restoreWindow ())
{
primaryScreenBounds = javafx.stage.Screen.getPrimary ().getVisualBounds ();
setX (800);
setY (primaryScreenBounds.getMinY ());
double height = primaryScreenBounds.getHeight ();
setHeight (Math.min (height, 1200));
}
BorderPane borderPane = new BorderPane ();
borderPane.setLeft (sessionTable); // fixed size
borderPane.setCenter (commandPane); // expands to fill window
borderPane.setTop (label);
borderPane.setBottom (checkBoxes);
Scene scene = new Scene (borderPane);
setScene (scene);
}