下面列出了javafx.scene.control.ToggleButton#setText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static Tuple3<Label, InputTextField, ToggleButton> addTopLabelInputTextFieldSlideToggleButton(GridPane gridPane,
int rowIndex,
String title,
String toggleButtonTitle) {
InputTextField inputTextField = new InputTextField();
ToggleButton toggleButton = new JFXToggleButton();
toggleButton.setText(toggleButtonTitle);
VBox.setMargin(toggleButton, new Insets(4, 0, 0, 0));
final Tuple2<Label, VBox> topLabelWithVBox = addTopLabelWithVBox(gridPane, rowIndex, title, inputTextField, 0);
topLabelWithVBox.second.getChildren().add(toggleButton);
return new Tuple3<>(topLabelWithVBox.first, inputTextField, toggleButton);
}
public static ToggleButton addSlideToggleButton(GridPane gridPane, int rowIndex, String title, double top) {
ToggleButton toggleButton = new AutoTooltipSlideToggleButton();
toggleButton.setText(title);
GridPane.setRowIndex(toggleButton, rowIndex);
GridPane.setColumnIndex(toggleButton, 0);
GridPane.setMargin(toggleButton, new Insets(top, 0, 0, 0));
gridPane.getChildren().add(toggleButton);
return toggleButton;
}
@Override
public void start(Stage stage) {
try {
// create stack pane and application scene
StackPane stackPane = new StackPane();
Scene scene = new Scene(stackPane);
// set title, size, and add scene to stage
stage.setTitle("Style WMS Layer Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();
// create a map and add it to the map view
ArcGISMap map = new ArcGISMap(Basemap.createImagery());
mapView = new MapView();
mapView.setMap(map);
// create style toggle button, disable until layer is loaded
ToggleButton styleToggleButton = new ToggleButton();
styleToggleButton.setText("Toggle style");
styleToggleButton.setDisable(true);
// create a WMS layer
List<String> wmsLayerNames = Collections.singletonList("fsa2017");
String url = "http://geoint.lmic.state.mn.us/cgi-bin/wms?VERSION=1.3.0&SERVICE=WMS&REQUEST=GetCapabilities";
wmsLayer = new WmsLayer(url, wmsLayerNames);
wmsLayer.addDoneLoadingListener(() -> {
if (wmsLayer.getLoadStatus() == LoadStatus.LOADED) {
// add the layer to the map
map.getOperationalLayers().add(wmsLayer);
// zoom to the layer on the map
mapView.setViewpoint(new Viewpoint(wmsLayer.getFullExtent()));
// get styles
List<String> styles = wmsLayer.getSublayers().get(0).getSublayerInfo().getStyles();
// set the style when the button is toggled
styleToggleButton.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (styleToggleButton.isSelected()) {
wmsLayer.getSublayers().get(0).setCurrentStyle(styles.get(1));
} else {
// default style
wmsLayer.getSublayers().get(0).setCurrentStyle(styles.get(0));
}
});
// enable the toggle button
styleToggleButton.setDisable(false);
} else {
Alert alert = new Alert(Alert.AlertType.ERROR, "Failed to load WMS layer");
alert.show();
}
});
wmsLayer.loadAsync();
// add the map view to stack pane
stackPane.getChildren().addAll(mapView, styleToggleButton);
StackPane.setAlignment(styleToggleButton, Pos.TOP_LEFT);
StackPane.setMargin(styleToggleButton, new Insets(10, 0, 0, 10));
} catch (Exception e) {
// on any error, display the stack trace.
e.printStackTrace();
}
}
/**
* Create a new LanguagePanel
*/
public LanguagePanel()
{
originalLanguage = ConfigurationSettings.getLanguage();
if ((SettingsHandler.getGameAsProperty().get() != null) && (SettingsHandler.getGameAsProperty().get().getUnitSet() != null))
{
originalUnitSet = SettingsHandler.getGameAsProperty().get().getUnitSet().getDisplayName();
}
else
{
originalUnitSet = "";
}
VBox vbox = new VBox();
for (LanguageChoice languageChoice: LanguageChoice.values())
{
ToggleButton languageButton = new RadioButton();
languageButton.setUserData(languageChoice.getShortName());
languageButton.setText(languageChoice.getLongName());
languageButton.setToggleGroup(languageChoiceGroup);
vbox.getChildren().add(languageButton);
}
Collection<UnitSet> unitSets = SettingsHandler.getGameAsProperty().get().getModeContext().getReferenceContext()
.getConstructedCDOMObjects(UnitSet.class);
Collection<String> names = unitSets.stream()
.filter(Objects::nonNull)
.map(UnitSet::getDisplayName)
.collect(Collectors.toUnmodifiableList());
ObservableList<String> unitSetNames = FXCollections.observableArrayList(names);
unitSetType = new ChoiceBox<>();
unitSetType.setItems(unitSetNames);
Label unitSetLabel = new Label(LanguageBundle.getString("in_Prefs_unitSetType"));
unitSetLabel.setLabelFor(unitSetType);
vbox.getChildren().add(unitSetLabel);
vbox.getChildren().add(unitSetType);
Node restartInfo = new Text(LanguageBundle.getString("in_Prefs_restartInfo"));
vbox.getChildren().add(restartInfo);
this.add(GuiUtility.wrapParentAsJFXPanel(vbox));
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
pane = new MigPane();
findField = new CustomTextField();
previousButton = new Button();
nextButton = new Button();
matchCaseButton = new ToggleButton();
regexButton = new ToggleButton();
findInfoLabel = new Label();
closeButton = new Button();
replacePane = new MigPane();
replaceField = new CustomTextField();
replaceButton = new Button();
replaceAllButton = new Button();
replaceInfoLabel = new Label();
nOfHitCountLabel = new Label();
//======== pane ========
{
pane.setLayout("insets 0,hidemode 3");
pane.setCols("[shrink 0,fill][fill]0[fill][pref:n,fill]1px[pref:n,fill][grow,fill][fill]");
pane.setRows("[fill]0[]");
//---- findField ----
findField.setPromptText(Messages.get("FindReplacePane.findField.promptText"));
findField.setPrefColumnCount(15);
pane.add(findField, "cell 0 0");
//---- previousButton ----
previousButton.setFocusTraversable(false);
pane.add(previousButton, "cell 1 0");
//---- nextButton ----
nextButton.setFocusTraversable(false);
pane.add(nextButton, "cell 2 0");
//---- matchCaseButton ----
matchCaseButton.setText("Aa");
matchCaseButton.setFocusTraversable(false);
pane.add(matchCaseButton, "cell 3 0");
//---- regexButton ----
regexButton.setText(".*");
regexButton.setFocusTraversable(false);
pane.add(regexButton, "cell 4 0");
pane.add(findInfoLabel, "cell 5 0");
//---- closeButton ----
closeButton.setFocusTraversable(false);
pane.add(closeButton, "cell 6 0");
//======== replacePane ========
{
replacePane.setLayout("insets rel 0 0 0");
replacePane.setCols("[shrink 0,fill][pref:n,fill][pref:n,fill][grow,fill]");
replacePane.setRows("[]");
//---- replaceField ----
replaceField.setPromptText(Messages.get("FindReplacePane.replaceField.promptText"));
replaceField.setPrefColumnCount(15);
replacePane.add(replaceField, "cell 0 0");
//---- replaceButton ----
replaceButton.setText(Messages.get("FindReplacePane.replaceButton.text"));
replaceButton.setFocusTraversable(false);
replacePane.add(replaceButton, "cell 1 0");
//---- replaceAllButton ----
replaceAllButton.setText(Messages.get("FindReplacePane.replaceAllButton.text"));
replaceAllButton.setFocusTraversable(false);
replacePane.add(replaceAllButton, "cell 2 0");
replacePane.add(replaceInfoLabel, "cell 3 0");
}
pane.add(replacePane, "cell 0 1 7 1");
}
//---- nOfHitCountLabel ----
nOfHitCountLabel.setText(Messages.get("FindReplacePane.nOfHitCountLabel.text"));
// JFormDesigner - End of component initialization //GEN-END:initComponents
}
/**
* Create a new LanguagePanel
*/
public LanguagePanel()
{
originalLanguage = ConfigurationSettings.getLanguage();
if ((SettingsHandler.getGameAsProperty().get() != null) && (SettingsHandler.getGameAsProperty().get().getUnitSet() != null))
{
originalUnitSet = SettingsHandler.getGameAsProperty().get().getUnitSet().getDisplayName();
}
else
{
originalUnitSet = "";
}
VBox vbox = new VBox();
for (LanguageChoice languageChoice: LanguageChoice.values())
{
ToggleButton languageButton = new RadioButton();
languageButton.setUserData(languageChoice.getShortName());
languageButton.setText(languageChoice.getLongName());
languageButton.setToggleGroup(languageChoiceGroup);
vbox.getChildren().add(languageButton);
}
Collection<UnitSet> unitSets = SettingsHandler.getGameAsProperty().get().getModeContext().getReferenceContext()
.getConstructedCDOMObjects(UnitSet.class);
Collection<String> names = unitSets.stream()
.filter(Objects::nonNull)
.map(UnitSet::getDisplayName)
.collect(Collectors.toUnmodifiableList());
ObservableList<String> unitSetNames = FXCollections.observableArrayList(names);
unitSetType = new ChoiceBox<>();
unitSetType.setItems(unitSetNames);
Label unitSetLabel = new Label(LanguageBundle.getString("in_Prefs_unitSetType"));
unitSetLabel.setLabelFor(unitSetType);
vbox.getChildren().add(unitSetLabel);
vbox.getChildren().add(unitSetType);
Node restartInfo = new Text(LanguageBundle.getString("in_Prefs_restartInfo"));
vbox.getChildren().add(restartInfo);
this.add(GuiUtility.wrapParentAsJFXPanel(vbox));
}