下面列出了javafx.scene.control.Label#setContentDisplay ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public BasicMacroItemCategory() {
final double height = 100;
VBox vb = new VBox(10);
categoryNode = vb;
ResourceBundle bundle = Lang.ApplicationBundle();
taComment.setPrefHeight(height);
taComment.setEditable(false);
Label lblComment = new Label(bundle.getString("Macros.comment"), taComment);
lblComment.setContentDisplay(ContentDisplay.BOTTOM);
taValue.setEditable(false);
taValue.setPrefHeight(height);
Label lblValue = new Label(bundle.getString("Macros.value"), taValue);
lblValue.setContentDisplay(ContentDisplay.BOTTOM);
lblMacroPropertyType = new Label(String.format(bundle.getString("Popups.ChooseMacro.property_type"), "?"));
vb.getChildren().addAll(lblValue, lblComment, lblMacroPropertyType);
}
public void setToolbarButton(EventHandler<ActionEvent> backevent, Node graphic, String text) {
Label l = new Label();
l.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
l.setAlignment(Pos.CENTER);
l.setGraphic(graphic);
l.setPrefSize(45.0, 40.0);
backbutton = new Button(text, l);
backbutton.setAlignment(Pos.BASELINE_LEFT);
backbutton.setMaxWidth(Double.MAX_VALUE);
backbutton.setFocusTraversable(false);
backbutton.setMnemonicParsing(false);
backbutton.getStyleClass().add("menubutton");
backbutton.setOnAction(backevent);
backbutton.setVisible(backevent != null);
}
public StackPaneSample() {
StackPane stackPane = new StackPane();
Rectangle rectangle = new Rectangle(280, 70, Color.BISQUE);
rectangle.setStroke(Color.BLACK);
ImageView imageView = new ImageView(ICON_48);
Label label = new Label("Your name could be here.", imageView);
label.setContentDisplay(ContentDisplay.RIGHT);
stackPane.getChildren().addAll(rectangle, label);
getChildren().add(stackPane);
}
public StackPaneSample() {
StackPane stackPane = new StackPane();
Rectangle rectangle = new Rectangle(280, 70, Color.BISQUE);
rectangle.setStroke(Color.BLACK);
ImageView imageView = new ImageView(ICON_48);
Label label = new Label("Your name could be here.", imageView);
label.setContentDisplay(ContentDisplay.RIGHT);
stackPane.getChildren().addAll(rectangle, label);
getChildren().add(stackPane);
}
public MaterialMenuItem() {
label = new Label();
label.setPrefWidth(180);
label.setPadding(new Insets(0, 0, 0, 5));
label.setContentDisplay(ContentDisplay.RIGHT);
label.setGraphicTextGap(0);
setGraphic(label);
}
@Override
protected Node constructContent() {
content = new Label(null);
content.setContentDisplay(ContentDisplay.TOP);
content.setAlignment(Pos.CENTER);
content.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
VBox.setVgrow(content, Priority.SOMETIMES);
return content;
}
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Set combo box properties
cbo.getItems().addAll("SINGLE", "MULTIPLE");
cbo.setValue("SINGLE");
// Create a label and set its content display
Label lblSelectionMode = new Label("Choose Selection Mode:", cbo);
lblSelectionMode.setContentDisplay(ContentDisplay.RIGHT);
// Set defaut list view as single
lv.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
// Create and register the handlers
cbo.setOnAction(e -> {
setMode();
setText();
});
lv.getSelectionModel().selectedItemProperty().addListener(
ov -> {
setMode();
setText();
});
// Place nodes in the pane
BorderPane pane = new BorderPane();
pane.setTop(lblSelectionMode);
pane.setCenter(new ScrollPane(lv));
pane.setBottom(lblSelectedItems);
pane.setAlignment(lblSelectionMode, Pos.CENTER);
// Create a scene and place it in the stage
Scene scene = new Scene(pane, 268, 196);
primaryStage.setTitle("Exercise_16_16"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
public static Text getIconForLabel(GlyphIcons icon, String iconSize, Label label, String style) {
if (icon.fontFamily().equals(MATERIAL_DESIGN_ICONS)) {
final Text textIcon = MaterialDesignIconFactory.get().createIcon(icon, iconSize);
textIcon.setOpacity(0.7);
if (style != null) {
textIcon.getStyleClass().add(style);
}
label.setContentDisplay(ContentDisplay.LEFT);
label.setGraphic(textIcon);
return textIcon;
} else {
throw new IllegalArgumentException("Not supported icon type");
}
}
public static Optional<Label> loadIconLabel(String filename) {
if (isHeadless) {
return Optional.empty();
}
Image img = loadIcon(filename).get();
Label label = new Label() {
@Override
public boolean equals(Object obj) {
if (obj instanceof Label) {
Label l2 = (Label) obj;
return super.equals(l2) || l2.getText().equals(getText());
} else {
return super.equals(obj);
}
}
@Override
public int hashCode() {
return getText().hashCode();
}
};
label.setGraphic(new ImageView(img));
label.setAlignment(Pos.CENTER);
label.setContentDisplay(ContentDisplay.TOP);
label.setTextFill(Color.WHITE);
DropShadow shadow = new DropShadow(5.0, Color.BLACK);
label.setEffect(shadow);
return Optional.of(label);
}
@Override
public void start(final Stage primaryStage) {
final FlowPane root = new FlowPane();
root.setAlignment(Pos.CENTER);
DataSet testDataSet = generateData();
Label label = new Label("left-click-hold-drag for zooming. middle-button for panning.\n"
+ "Tip: drag horizontally/vertically/diagonally for testing; try to select the outlier");
label.setFont(Font.font(20));
label.setAlignment(Pos.CENTER);
label.setContentDisplay(ContentDisplay.CENTER);
label.setPrefWidth(2.0 * PREF_WIDTH);
// chart with default zoom
final Chart chart1 = getTestChart("default zoom", testDataSet);
Zoomer zoomer1 = new Zoomer();
registerZoomerChangeListener(zoomer1, chart1.getTitle());
chart1.getPlugins().add(zoomer1);
// chart with auto xy zoom
final Chart chart2 = getTestChart("auto xy zoom", testDataSet);
final Zoomer zoomer2 = new Zoomer();
zoomer2.setAutoZoomEnabled(true);
registerZoomerChangeListener(zoomer2, chart2.getTitle());
chart2.getPlugins().add(zoomer2);
// chart with x-only zoom
final Chart chart3 = getTestChart("x-only zoom", testDataSet);
Zoomer zoomer3 = new Zoomer(AxisMode.X);
registerZoomerChangeListener(zoomer3, chart3.getTitle());
chart3.getPlugins().add(zoomer3);
// chart with x-only zoom
final Chart chart4 = getTestChart("y-only zoom", testDataSet);
Zoomer zoomer4 = new Zoomer(AxisMode.Y);
registerZoomerChangeListener(zoomer4, chart4.getTitle());
chart4.getPlugins().add(zoomer4);
root.getChildren().addAll(chart1, chart2, chart3, chart4, label);
primaryStage.setTitle(this.getClass().getSimpleName());
primaryStage.setScene(new Scene(root));
primaryStage.setOnCloseRequest(evt -> Platform.exit());
primaryStage.show();
}
public SimpleLabel() {
ImageView imageView = new ImageView(ICON_48);
Label label = new Label("A simple label with a graphic on the left.", imageView);
label.setContentDisplay(ContentDisplay.LEFT);
getChildren().add(label);
}
public SimpleLabel() {
ImageView imageView = new ImageView(ICON_48);
Label label = new Label("A simple label with a graphic on the left.", imageView);
label.setContentDisplay(ContentDisplay.LEFT);
getChildren().add(label);
}
public AboutDialog() {
super(ArmaDialogCreator.getPrimaryStage(), new VBox(10), null, false, true, false);
ResourceBundle bundle = Lang.ApplicationBundle();
setTitle(bundle.getString("Popups.About.dialog_title"));
final Link hypRepo = new Link(Lang.Misc.REPO_URL);
final Label lblRepoUrl = new Label(bundle.getString("Popups.About.repository") + ":", hypRepo);
myStage.setResizable(false);
lblRepoUrl.setContentDisplay(ContentDisplay.RIGHT);
String version = Lang.Application.VERSION;
String build = ArmaDialogCreator.getManifest().getMainAttributes().getValue("Build-Number");
String javafx = System.getProperty("javafx.runtime.version");
String java = System.getProperty("java.version");
myRootElement.getChildren().addAll(
new ImageView(ADCImagePaths.ABOUT_HEADER),
new Label(bundle.getString("Popups.About.author") + ": " + "Kayler \"K-Town\" Renslow"),
new Label(bundle.getString("Popups.About.version") + ": " + version),
new Label(bundle.getString("Popups.About.build") + ": " + build),
new Label("Java: " + java),
new Label("JavaFX: " + javafx),
lblRepoUrl
);
HBox hboxLib = new HBox(5,
new Label(bundle.getString("Popups.About.libraries")),
new Link("ANTLR 4.7", "http://www.antlr.org/"),
new Link("RichTextFX 0.7-M2", "https://github.com/TomasMikula/RichTextFX"),
new Link("Json Simple 1.1.1", "https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple/1.1.1")
);
hboxLib.setAlignment(Pos.CENTER_LEFT);
myRootElement.getChildren().add(hboxLib);
Button btnCopyInfo = new Button(bundle.getString("Popups.About.copy_info"));
btnCopyInfo.setOnAction((e) -> {
StringSelection selection = new StringSelection(
String.format(
"Arma Dialog Creator Details\nVersion: %s\nBuild: %s\nJava: %s\nJavaFX: %s",
version,
build,
java,
javafx
)
);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
});
footer.getRightContainer().getChildren().add(0, btnCopyInfo);
btnOk.requestFocus();
}
public void construct(List<UnitPage> appunitpages) {
appunitpage.subscribeStatus(messagePageHandler);
appbeeper.subscribeStatus(beeper.getMessageHandler());
appbuzzer.subscribeStatus(buzzer.getMessageHandler());
systime.subscribeStatus(timeindicator.getMessageHandler());
// Add configured unitpages.
for (UnitPage up : appunitpages) {
this.addUnitPage(up);
}
//Init unit nodes
for (Unit u : app.getUnits()) {
Node n = u.getNode();
if (n != null) {
UnitPage unitpage = buildUnitPage(UnitPage.getPage(n));
unitpage.addUnitNode(n);
}
}
// Build listpages based on unitpages
List<UnitPage> sortedunitpages = new ArrayList<>();
sortedunitpages.addAll(unitpages.values());
Collections.sort(sortedunitpages);
firstmenupage = null;
for (UnitPage value : sortedunitpages) {
value.buildNode();
if (!value.isSystem() && !value.isEmpty() && (value.getName() == null || !value.getName().startsWith("."))) {
Label l = new Label();
l.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
l.setAlignment(Pos.CENTER);
l.setGraphic(value.getGraphic());
l.setPrefSize(45.0, 40.0);
Button buttonmenu = new Button(value.getText(), l);
buttonmenu.getStyleClass().add("menubutton");
buttonmenu.setAlignment(Pos.BASELINE_LEFT);
buttonmenu.setMaxWidth(Double.MAX_VALUE);
buttonmenu.setFocusTraversable(false);
buttonmenu.setMnemonicParsing(false);
buttonmenu.setOnAction(e -> {
appunitpage.sendStatus(value.getName());
});
menupages.getChildren().add(buttonmenu); // Last button is disconnect button
if (firstmenupage == null) {
firstmenupage = value.getName();
}
}
}
// Add backbutton
if (backbutton != null && backbutton.isVisible()) {
menupages.getChildren().add(new Separator(Orientation.HORIZONTAL));
menupages.getChildren().add(backbutton);
}
gotoPage("start");
// Remove menubutton if 0 or 1 visible page.
menubutton.setVisible(!menupages.getChildren().isEmpty());
}
public Label addDiagnosticMessage(final String message, final long chimeDelay, final Color backgroundColor) {
final Label diagnosticLabel = new Label(message);
diagnosticLabel.setStyle("-fx-background-color: " + colorToWebCode(backgroundColor));
final ImageView muteView = new ImageView();
muteView.setFitHeight(20);
muteView.setFitWidth(muteView.getFitHeight());
if (config.isChimeMuted(message)) {
muteView.setImage(muteImage);
} else {
muteView.setImage(soundImage);
}
diagnosticLabel.setContentDisplay(ContentDisplay.RIGHT);
diagnosticLabel.setGraphic(muteView);
diagnosticLabel.setOnMouseClicked((event) -> {
if (config.isChimeMuted(message)) {
muteView.setImage(soundImage);
config.unmuteMessageChime(message);
} else {
muteView.setImage(muteImage);
config.muteMessageChime(message);
}
try {
config.writeConfigurationFile();
} catch (final Exception e) {
logger.error("Failed persisting message's (" + message + ") chime mute settings.", e);
}
});
Platform.runLater(() -> diagnosticsVBox.getChildren().add(diagnosticLabel));
if (chimeDelay > 0 && !config.isChimeMuted(message) && !diagnosticExecutorService.isShutdown()) {
@SuppressWarnings("unchecked")
final ScheduledFuture<Void> chimeFuture = (ScheduledFuture<Void>) diagnosticExecutorService.schedule(
() -> TrainingExerciseBase.playSound("sounds/chime.wav"), chimeDelay, TimeUnit.MILLISECONDS);
diagnosticFutures.put(diagnosticLabel, chimeFuture);
}
return diagnosticLabel;
}
@Override
protected Pair<Node, Subscription> getNonEditingGraphic(Pair<PropertyDescriptorSpec, Var<String>> pair) {
setEditable(true);
Subscription sub = Subscription.EMPTY;
Label propName = new Label();
propName.textProperty().bind(pair.getKey().nameProperty());
sub = sub.and(() -> propName.textProperty().unbind());
Label sep = new Label(" → ");
Label propValue = new Label();
propValue.textProperty().bind(pair.getValue());
sub = sub.and(() -> propValue.textProperty().unbind());
Pane spacer = new Pane();
HBox.setHgrow(spacer, Priority.ALWAYS);
FontIcon defaultIcon = new FontIcon("fas-map-marker");
Label defaultLabel = new Label("", defaultIcon);
defaultLabel.visibleProperty().bind(
pair.getValue().flatMap(it -> pair.getKey().valueProperty())
.map(it -> Objects.equals(it, pair.getValue().getValue()))
);
defaultLabel.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
defaultLabel.setTooltip(new Tooltip("Default value"));
sub = sub.and(() -> defaultLabel.visibleProperty().unbind());
HBox box = new HBox();
box.getChildren().addAll(propName, sep, propValue, spacer, defaultLabel);
sub = sub.and(ControlUtil.registerDoubleClickListener(box, this::doStartEdit));
return new Pair<>(box, sub);
}
public BorderPane init(String unitName, String unitType, String unitDescription) {
//this.setSize(350, 400); // undecorated 301, 348 ; decorated : 303, 373
mainPane = new BorderPane();
name = new Label(unitName);
name.setPadding(new Insets(5,5,5,5));
name.setTextAlignment(TextAlignment.CENTER);
name.setContentDisplay(ContentDisplay.TOP);
box0 = new VBox();
box0.setAlignment(Pos.CENTER);
box0.setPadding(new Insets(5,5,5,5));
box0.getChildren().addAll(name);
mainPane.setTop(box0);
String type = "TYPE :";
String description = "DESCRIPTION :";
box1 = new VBox();
ta = new TextArea();
ta.setEditable(false);
ta.setWrapText(true);
box1.getChildren().add(ta);
ta.setText(System.lineSeparator() + type + System.lineSeparator() + unitType + System.lineSeparator() + System.lineSeparator());
ta.appendText(description + System.lineSeparator() + unitDescription + System.lineSeparator() + System.lineSeparator());
ta.setScrollTop(300);
applyTheme();
mainPane.setCenter(ta);
return mainPane;
}