下面列出了怎么用javafx.scene.layout.AnchorPane的API类实例代码及写法,或者点击链接到github查看源代码。
public static Initializable getInitializable(String viewName) throws IOException {
FXMLLoader loader = new FXMLLoader(); // 创建对象
loader.setBuilderFactory(new JavaFXBuilderFactory()); // 设置BuilderFactory
loader.setLocation(GameView.class.getResource(viewName + ".fxml")); // 设置路径基准
try {
InputStream in = GameView.class.getResourceAsStream(viewName + ".fxml");
AnchorPane page = (AnchorPane) loader.load(in); // 对象方法的参数是InputStream,返回值是Object
Scene scene = new Scene(page, 800, 600);
Stage stage = new Stage();
stage.setScene(scene);
stage.sizeToScene();
return (Initializable) loader.getController(); // 可以得到Controller
} finally {
in.close();
return null;
}
}
@SuppressWarnings("Duplicates")
public ScrollPane getView() {
ScrollPane scrollPane = new ScrollPane();
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);
AnchorPane anchorPane = new AnchorPane();
scrollPane.setContent(anchorPane);
gridPane.setHgap(5);
gridPane.setVgap(5);
ColumnConstraints columnConstraints1 = new ColumnConstraints();
columnConstraints1.setPercentWidth(100);
gridPane.getColumnConstraints().addAll(columnConstraints1);
AnchorPane.setBottomAnchor(gridPane, 10d);
AnchorPane.setRightAnchor(gridPane, 10d);
AnchorPane.setLeftAnchor(gridPane, 10d);
AnchorPane.setTopAnchor(gridPane, 10d);
anchorPane.getChildren().add(gridPane);
return scrollPane;
}
/**
* Creates a new about dialog.
*
* @param root root stack pane.
*/
public AboutDialog(StackPane root) {
super();
AnchorPane anchor = new AnchorPane();
anchor.setMaxHeight(274);
anchor.setMaxWidth(500);
anchor.setMinHeight(274);
anchor.setMaxWidth(500);
ImageView about = Icons.about();
Label version = new Label(Globals.VERSION);
Label license = new Label(Globals.LICENSE);
version.getStyleClass().add("about");
license.getStyleClass().add("about");
anchor.setTopAnchor(about, 0.0);
anchor.setBottomAnchor(about, 0.0);
anchor.setLeftAnchor(about, 0.0);
anchor.setRightAnchor(about, 0.0);
anchor.setTopAnchor(version, 5.0);
anchor.setRightAnchor(version, 10.0);
anchor.setBottomAnchor(license, 5.0);
anchor.setLeftAnchor(license, 10.0);
anchor.getChildren().addAll(about, version, license);
setDialogContainer(root);
setContent((Region) anchor);
setTransitionType(JFXDialog.DialogTransition.TOP);
}
private void updateConfidence(TransactionConfidence confidence) {
GUIUtil.updateConfidence(confidence, progressIndicatorTooltip, txConfidenceIndicator);
if (confidence != null) {
if (txConfidenceIndicator.getProgress() != 0) {
txConfidenceIndicator.setVisible(true);
AnchorPane.setRightAnchor(txConfidenceIndicator, 0.0);
}
} else {
//TODO we should show some placeholder in case of a tx which we are not aware of but which can be
// confirmed already. This is for instance the case of the other peers trade fee tx, as it is not related
// to our wallet we don't have a confidence object but we should show that it is in an unknown state instead
// of not showing anything which causes confusion that the tx was not broadcasted. Best would be to request
// it from a block explorer service but that is a bit too heavy for that use case...
// Maybe a question mark with a tooltip explaining why we don't know about the confidence might be ok...
}
}
private void adjustAxisAnchors() {
axis.forEach(axis -> {
if (Orientation.HORIZONTAL == axis.getOrientation()) {
AnchorPane.setLeftAnchor(axis, hasLeftYAxis ? leftAxisWidth : 0d);
AnchorPane.setRightAnchor(axis, hasRightYAxis ? rightAxisWidth : 0d);
AnchorPane.setLeftAnchor(xyPane, hasLeftYAxis ? leftAxisWidth : 0d);
AnchorPane.setRightAnchor(xyPane, hasRightYAxis ? rightAxisWidth : 0d);
} else {
AnchorPane.setTopAnchor(axis, hasTopXAxis ? topAxisHeight : 0d);
AnchorPane.setBottomAnchor(axis, hasBottomXAxis ? bottomAxisHeight : 0d);
AnchorPane.setTopAnchor(xyPane, hasTopXAxis ? topAxisHeight : 0d);
AnchorPane.setBottomAnchor(xyPane, hasBottomXAxis ? bottomAxisHeight : 0d);
}
});
}
public void loadRecipes(){
FXMLLoader loader = new FXMLLoader(getClass().getResource("/poe/level/fx/overlay/RecipeOverlay.fxml"));
AnchorPane ap = null;
try {
ap = loader.load();
} catch (IOException ex) {
Logger.getLogger(ZoneOverlay_Stage.class.getName()).log(Level.SEVERE, null, ex);
}
loader.<RecipeOverlay_Controller>getController().hookGameModeOn(parent_gameModeOn);
Scene scene = new Scene(ap);
scene.getStylesheets().add(getClass().getResource("/styles/style.css").toExternalForm());
this.setScene(scene);
//this.setAlwaysOnTop(true);
this.setOnCloseRequest(event -> {
RecipeOverlay_Controller.gameModeOn = false;
this.close();
});
this.show();
}
public void loadFXMLBeta(){
FXMLLoader loader = new FXMLLoader(getClass().getResource("/poe/level/fx/overlay/GemOverlayBeta.fxml"));
AnchorPane ap = null;
try {
ap = loader.load();
} catch (IOException ex) {
Logger.getLogger(GemOverlay_Stage.class.getName()).log(Level.SEVERE, null, ex);
}
controller_beta = loader.<GemOverlayBeta_Controller>getController();
Scene scene = new Scene(ap);
scene.getStylesheets().add(getClass().getResource("/styles/style.css").toExternalForm());
scene.setFill(Color.TRANSPARENT);
this.setScene(scene);
controller_beta.hookStage(this);
controller_beta.defaultTitle();
this.show();
}
private Scene createPreloaderScene() {
bar = new ProgressBar();
//BorderPane p = new BorderPane();
FXMLLoader loader = new FXMLLoader(getClass().getResource("loading.fxml"));
AnchorPane p = null;
try {
p = loader.load();
} catch (IOException ex) {
Logger.getLogger(MainApp_Controller.class.getName()).log(Level.SEVERE, null, ex);
}
//at this point this class has done enough, and we need to contact with the
//appropriate controllers.
controller = loader.<Loading_Controller>getController();
Scene pr = new Scene(p);
pr.getStylesheets().add(getClass().getResource("/styles/style.css").toExternalForm());
return pr;
}
public InfoTextField() {
arrowLocation = PopOver.ArrowLocation.RIGHT_TOP;
textField = new BisqTextField();
textField.setLabelFloat(true);
textField.setEditable(false);
textField.textProperty().bind(text);
textField.setFocusTraversable(false);
textField.setId("info-field");
infoIcon = getIcon(AwesomeIcon.INFO_SIGN);
infoIcon.setLayoutY(5);
infoIcon.getStyleClass().addAll("icon", "info");
AnchorPane.setRightAnchor(infoIcon, 7.0);
AnchorPane.setRightAnchor(textField, 0.0);
AnchorPane.setLeftAnchor(textField, 0.0);
hideIcons();
getChildren().addAll(textField, infoIcon);
}
public Material showMaterialEditor() throws Exception {
if (this.materialController == null) {
FXMLLoader loader = FXMLLoaderFactory.materialEditorLoader();
AnchorPane pane = (AnchorPane) loader.getRoot();
// Create the dialog Stage.
Stage dialogStage = new Stage(StageStyle.DECORATED);
dialogStage.setTitle(DesignerLocalizer.instance().getLangString("material.editor.title"));
dialogStage.initModality(Modality.NONE);
Scene scene = new Scene(pane);
dialogStage.setScene(scene);
// get the controller
materialController = loader.getController();
materialController.setDialogStage(dialogStage);
materialController.initialize(this);
}
// Show the dialog and wait until the user closes it
if (!materialController.getDialogStage().isShowing()) {
materialController.getDialogStage().showAndWait();
}
return materialController.getSelectedMaterial();
}
private void onSelectMinorStoppagesPareto() throws Exception {
List<ParetoItem> items = EquipmentLossManager.getParetoData(equipmentLoss, TimeLoss.MINOR_STOPPAGES);
Number divisor = equipmentLoss.getLoss(TimeLoss.MINOR_STOPPAGES).getSeconds();
StackPane spMinorStoppagesPareto = new StackPane();
AnchorPane.setBottomAnchor(spMinorStoppagesPareto, 0.0);
AnchorPane.setLeftAnchor(spMinorStoppagesPareto, 0.0);
AnchorPane.setRightAnchor(spMinorStoppagesPareto, 0.0);
AnchorPane.setTopAnchor(spMinorStoppagesPareto, 0.0);
apMinorStoppagesPareto.getChildren().clear();
apMinorStoppagesPareto.getChildren().add(0, spMinorStoppagesPareto);
ParetoChartController controller = new ParetoChartController();
controller.createParetoChart(DesignerLocalizer.instance().getLangString("stoppages.pareto"),
spMinorStoppagesPareto, items, divisor, DesignerLocalizer.instance().getLangString("time.by.reason"));
}
private void onSelectSetupPareto() throws Exception {
List<ParetoItem> items = EquipmentLossManager.getParetoData(equipmentLoss, TimeLoss.SETUP);
Number divisor = equipmentLoss.getLoss(TimeLoss.SETUP).getSeconds();
StackPane spSetupPareto = new StackPane();
AnchorPane.setBottomAnchor(spSetupPareto, 0.0);
AnchorPane.setLeftAnchor(spSetupPareto, 0.0);
AnchorPane.setRightAnchor(spSetupPareto, 0.0);
AnchorPane.setTopAnchor(spSetupPareto, 0.0);
apSetupPareto.getChildren().clear();
apSetupPareto.getChildren().add(0, spSetupPareto);
ParetoChartController controller = new ParetoChartController();
controller.createParetoChart(DesignerLocalizer.instance().getLangString("setup.pareto"), spSetupPareto, items,
divisor, DesignerLocalizer.instance().getLangString("time.by.reason"));
}
private SetupEditorController getSetupController() throws Exception {
if (setupEditorController == null) {
FXMLLoader loader = FXMLLoaderFactory.setupEditorLoader();
AnchorPane page = (AnchorPane) loader.getRoot();
Stage dialogStage = new Stage(StageStyle.DECORATED);
dialogStage.setTitle(DesignerLocalizer.instance().getLangString("setup.editor"));
dialogStage.initModality(Modality.APPLICATION_MODAL);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
// get the controller
setupEditorController = loader.getController();
setupEditorController.setDialogStage(dialogStage);
}
return setupEditorController;
}
private Reason showReasonSelector() throws Exception {
FXMLLoader loader = FXMLLoaderFactory.reasonSelectorLoader();
AnchorPane page = (AnchorPane) loader.getRoot();
Stage dialogStage = new Stage(StageStyle.DECORATED);
dialogStage.setTitle(OperatorLocalizer.instance().getLangString("reason.selector.title"));
dialogStage.initModality(Modality.WINDOW_MODAL);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
reasonController = loader.getController();
reasonController.setDialogStage(dialogStage);
reasonController.initialize();
if (!reasonController.getDialogStage().isShowing()) {
reasonController.getDialogStage().showAndWait();
}
return reasonController.getSelectedReason();
}
public void start(Stage primaryStage) {
try {
FXMLLoader loader = FXMLLoaderFactory.testerApplicationLoader();
AnchorPane mainLayout = loader.getRoot();
testerController = loader.getController();
testerController.initialize();
Scene scene = new Scene(mainLayout);
primaryStage.setTitle(TesterLocalizer.instance().getLangString("test.app.title"));
primaryStage.getIcons().add(ImageManager.instance().getImage(Images.POINT85));
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
logger.error(e.getMessage());
stop();
}
}
private static AnchorPane wrap(Node node) {
AnchorPane anchorPane = new AnchorPane(node);
AnchorPane.setTopAnchor(node, 0.0);
AnchorPane.setLeftAnchor(node, 0.0);
AnchorPane.setRightAnchor(node, 0.0);
AnchorPane.setBottomAnchor(node, 0.0);
return anchorPane;
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Event Handler Demo");
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("EventHandlerDemo.fxml"));
AnchorPane page = (AnchorPane)loader.load();
Scene scene = new Scene(page);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
System.err.println("Error loading EventHandlerDemo.fxml!");
e.printStackTrace();
}
}
private void addScrollPane() {
scrollPane = new ScrollPane();
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);
AnchorPane.setLeftAnchor(scrollPane, 0d);
AnchorPane.setTopAnchor(scrollPane, 0d);
AnchorPane.setRightAnchor(scrollPane, 0d);
AnchorPane.setBottomAnchor(scrollPane, 0d);
root.getChildren().add(scrollPane);
}
public BrokerConfigView(KafkaBrokerConfig config,
AnchorPane parentPane,
ModelConfigObjectsGuiInformer guiInformer,
Window parentWindow,
Runnable refeshCallback,
UserInteractor guiInteractor,
ClusterStatusChecker statusChecker,
KafkaClusterProxies kafkaClusterProxies) throws IOException {
this.statusChecker = statusChecker;
this.kafkaClusterProxies = kafkaClusterProxies;
CustomFxWidgetsLoader.loadAnchorPane(this, FXML_FILE);
this.config = config;
this.parentWindow = parentWindow;
this.rerfeshCallback = refeshCallback;
this.userInteractor = guiInteractor;
final StringExpression windowTitle = composeConfigWindowTitle();
displayBehaviour = new DetachableDisplayBehaviour(parentPane,
windowTitle,
this,
detachPaneButton.selectedProperty(),
config,
guiInformer);
GuiUtils.expandNodeToAnchorPaneBorders(this);
configureGuiControls();
startObservingNewKafkaBrokerProxyForNewHostInfo();
setCallbackToStartListeningOnNewKafkaProxyChangesWhenHostnameOrPortPropertyChanges();
resetKafkaBrokerPropertyToFireUpCallbacksForTheFirstTime();
}
public PropertyCollectionView(@NamedArg("designerRoot") DesignerRoot root) {
this.root = root;
this.getStyleClass().addAll("property-collection-view");
view = new ListView<>();
initListView(view);
setOwnerStageFactory(root.getMainStage()); // default
AnchorPane footer = new AnchorPane();
footer.setPrefHeight(30);
footer.getStyleClass().addAll("footer");
footer.getStylesheets().addAll(DesignerUtil.getCss("flat").toString());
Button addProperty = new Button("Add property");
ControlUtil.anchorFirmly(addProperty);
addProperty.setOnAction(e -> {
addNewProperty(getUniqueNewName());
view.requestFocus();
});
footer.getChildren().addAll(addProperty);
this.getChildren().addAll(view, footer);
myEditPopover = new PopOverWrapper<>(this::rebindPopover);
myEditPopover.rebind(new PropertyDescriptorSpec());
myEditPopover.doFirstLoad(root.getMainStage());
}
void showHttpTrendDialog(EventResolver eventResolver) throws Exception {
// Load the fxml file and create a new stage for the pop-up dialog.
FXMLLoader loader = FXMLLoaderFactory.httpTrendLoader();
AnchorPane page = (AnchorPane) loader.getRoot();
// Create the dialog Stage.
Stage dialogStage = new Stage(StageStyle.DECORATED);
dialogStage.setTitle(DesignerLocalizer.instance().getLangString("http.trend.title"));
dialogStage.initModality(Modality.NONE);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
// get the controller
HttpTrendController httpTrendController = loader.getController();
httpTrendController.setDialogStage(dialogStage);
httpTrendController.setApp(this);
// add the trend chart
SplitPane chartPane = httpTrendController.initializeTrend();
AnchorPane.setBottomAnchor(chartPane, 50.0);
AnchorPane.setLeftAnchor(chartPane, 5.0);
AnchorPane.setRightAnchor(chartPane, 5.0);
AnchorPane.setTopAnchor(chartPane, 50.0);
page.getChildren().add(0, chartPane);
// set the script resolver
httpTrendController.setScriptResolver(eventResolver);
// start HTTP server
httpTrendController.onStartServer();
// show the trend
httpTrendController.getDialogStage().show();
}
/**
* Creates and shows a new FeatureTable. Should be called via {@link
* Platform#runLater(Runnable)}.
*
* @param flist The feature list.
* @return The {@link FeatureTableWindowFXMLController} of the window or null if failed to
* initialise.
*/
@Nullable
public static FeatureTableWindowFXMLController createFeatureTableWindow(
ModularFeatureList flist) {
FeatureTableWindowFXMLController controller;
FXMLLoader loader =
new FXMLLoader((FeatureTableFX.class.getResource("FeatureTableFXMLWindow.fxml")));
Stage stage = new Stage();
try {
AnchorPane root = (AnchorPane) loader.load();
Scene scene = new Scene(root, 1000, 600);
// Use main CSS
scene.getStylesheets()
.addAll(MZmineCore.getDesktop().getMainWindow().getScene().getStylesheets());
stage.setScene(scene);
logger.finest("Feature table stage has been successfully loaded from the FXML loader.");
} catch (IOException e) {
e.printStackTrace();
return null;
}
// Get controller
controller = loader.getController();
stage.setTitle("Feature table - " + flist.getName());
stage.show();
stage.setMinWidth(stage.getWidth());
stage.setMinHeight(stage.getHeight());
controller.setFeatureList(flist);
return controller;
}
@Override
public ListenerConfigView getListenerConfigGuiController(KafkaListenerConfig config,
AnchorPane parentPane,
Listeners activeConsumers,
Runnable refreshCallback,
ObservableList<KafkaTopicConfig> topicConfigs,
ToFileSaver toFileSaver
) {
return getControllerFor(config, listenersControllers, () -> {
try {
final FixedNumberRecordsCountLogger fixedRecordsLogger = new FixedNumberRecordsCountLogger(new CyclicStringBuffer());
restartables.register(fixedRecordsLogger);
return new ListenerConfigView(config,
parentPane,
guiInformer,
activeConsumers,
refreshCallback,
topicConfigs,
toFileSaver,
fixedRecordsLogger);
} catch (IOException e) {
Logger.error(e);
return null;
}
});
}
@FXML
private void Back() {
try {
AnchorPane studentMgmt = FXMLLoader.load(getClass().getResource(("/sms/view/fxml/MainDashboard.fxml")));
userAccount.getChildren().setAll(studentMgmt);
}catch(IOException e){
System.out.println(e);
}
}
private boolean addCameraTab(String webcamName, Camera cameraInterface) {
if (cameraInterface.isLocked() && !cameraInterface.isOpen()) {
return false;
}
final Tab cameraTab = new Tab(webcamName);
final Group cameraCanvasGroup = new Group();
// 640 x 480
cameraTab.setContent(new AnchorPane(cameraCanvasGroup));
final CanvasManager canvasManager = new CanvasManager(cameraCanvasGroup, this, webcamName, shotEntries);
final Optional<CameraManager> cameraManagerOptional = camerasSupervisor.addCameraManager(cameraInterface, this,
canvasManager);
if (!cameraManagerOptional.isPresent()) {
return false;
}
final CameraManager cameraManager = cameraManagerOptional.get();
cameraManagerTabs.put(cameraTab, cameraManager);
if (config.getRecordingCameras().contains(cameraInterface)) {
config.registerRecordingCameraManager(cameraManager);
}
canvasManager.setContextMenu(createContextMenu());
installDebugCoordDisplay(canvasManager);
return cameraTabPane.getTabs().add(cameraTab);
}
@FXML
private void ManageUsers() {
try {
AnchorPane studentMgmt = FXMLLoader.load(getClass().getResource(("/sms/view/fxml/ManageUsers.fxml")));
userAccount.getChildren().setAll(studentMgmt);
}catch(IOException e){
System.out.println(e);
}
}
public void setOverlayTopRight(Group content) {
Platform.runLater(() -> {
DriveControlsAnchor.getChildren().clear();
DriveControlsAnchor.getChildren().add(content);
AnchorPane.setTopAnchor(content, 0.0);
AnchorPane.setRightAnchor(content, 0.0);
AnchorPane.setLeftAnchor(content, 0.0);
AnchorPane.setBottomAnchor(content, 0.0);
DriveControlsAnchor.setVisible(true);
});
}
void showDatabaseTrendDialog(EventResolver eventResolver) throws Exception {
// Load the fxml file and create a new stage for the pop-up dialog.
FXMLLoader loader = FXMLLoaderFactory.databaseTrendLoader();
AnchorPane page = (AnchorPane) loader.getRoot();
// Create the dialog Stage.
Stage dialogStage = new Stage(StageStyle.DECORATED);
dialogStage.setTitle(DesignerLocalizer.instance().getLangString("db.event.trend"));
dialogStage.initModality(Modality.NONE);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
// get the controller
DatabaseTrendController databaseTrendController = loader.getController();
databaseTrendController.setDialogStage(dialogStage);
databaseTrendController.setApp(this);
// add the trend chart
SplitPane chartPane = databaseTrendController.initializeTrend();
AnchorPane.setBottomAnchor(chartPane, 50.0);
AnchorPane.setLeftAnchor(chartPane, 5.0);
AnchorPane.setRightAnchor(chartPane, 5.0);
AnchorPane.setTopAnchor(chartPane, 50.0);
page.getChildren().add(0, chartPane);
// set the script resolver
databaseTrendController.setEventResolver(eventResolver);
// connect to the database server
databaseTrendController.subscribeToDataSource();
// show the window
databaseTrendController.getDialogStage().show();
}
@Override
public TemplateGuiActionsHandler<KafkaSenderConfig> createSenderConfigListViewActionHandler(AnchorPane rightContentPane,
TabPane masterTabPane,
Tab tab,
ListView<KafkaSenderConfig> listView,
ListView<KafkaTopicConfig> topicConfigListView,
ControllerProvider repository) {
return new SenderConfigGuiActionsHandler(new TabPaneSelectionInformer(masterTabPane, tab),
new ListViewActionsHandler<>(interactor, listView),
modelDataProxy,
repository,
rightContentPane,
topicConfigListView,
applicationPorts.getSender());
}
private Axis createLeftYAxis(final double MIN, final double MAX, final boolean AUTO_SCALE) {
Axis axis = new Axis(Orientation.VERTICAL, Position.LEFT);
axis.setMinValue(MIN);
axis.setMaxValue(MAX);
axis.setPrefWidth(AXIS_WIDTH);
axis.setAutoScale(AUTO_SCALE);
AnchorPane.setTopAnchor(axis, 0d);
AnchorPane.setBottomAnchor(axis, 25d);
AnchorPane.setLeftAnchor(axis, 0d);
return axis;
}