下面列出了javafx.scene.control.Label#setText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Refresh this cell.
*/
protected void refresh() {
final TextureLayer item = getItem();
if (item == null) return;
setIgnoreListeners(true);
try {
final FloatTextField scaleField = getScaleField();
scaleField.setValue(item.getScale());
final NamedChooseTextureControl normalTextureControl = getNormalTextureControl();
normalTextureControl.setTextureFile(item.getNormalFile());
final NamedChooseTextureControl diffuseTextureControl = getDiffuseTextureControl();
diffuseTextureControl.setTextureFile(item.getDiffuseFile());
final Label layerField = getLayerField();
layerField.setText(Messages.MODEL_PROPERTY_LAYER + " #" + (item.getLayer() + 1));
} finally {
setIgnoreListeners(false);
}
}
private void addDiskBox(Disk disk) {
try {
Parent parentDisk = FXMLLoader.load(getClass().getResource("/resources/views/models/DiskInfo.fxml"));
//Label lblName = (Label) parentDisk.lookup("#lblName");
Label lblTotalSpace = (Label) parentDisk.lookup("#lblTotalSpace");
PieChart pieData = (PieChart) parentDisk.lookup("#pieData");
pieData.setTitle(disk.getName());
lblTotalSpace.setText(Utils.humanReadableByteCount(disk.getTotalSpace()));
// Data of pie chart
ObservableList<PieChart.Data> data = FXCollections.observableArrayList();
data.add(new PieChart.Data("Usable", Utils.humanReadableByteCountNumber(disk.getUsableSpace())));
data.add(new PieChart.Data("Free", Utils.humanReadableByteCountNumber(disk.getFreeSpace())));
pieData.setData(data);
pieData.getData().forEach(d ->
d.nameProperty().bind(Bindings.concat(d.getName(), " ", d.pieValueProperty(), " GB"))
);
boxContainerDisks.getChildren().add(parentDisk);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
@Override
public Node getNode() {
// actual name for labels at the top, add tick for selected labels
Label label = new Label((canDisplayFullName ? getFullName() : getShortName()));
setLabelStyle(label);
label.setText(label.getText() + (!canDisplayFullName && isSelected ? " ✓" : ""));
FontLoader fontLoader = Toolkit.getToolkit().getFontLoader();
double width = fontLoader.computeStringWidth(label.getText(), label.getFont());
label.setPrefWidth(width + 30);
if (isInGroup()) {
Tooltip groupTooltip = new Tooltip(getGroupName());
label.setTooltip(groupTooltip);
}
setupEvents(label);
return label;
}
@Override
protected void updateItem(SocketGroup sg, boolean empty) {
super.updateItem(sg, empty) ;
if (empty) {
setText(null);
} else {
Label l = new Label();
if(sg.getActiveGem()!=null){
if(!sg.getActiveGem().getGemName().equals("<empty group>")){
l.setGraphic(new ImageView(sg.getActiveGem().getSmallIcon()));
l.setText(sg.getActiveGem().getGemName());
}
}
else{
setText(null);
}
setGraphic(l);
}
}
/**
* Reload.
*/
@FxThread
protected void reload() {
final ImageChannelPreview textureTooltip = getTextureTooltip();
final Label textureLabel = getTextureLabel();
final ImageView preview = getTexturePreview();
final Path textureFile = getTextureFile();
if (textureFile == null) {
textureLabel.setText(Messages.MATERIAL_MODEL_PROPERTY_CONTROL_NO_TEXTURE);
preview.setImage(null);
textureTooltip.clean();
return;
}
final Path assetFile = notNull(getAssetFile(textureFile));
textureLabel.setText(assetFile.toString());
preview.setImage(IMAGE_MANAGER.getImagePreview(textureFile, 28, 28));
textureTooltip.showImage(textureFile);
}
private static VBox createContent(String title, String message){
VBox container = new VBox();
container.setAlignment(Pos.TOP_CENTER);
container.setSpacing(20D);
VBox.setMargin(container, new Insets(10,0,0,0));
Label lblTitle = new Label(title);
lblTitle.getStyleClass().add("h2");
Label text = new Label();
text.setWrapText(true);
text.setText(message);
text.setMaxWidth(420);
text.setAlignment(Pos.CENTER);
text.setStyle("-fx-text-fill : -text-color; ");
container.getChildren().addAll(lblTitle, text);
return container;
}
public Node getNode() {
Label repoLabel = new Label();
repoLabel.setPrefWidth(REPO_LABEL_PREFERRED_WIDTH);
repoLabel.setPadding(DEFAULT_REPO_LABEL_PADDING);
if (isSelected) {
repoLabel.setText(repositoryId);
repoLabel.setStyle(COMMON_REPO_LABEL_STYLE + SELECTED_REPO_LABEL_STYLE);
} else {
repoLabel.setText(repositoryId);
repoLabel.setStyle(COMMON_REPO_LABEL_STYLE + DEFAULT_REPO_LABEL_STYLE);
}
return repoLabel;
}
private void createContent() {
HBox slidingContentWithPagingBox = new HBox();
slidingContentWithPagingBox.setPadding(new Insets(30, 0, 0, 0));
slidingContentWithPagingBox.setAlignment(Pos.CENTER);
Button prevButton = getIconButton(MaterialDesignIcon.ARROW_LEFT, "dao-launch-paging-button");
prevButton.setOnAction(event -> {
autoPlayTimeline.stop();
goToPrevSection();
});
Button nextButton = getIconButton(MaterialDesignIcon.ARROW_RIGHT, "dao-launch-paging-button");
nextButton.setOnAction(event -> {
autoPlayTimeline.stop();
goToNextSection();
});
VBox slidingContent = new VBox();
slidingContent.setMinWidth(616);
slidingContent.setSpacing(20);
sectionDescriptionLabel = new Label();
sectionDescriptionLabel.setTextAlignment(TextAlignment.CENTER);
sectionDescriptionLabel.getStyleClass().add("dao-launch-description");
sectionDescriptionLabel.setMaxWidth(562);
sectionDescriptionLabel.setWrapText(true);
selectedSection = sections.get(currentSectionIndex.get());
sectionDescriptionLabel.setText(selectedSection.description);
sectionScreenshot = new ImageView();
sectionScreenshot.setOpacity(0);
sectionScreenshot.setId(selectedSection.imageId);
slidingContent.setAlignment(Pos.CENTER);
slidingContent.getChildren().addAll(sectionDescriptionLabel, sectionScreenshot);
slidingContentWithPagingBox.getChildren().addAll(prevButton, slidingContent, nextButton);
GridPane.setRowIndex(slidingContentWithPagingBox, ++rowIndex);
GridPane.setColumnSpan(slidingContentWithPagingBox, 2);
GridPane.setHgrow(slidingContent, Priority.ALWAYS);
gridPane.getChildren().add(slidingContentWithPagingBox);
}
public boolean display(final String title, final String message) {
final Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
window.setMinWidth(250);
window.setMinHeight(150);
window.getIcons().add(new Image(getClass().getResourceAsStream("Smart_parking_icon.png")));
final Label label = new Label();
label.setText(message);
yesButton = new Button("Yes");
yesButton.setOnAction(λ -> {
answer = true;
window.close();
});
noButton = new Button("No");
noButton.setOnAction(λ -> {
answer = false;
window.close();
});
final VBox layout = new VBox();
layout.getChildren().addAll(label, noButton, yesButton);
layout.setAlignment(Pos.CENTER);
final Scene scene = new Scene(layout);
scene.getStylesheets().add(getClass().getResource("mainStyle.css").toExternalForm());
window.setScene(scene);
window.showAndWait();
return answer;
}
private void updateMarketPriceLabel(Label label) {
if (model.getIsPriceAvailable().get()) {
if (model.getIsExternallyProvidedPrice().get()) {
label.setText(Res.get("mainView.marketPriceWithProvider.label", getPriceProvider()));
label.setTooltip(new Tooltip(getPriceProviderTooltipString()));
} else {
label.setText(Res.get("mainView.marketPrice.bisqInternalPrice"));
final Tooltip tooltip = new Tooltip(Res.get("mainView.marketPrice.tooltip.bisqInternalPrice"));
label.setTooltip(tooltip);
}
} else {
label.setText("");
label.setTooltip(null);
}
}
public void generateLabel(){
sgLabel = new Label();
if(sg == null){
sg = new SocketGroup(); //creating dummie
}
if(sg.getActiveGem()!=null){
Image img = sg.getActiveGem().getSmallIcon();
sgLabel.setGraphic(new ImageView(img));
sgLabel.setText(sg.getActiveGem().getGemName());
}else{
sgLabel.setText("<empty group>");
}
}
public static Callback<ListView<PaymentMethod>, ListCell<PaymentMethod>> getPaymentMethodCellFactory() {
return p -> new ListCell<>() {
@Override
protected void updateItem(PaymentMethod method, boolean empty) {
super.updateItem(method, empty);
if (method != null && !empty) {
String id = method.getId();
HBox box = new HBox();
box.setSpacing(20);
Label paymentType = new AutoTooltipLabel(
method.isAsset() ? Res.get("shared.crypto") : Res.get("shared.fiat"));
paymentType.getStyleClass().add("currency-label-small");
Label paymentMethod = new AutoTooltipLabel(Res.get(id));
paymentMethod.getStyleClass().add("currency-label");
box.getChildren().addAll(paymentType, paymentMethod);
if (id.equals(GUIUtil.SHOW_ALL_FLAG)) {
paymentType.setText(Res.get("shared.all"));
paymentMethod.setText(Res.get("list.currency.showAll"));
}
setGraphic(box);
} else {
setGraphic(null);
}
}
};
}
/** Limit the number of alarms
* @param alarms List of alarms, may be trimmed
* @param alarm_count Label where count will be shown
* @param message Message to use for the count
*/
private void limitAlarmCount(final List<AlarmInfoRow> alarms,
final Label alarm_count, final String message)
{
final int N = alarms.size();
final StringBuilder buf = new StringBuilder();
buf.append(message).append(N);
if (N > AlarmSystem.alarm_table_max_rows)
{
buf.append(" (").append(N - AlarmSystem.alarm_table_max_rows).append(" not shown)");
alarms.subList(AlarmSystem.alarm_table_max_rows, N).clear();
}
alarm_count.setText(buf.toString());
}
/**
* Create the container for displaying a series cover, for use in FlowPane layouts where covers
* are shown in a somewhat grid-like fashion.
*
* @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
* @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) {
StackPane result_pane = new StackPane();
result_pane.setAlignment(Pos.BOTTOM_LEFT);
// create the label for showing the series title
Label label = new Label();
label.setText(title);
label.getStyleClass().add("coverLabel");
label.setWrapText(true);
// We create a new ImageView for the cell instead of using the result's cover ImageView
// since we may not want to mess with the sizing of the result's cover -- particularly if we
// want to have additional result layouts.
ImageView image_view = new ImageView();
applyCoverSizing(image_view);
image_view.fitWidthProperty().bind(result_pane.prefWidthProperty());
image_view.imageProperty().bind(cover.imageProperty());
image_view.setEffect(COVER_ADJUST_DEFAULT);
image_view.getStyleClass().add("coverImage");
// create the mouse event handlers for the result pane
result_pane.setOnMouseEntered(t -> {
image_view.setEffect(COVER_ADJUST_HOVER);
setChildButtonVisible(result_pane, true);
});
result_pane.setOnMouseExited(t -> {
image_view.setEffect(COVER_ADJUST_DEFAULT);
setChildButtonVisible(result_pane, false);
});
result_pane.getChildren().addAll(image_view, label);
return result_pane;
}
public Label createLabelRight(String tip) {
Label l = new Label();
l.setAlignment(Pos.CENTER);
// upTimeLabel.setEffect(blend);
l.setStyle(LABEL_CSS_STYLE);
l.setPadding(new Insets(1, 1, 1, 2));
if (uptimer != null)
l.setText(uptimer.getUptime());
setQuickToolTip(l, tip);
return l;
}
@Override
public void start(Stage primaryStage) {
try {
Group root = new Group();
Scene scene = new Scene(root, 400, 400);
Pane p = new Pane();
p.setPrefSize(400, 400);
p.setBackground(new Background(new BackgroundFill(Color.GOLD,
null, null)));
root.getChildren().add(p);
primaryStage.setScene(scene);
primaryStage.setTitle("Conversation about Bubbles with Elltz");
primaryStage.show();
Label bl1 = new Label();
bl1.relocate(10, 50);
bl1.setText("Hi Elltz -:)");
bl1.setBackground(new Background(new BackgroundFill(Color.YELLOWGREEN,
null, null)));
Label bl2 = new Label();
bl2.relocate(310, 100);
bl2.setText("Heloooo Me");
bl2.setBackground(new Background(new BackgroundFill(Color.GREENYELLOW,
null, null)));
Label bl3 = new Label();
bl3.relocate(10, 150);
bl3.setText("you know this would be a nice library");
bl3.setBackground(new Background(new BackgroundFill(Color.YELLOWGREEN,
null, null)));
Label bl4 = new Label();
bl4.relocate(165, 200);
bl4.setText("uhmm yea, kinda, but yknow,im tryna \nact like im not impressed");
bl4.setBackground(new Background(new BackgroundFill(Color.GREENYELLOW,
null, null)));
Label bl5 = new Label();
bl5.relocate(10, 250);
bl5.setText("yea! yea! i see that, lowkey.. you not gonna\n get upvotes though..lmao");
bl5.setBackground(new Background(new BackgroundFill(Color.YELLOWGREEN,
null, null)));
Label bl6 = new Label();
bl6.relocate(165, 300);
bl6.setText("Man! shut up!!.. what you know about\n upvotes.");
bl6.setBackground(new Background(new BackgroundFill(Color.GREENYELLOW,
null, null)));
p.getChildren().addAll(bl1, bl2, bl3, bl4, bl5, bl6);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Callback<ListView<TradeCurrency>, ListCell<TradeCurrency>> getTradeCurrencyCellFactory(String postFixSingle,
String postFixMulti,
Map<String, Integer> offerCounts) {
return p -> new ListCell<>() {
@Override
protected void updateItem(TradeCurrency item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
String code = item.getCode();
HBox box = new HBox();
box.setSpacing(20);
Label currencyType = new AutoTooltipLabel(
CurrencyUtil.isFiatCurrency(item.getCode()) ? Res.get("shared.fiat") : Res.get("shared.crypto"));
currencyType.getStyleClass().add("currency-label-small");
Label currency = new AutoTooltipLabel(item.getCode());
currency.getStyleClass().add("currency-label");
Label offers = new AutoTooltipLabel(item.getName());
offers.getStyleClass().add("currency-label");
box.getChildren().addAll(currencyType, currency, offers);
Optional<Integer> offerCountOptional = Optional.ofNullable(offerCounts.get(code));
switch (code) {
case GUIUtil.SHOW_ALL_FLAG:
currencyType.setText(Res.get("shared.all"));
currency.setText(Res.get("list.currency.showAll"));
break;
case GUIUtil.EDIT_FLAG:
currencyType.setText(Res.get("shared.edit"));
currency.setText(Res.get("list.currency.editList"));
break;
default:
offerCountOptional.ifPresent(numOffer -> offers.setText(offers.getText() + " (" + numOffer + " " +
(numOffer == 1 ? postFixSingle : postFixMulti) + ")"));
}
setGraphic(box);
} else {
setGraphic(null);
}
}
};
}
private void drawCells() {
List<ChartData> dataList = tile.getChartData();
ZonedDateTime time = tile.getTime();
Locale locale = tile.getLocale();
int day = time.getDayOfMonth();
int startDay = time.withDayOfMonth(1).getDayOfWeek().getValue();
long lastDay = time.range(DAY_OF_MONTH).getMaximum();
Color textColor = tile.getTextColor();
Color bkgColor = tile.getBackgroundColor();
Font regFont = Fonts.latoRegular(size * 0.045);
Font bldFont = Fonts.latoBold(size * 0.045);
Background bkgToday = new Background(new BackgroundFill(tile.getBarColor(), new CornerRadii(size * 0.0125), new Insets(2)));
Border appmntBorder = new Border(new BorderStroke(tile.getAlarmColor(),
tile.getAlarmColor(),
tile.getAlarmColor(),
tile.getAlarmColor(),
BorderStrokeStyle.SOLID,
BorderStrokeStyle.SOLID,
BorderStrokeStyle.SOLID,
BorderStrokeStyle.SOLID,
new CornerRadii(size * 0.0125), BorderWidths.DEFAULT,
new Insets(1)));
boolean counting = false;
int dayCounter = 1;
for (int y = 0 ; y < 7 ; y++) {
for (int x = 0 ; x < 8 ; x++) {
int index = y * 8 + x;
Label label = labels.get(index);
String text;
if (x == 0 && y == 0) {
text = "";
label.setManaged(false);
label.setVisible(false);
} else if (y == 0) {
text = DayOfWeek.of(x).getDisplayName(TextStyle.SHORT, locale);
//label.setTextFill(x == 7 ? Tile.RED : textColor);
label.setTextFill(textColor);
label.setFont(bldFont);
} else if (x == 0) {
text = Integer.toString(time.withDayOfMonth(1).plusDays((y - 1) * 7).get(IsoFields.WEEK_OF_WEEK_BASED_YEAR));
label.setTextFill(Tile.GRAY);
label.setFont(regFont);
label.setBorder(weekBorder);
} else {
if (index - 7 > startDay) {
counting = true;
text = Integer.toString(dayCounter);
LocalDate currentDay = time.toLocalDate().plusDays(dayCounter - 1);
long appointments = dataList.stream().filter(data -> data.getTimestampAsLocalDate().isEqual(currentDay)).count();
if (x == 7) {
if (appointments > 0) { label.setBorder(appmntBorder); } else { label.setBorder(null); }
label.setTextFill(Tile.RED);
label.setFont(regFont);
} else if (dayCounter == day) {
if (appointments > 0) { label.setBorder(appmntBorder); } else { label.setBorder(null); }
label.setBackground(bkgToday);
label.setTextFill(bkgColor);
label.setFont(bldFont);
} else {
if (appointments > 0) { label.setBorder(appmntBorder); } else { label.setBorder(null); }
label.setTextFill(textColor);
label.setFont(regFont);
}
} else {
text = "";
label.setManaged(false);
label.setVisible(false);
}
if (dayCounter > lastDay) {
text = "";
label.setManaged(false);
label.setVisible(false);
}
if (counting) { dayCounter++; }
}
label.setText(text);
label.setVisible(true);
label.setManaged(true);
label.setPrefSize(cellWidth, cellHeight);
label.relocate(x * cellWidth + cellOffsetX, y * cellHeight + cellOffsetY);
}
}
}
private static Node getTextNodeContent(String content) {
Label l = new Label();
l.setText(content);
l.setWrapText(true);
return l;
}
/**
* A simple method for printing text to a terminal.
*
* @param termArea The Label to print to.
*
* @param text The String to print.
*/
public static void printText(Label termArea, String text) {
termArea.setText(String.format("%s%n%s", termArea.getText(), text));
}