下面列出了javafx.scene.control.Label#setWrapText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Creates the pause box to be displayed on the root pane.
*
* @return VBox
*/
private VBox createPausePaneContent() {
VBox vbox = new VBox();
vbox.setPrefSize(150, 150);
Label label = new Label("||");
label.setAlignment(Pos.CENTER);
label.setPadding(new Insets(10));
label.setStyle("-fx-font-size: 48px; -fx-text-fill: cyan;");
// label.setMaxWidth(250);
label.setWrapText(true);
Label label1 = new Label("ESC to resume");
label1.setAlignment(Pos.CENTER);
label1.setPadding(new Insets(2));
label1.setStyle(" -fx-font: bold 11pt 'Corbel'; -fx-text-fill: cyan;");
vbox.getChildren().addAll(label, label1);
vbox.setAlignment(Pos.CENTER);
return vbox;
}
@Override
public final LabelDescriptionBox buildParameterLabel(final PluginParameter<?> parameter) {
final Label label = new Label(parameter.getName() + ":");
final Label description = new Label(parameter.getDescription());
label.setMinWidth(120);
label.setPrefWidth(200);
label.setMaxWidth(400);
label.setWrapText(true);
description.setStyle("-fx-font-size: 80%;");
description.getStyleClass().add("description-label");
description.setMinWidth(120);
description.setPrefWidth(200);
description.setMaxWidth(400);
description.setWrapText(true);
final LabelDescriptionBox labels = new LabelDescriptionBox(label, description);
labels.setStyle("-fx-padding: " + PADDING);
labels.setVisible(parameter.isVisible());
labels.setManaged(parameter.isVisible());
parameter.setVisible(parameter.isVisible());
linkParameterLabelToTop(parameter, labels);
return labels;
}
/**
* Create the container for displaying a series cover, for use in FlowPane layouts where covers
* are shown in a somewhat grid-like fashion. However this includes a count of the amount of
* chapters that have been marked as read. The count is displayed in the top right corner.
*
* @param container the parent FlowPane container
* @param title the title of the series being represented
* @param cover the cover of the series being represented; this ImageView is not
* modified, a copy is made to be used in the new container
* @param numUnreadChapters the amount of Chapters that have been marked as unread
* @return a StackPane which displays the provided title and cover and can be added to the
* FlowPane
*/
public static StackPane createCoverContainer(FlowPane container, String title, ImageView cover,
int numUnreadChapters) {
String amountOfReadChapters = String.valueOf(numUnreadChapters);
// create the label for showing the amount of chapters marked as read
Label label = new Label();
label.setText(amountOfReadChapters);
label.getStyleClass().add("coverLabel");
label.setWrapText(true);
// this label will be situated in the top right as the title is located in the bottom left
StackPane.setAlignment(label, Pos.TOP_RIGHT);
// We call the other createCoverContainer method to provide a filled stackpane with the
// title and cover
StackPane pane = createCoverContainer(container, title, cover);
pane.getChildren().add(label);
return pane;
}
public JFXDefaultChip(JFXChipView<T> view, T item) {
super(view, item);
JFXButton closeButton = new JFXButton(null, new SVGGlyph());
closeButton.getStyleClass().add("close-button");
closeButton.setOnAction((event) -> view.getChips().remove(item));
String tagString = null;
if (getItem() instanceof String) {
tagString = (String) getItem();
} else {
tagString = view.getConverter().toString(getItem());
}
Label label = new Label(tagString);
label.setWrapText(true);
root = new HBox(label, closeButton);
getChildren().setAll(root);
label.setMaxWidth(100);
}
public SimpleObjectProperty<Node>getDBSNode(){
String dbs[] = this.getDBS();
VBox vBox = new VBox();
String dbsWords="";
Label label = new Label();
label.setMaxWidth(180);
label.setWrapText(true);
for(String S:dbs)
{
dbsWords+=S+" \n";
}
label.setText(dbsWords);
vBox.getChildren().add(label);
return new SimpleObjectProperty<>(label);
}
public HistoryListItemNode(@NotNull HistoryListItem item) {
super(5);
final VBox vboxTitle = new VBox(5);
final Label lblTitle = new Label(item.getItemTitle());
lblTitle.setFont(Font.font(15));
vboxTitle.getChildren().add(lblTitle);
Font subInfoLabelFont = Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 10);
Font subInfoTextFont = Font.font(subInfoLabelFont.getSize());
for (HistoryListItemSubInfo subInfo : item.getSubInfo()) {
final Label lbl = new Label(subInfo.getLabel());
lbl.setFont(subInfoLabelFont);
final Label lblInfo = new Label(subInfo.getInfo());
lblInfo.setFont(subInfoTextFont);
vboxTitle.getChildren().add(new HBox(5, lbl, lblInfo));
}
getChildren().add(vboxTitle);
final Label lblMainInfo = new Label(item.getInformation());
lblMainInfo.setWrapText(true);
getChildren().add(lblMainInfo);
}
private void addMsg(String msg, boolean senderIsRobot) {
Label lbl = new Label(msg);
lbl.setStyle("-fx-font-size: 16px;"
+ "-fx-background-color: #" + ((senderIsRobot) ? "B00020" : "2196f3") + ";"
+ "-fx-text-fill: #FFF;"
+ "-fx-background-radius:25;"
+ "-fx-padding: 10px;");
lbl.setWrapText(true);
lbl.setMaxWidth(400);
HBox container = new HBox();
container.setPrefHeight(40);
container.setAlignment(Pos.CENTER_LEFT);
container.setPadding(new Insets(0, 10, 0, 10));
container.setSpacing(10);
container.getChildren().add(lbl);
msgNodes.getItems().add(container);
}
@Override protected void initGraphics() {
super.initGraphics();
final ZonedDateTime TIME = tile.getTime();
titleText = new Text(DAY_FORMATTER.format(TIME));
titleText.setFill(tile.getTitleColor());
description = new Label(Integer.toString(TIME.getDayOfMonth()));
description.setAlignment(Pos.CENTER);
description.setTextAlignment(TextAlignment.CENTER);
description.setWrapText(true);
description.setTextOverrun(OverrunStyle.WORD_ELLIPSIS);
description.setTextFill(tile.getTextColor());
description.setPrefSize(PREFERRED_WIDTH * 0.9, PREFERRED_HEIGHT * 0.72);
description.setFont(Fonts.latoLight(PREFERRED_HEIGHT * 0.65));
text = new Text(MONTH_YEAR_FORMATTER.format(TIME));
text.setFill(tile.getTextColor());
getPane().getChildren().addAll(titleText, text, description);
}
public static void create_Popup_Window(String windowTitle, String message, Integer width, Integer height) {
//Create a new window
WindowBuilder window = new WindowBuilder(windowTitle);
window.setProcessName("popup.app");
window.setPrefSize(width, height);
Label messageArea = new Label(message);
try {
messageArea.setFont(Desktop.loadFont(Desktop.desktopFont, Desktop.desktopFontSize));
} catch (NullPointerException e) {}
messageArea.setWrapText(true);
messageArea.setStyle(Apps.windowFontColor);
window.setCenter(messageArea);
//Spawn the window
window.spawnWindow();
window.placeApp();
}
public void extendReport(final String extensionTitle, final String extensionContent) {
final HBox spacerReportBox = new HBox();
final Label spacerLabel = new Label("\n");
spacerReportBox.getChildren().add(spacerLabel);
final HBox extensionReportBox = new HBox();
final Label extensionLabel = new Label(String.format("%s: ", extensionTitle));
extensionLabel.setStyle(JavafxStyleManager.CSS_FONT_WEIGHT_BOLD);
final Label extensionValue = new Label(extensionContent);
extensionValue.setWrapText(true);
extensionReportBox.getChildren().addAll(extensionLabel, extensionValue);
report.getChildren().addAll(spacerReportBox, extensionReportBox);
}
private Label createMarketAlertPriceInfoPopupLabel(String text) {
final Label label = new Label(text);
label.setPrefWidth(300);
label.setWrapText(true);
label.setPadding(new Insets(10));
return label;
}
@Override protected void initGraphics() {
super.initGraphics();
titleText = new Text();
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
text = new Text(tile.getText());
text.setFill(tile.getUnitColor());
Helper.enableNode(text, tile.isTextVisible());
valueText = new Text(String.format(locale, formatString, ((tile.getValue() - minValue) / range * 100)));
valueText.setFill(tile.getValueColor());
valueText.setTextOrigin(VPos.BASELINE);
Helper.enableNode(valueText, tile.isValueVisible());
unitText = new Text(" " + tile.getUnit());
unitText.setFill(tile.getUnitColor());
unitText.setTextOrigin(VPos.BASELINE);
Helper.enableNode(unitText, !tile.getUnit().isEmpty());
valueUnitFlow = new TextFlow(valueText, unitText);
valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);
description = new Label(tile.getText());
description.setAlignment(tile.getDescriptionAlignment());
description.setWrapText(true);
description.setTextFill(tile.getTextColor());
Helper.enableNode(description, tile.isTextVisible());
getPane().getChildren().addAll(titleText, text, valueUnitFlow, description);
}
/** @return the content of the address, with a signature and portrait attached. */
private Pane getContent() {
final VBox content = new VBox();
content.getStyleClass().add("address");
//int rand = RandomUtil.getRandomInt(1);
final Label address = new Label(START1+START2+MID1+MID2+MID3+MID4);
address.setWrapText(true);
ScrollPane addressScroll = makeScrollable(address);
final ImageView signature = new ImageView(); signature.setId("signature");
final ImageView lincolnImage = new ImageView(); lincolnImage.setId("portrait");
VBox.setVgrow(addressScroll, Priority.ALWAYS);
final Region spring = new Region();
HBox.setHgrow(spring, Priority.ALWAYS);
//final Node alignedSignature = HBoxBuilder.create().children(spring, signature).build();
final HBox alignedSignature = new HBox(spring, signature);
Label date = new Label(DATE);
date.setAlignment(Pos.BOTTOM_RIGHT);
content.getChildren().addAll(
lincolnImage,
addressScroll,
alignedSignature,
date
);
return content;
}
private void addContent() {
TableView<MarketAlertFilter> tableView = new TableView<>();
GridPane.setRowIndex(tableView, ++rowIndex);
GridPane.setColumnSpan(tableView, 2);
GridPane.setMargin(tableView, new Insets(10, 0, 0, 0));
gridPane.getChildren().add(tableView);
Label placeholder = new AutoTooltipLabel(Res.get("table.placeholder.noData"));
placeholder.setWrapText(true);
tableView.setPlaceholder(placeholder);
tableView.setPrefHeight(300);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
setColumns(tableView);
tableView.setItems(FXCollections.observableArrayList(marketAlerts.getMarketAlertFilters()));
}
/**
* Adds the wine architecture information of the container to the {@link GridPane overviewGrid}
*
* @param overviewGrid The grid containing the overview information
*/
private void addArchitecture(final GridPane overviewGrid) {
final int row = overviewGrid.getRowCount();
final Text architectureDescription = new Text(tr("Wine architecture:"));
architectureDescription.getStyleClass().add("captionTitle");
final Label architectureOutput = new Label();
architectureOutput.textProperty()
.bind(StringBindings.map(getControl().containerProperty(), WinePrefixContainerDTO::getArchitecture));
architectureOutput.setWrapText(true);
overviewGrid.addRow(row, architectureDescription, architectureOutput);
}
private GridPane createSpatialGridPane() {
GridPane gp = new GridPane();
gp.setHgap(10.00);
gp.setVgap(10.00);
int j = 0, k = 1;
Collection<? extends ReferenceSystem> referenceSystemInfos = metadata.getReferenceSystemInfo();
if (!referenceSystemInfos.isEmpty()) {
ReferenceSystem referenceSystemInfo = referenceSystemInfos.iterator().next();
Label rsiValue = new Label("Reference system infos: " + referenceSystemInfo.getName().toString());
rsiValue.setWrapText(true);
gp.add(rsiValue, j, k++);
}
Collection<? extends SpatialRepresentation> sris = this.metadata.getSpatialRepresentationInfo();
if (sris.isEmpty()) {
return gp;
}
NumberFormat numberFormat = NumberFormat.getIntegerInstance(locale);
for (SpatialRepresentation sri : sris) {
String currentValue = "• ";
if (sri instanceof DefaultGridSpatialRepresentation) {
DefaultGridSpatialRepresentation sr = (DefaultGridSpatialRepresentation) sri;
Iterator<? extends Dimension> it = sr.getAxisDimensionProperties().iterator();
while (it.hasNext()) {
Dimension dim = it.next();
currentValue += numberFormat.format(dim.getDimensionSize()) + " " + Types.getCodeTitle(dim.getDimensionName()) + " * ";
}
currentValue = currentValue.substring(0, currentValue.length() - 3);
Label spRep = new Label(currentValue);
gp.add(spRep, j, k++, 2, 1);
if (sr.getCellGeometry() != null) {
Label cellGeo = new Label("Cell geometry:");
Label cellGeoValue = new Label(Types.getCodeTitle(sr.getCellGeometry()).toString());
cellGeoValue.setWrapText(true);
gp.add(cellGeo, j, k);
gp.add(cellGeoValue, ++j, k++);
j = 0;
}
}
}
return gp;
}
@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);
}
@Override
public void start(Stage primaryStage) {
InlineCssTextArea area = new InlineCssTextArea();
InputMap<Event> preventSelectionOrRightArrowNavigation = InputMap.consume(
anyOf(
// prevent selection via (CTRL + ) SHIFT + [LEFT, UP, DOWN]
keyPressed(LEFT, SHIFT_DOWN, SHORTCUT_ANY),
keyPressed(KP_LEFT, SHIFT_DOWN, SHORTCUT_ANY),
keyPressed(UP, SHIFT_DOWN, SHORTCUT_ANY),
keyPressed(KP_UP, SHIFT_DOWN, SHORTCUT_ANY),
keyPressed(DOWN, SHIFT_DOWN, SHORTCUT_ANY),
keyPressed(KP_DOWN, SHIFT_DOWN, SHORTCUT_ANY),
// prevent selection via mouse events
eventType(MouseEvent.MOUSE_DRAGGED),
eventType(MouseEvent.DRAG_DETECTED),
mousePressed().unless(e -> e.getClickCount() == 1 && !e.isShiftDown()),
// prevent any right arrow movement, regardless of modifiers
keyPressed(RIGHT, SHORTCUT_ANY, SHIFT_ANY),
keyPressed(KP_RIGHT, SHORTCUT_ANY, SHIFT_ANY)
)
);
Nodes.addInputMap(area, preventSelectionOrRightArrowNavigation);
area.replaceText(String.join("\n",
"You can't move the caret to the right via the RIGHT arrow key in this area.",
"Additionally, you cannot select anything either",
"",
":-p"
));
area.moveTo(0);
CheckBox addExtraEnterHandlerCheckBox = new CheckBox("Temporarily add an EventHandler to area's `onKeyPressedProperty`?");
addExtraEnterHandlerCheckBox.setStyle("-fx-font-weight: bold;");
Label checkBoxExplanation = new Label(String.join("\n",
"The added handler will insert a newline character at the caret's position when [Enter] is pressed.",
"If checked, the default behavior and added handler will both occur: ",
"\tthus, two newline characters should be inserted when user presses [Enter].",
"When unchecked, the handler will be removed."
));
checkBoxExplanation.setWrapText(true);
EventHandler<KeyEvent> insertNewlineChar = e -> {
if (e.getCode().equals(ENTER)) {
area.insertText(area.getCaretPosition(), "\n");
e.consume();
}
};
addExtraEnterHandlerCheckBox.selectedProperty().addListener(
(obs, ov, isSelected) -> area.setOnKeyPressed( isSelected ? insertNewlineChar : null)
);
VBox vbox = new VBox(area, addExtraEnterHandlerCheckBox, checkBoxExplanation);
vbox.setSpacing(10);
vbox.setPadding(new Insets(10));
primaryStage.setScene(new Scene(vbox, 700, 350));
primaryStage.show();
primaryStage.setTitle("An area whose behavior has been overridden permanently and temporarily!");
}
public HTMLEditorSample() {
VBox vRoot = new VBox();
vRoot.setPadding(new Insets(8, 8, 8, 8));
vRoot.setSpacing(5);
htmlEditor = new HTMLEditor();
htmlEditor.setPrefSize(500, 245);
htmlEditor.setHtmlText(INITIAL_TEXT);
vRoot.getChildren().add(htmlEditor);
final Label htmlLabel = new Label();
htmlLabel.setMaxWidth(500);
htmlLabel.setWrapText(true);
ScrollPane scrollPane = new ScrollPane();
scrollPane.getStyleClass().add("noborder-scroll-pane");
scrollPane.setContent(htmlLabel);
scrollPane.setFitToWidth(true);
scrollPane.setPrefHeight(180);
Button showHTMLButton = new Button("Show the HTML below");
vRoot.setAlignment(Pos.CENTER);
showHTMLButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
htmlLabel.setText(htmlEditor.getHtmlText());
}
});
vRoot.getChildren().addAll(showHTMLButton, scrollPane);
getChildren().addAll(vRoot);
// REMOVE ME
// Workaround for RT-16781 - HTML editor in full screen has wrong border
javafx.scene.layout.GridPane grid = (javafx.scene.layout.GridPane)htmlEditor.lookup(".html-editor");
for(javafx.scene.Node child: grid.getChildren()) {
javafx.scene.layout.GridPane.setHgrow(child, javafx.scene.layout.Priority.ALWAYS);
}
// END REMOVE ME
}
protected static Label createValueLabel() {
Label ret = new Label();
ret.getStyleClass().add("info-property-value");
ret.setWrapText(true);
return ret;
}