下面列出了怎么用javafx.scene.Parent的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void start(Stage stage) throws Exception {
// set up the scene
FXMLLoader loader = new FXMLLoader(getClass().getResource("/create_and_save_kml_file/main.fxml"));
Parent root = loader.load();
controller = loader.getController();
Scene scene = new Scene(root);
// set title, size and add scene to stage
stage.setTitle("Create and Save KML File");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();
}
@Override
protected void layoutChildren() {
// invalidate breadth for each cell that has dirty layout
int n = cells.getMemoizedCount();
for(int i = 0; i < n; ++i) {
int j = cells.indexOfMemoizedItem(i);
Node node = cells.get(j).getNode();
if(node instanceof Parent && ((Parent) node).isNeedsLayout()) {
sizeTracker.forgetSizeOf(j);
}
}
if(!cells.isEmpty()) {
targetPosition.clamp(cells.size())
.accept(this);
}
currentPosition = getCurrentPosition();
targetPosition = currentPosition;
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/resources/fxml/singleimage.fxml"));
Scene scene = new Scene(root);
stage.resizableProperty().setValue(false);
stage.setTitle("Single Image Checker");
stage.setScene(scene);
stage.show();
CommonUtil.attachIcon(stage);
stage.setOnCloseRequest((WindowEvent event) -> {
System.exit(0);
});
}
public void show() {
if (options.isButtonHideOnSelect() && mainMenuButton.getOpacity() > 0) {
return;
}
if (options.isButtonHideOnSelect() || mainMenuButton.getOpacity() == 0) {
mainMenuButton.setScaleX(1.0);
mainMenuButton.setScaleY(1.0);
cross.setRotate(0);
mainMenuButton.setRotate(0);
FadeTransition buttonFadeIn = new FadeTransition();
buttonFadeIn.setNode(mainMenuButton);
buttonFadeIn.setDuration(Duration.millis(200));
buttonFadeIn.setToValue(options.getButtonAlpha());
buttonFadeIn.play();
}
for (Parent node : items.keySet()) {
node.setScaleX(1.0);
node.setScaleY(1.0);
node.setTranslateX(0);
node.setTranslateY(0);
node.setRotate(0);
}
}
/**
* Fill a list of components.
*
* @param container the container
* @param node the node
*/
@FxThread
public static void fillComponents(@NotNull final Array<ScreenComponent> container, @NotNull final Node node) {
if (node instanceof ScreenComponent) {
container.add((ScreenComponent) node);
}
if (node instanceof SplitPane) {
final ObservableList<Node> items = ((SplitPane) node).getItems();
items.forEach(child -> fillComponents(container, child));
} else if (node instanceof TabPane) {
final ObservableList<Tab> tabs = ((TabPane) node).getTabs();
tabs.forEach(tab -> fillComponents(container, tab.getContent()));
}
if (!(node instanceof Parent)) {
return;
}
final ObservableList<Node> nodes = ((Parent) node).getChildrenUnmodifiable();
nodes.forEach(child -> fillComponents(container, child));
}
/** {@inheritDoc} */
@Override
public void start(Stage stage) {
try {
// load splash
Parent root = FXMLLoader.load(getClass().getResource("/jupiter/fxml/Splash.fxml"));
// create scene and add styles
Scene scene = new Scene(root, 500, 274);
scene.getStylesheets().addAll(getClass().getResource("/jupiter/css/splash.css").toExternalForm());
// set stage
stage.setScene(scene);
stage.setResizable(false);
stage.initStyle(StageStyle.UNDECORATED);
stage.getIcons().add(Icons.favicon());
stage.toFront();
stage.show();
} catch (IOException e) {
e.printStackTrace();
Logger.error("could not load Jupiter GUI");
Jupiter.exit(1);
}
}
private Parent createContent() {
Pane root = new Pane();
root.setPrefSize(600, 600);
char c = 'A';
List<Tile> tiles = new ArrayList<>();
for (int i = 0; i < NUM_OF_PAIRS; i++) {
tiles.add(new Tile(String.valueOf(c)));
tiles.add(new Tile(String.valueOf(c)));
c++;
}
Collections.shuffle(tiles);
for (int i = 0; i < tiles.size(); i++) {
Tile tile = tiles.get(i);
tile.setTranslateX(50 * (i % NUM_PER_ROW));
tile.setTranslateY(50 * (i / NUM_PER_ROW));
root.getChildren().add(tile);
}
return root;
}
private Parent createContent() {
Pane root = new Pane();
root.setPrefSize(800, 600);
Canvas canvas = new Canvas(800, 600);
g = canvas.getGraphicsContext2D();
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
t += 0.017;
draw();
}
};
timer.start();
root.getChildren().add(canvas);
return root;
}
protected Parent overlay(Args args) {
Color fill = getTextFill(args);
TextFlow topLeft = text(fill, getTopLeftText(args), LEFT);
TextFlow topCenter = text(fill, getTopCenterText(args), CENTER);
TextFlow topRight = text(fill, getTopRightText(args), RIGHT);
TextFlow bottomLeft = text(fill, getBottomLeftText(args), LEFT);
TextFlow bottomCenter = text(fill, getBottomCenterText(args), CENTER);
TextFlow bottomRight = text(fill, getBottomRightText(args), RIGHT);
StackPane top = new StackPane(topLeft, topCenter, topRight);
StackPane bottom = new StackPane(bottomLeft, bottomCenter, bottomRight);
BorderPane.setMargin(top, new Insets(20));
BorderPane.setMargin(bottom, new Insets(20));
BorderPane layout = new BorderPane();
layout.setBackground(EMPTY);
layout.setTop(top);
layout.setBottom(bottom);
return layout;
}
@Override
public void start(Stage primaryStage) {
try {
Parent p = FXMLLoader.load(getClass().getResource("/menubutton-fxml/CollegeSelection.fxml"));
Scene scene = new Scene(p);
primaryStage.setTitle("bekwam.com Menu Button Example");
primaryStage.setScene( scene );
primaryStage.show();
} catch(IOException exc) {
logger.error( "error loading fxml", exc );
Alert alert = new Alert(Alert.AlertType.ERROR, "Error loading FXML");
alert.showAndWait();
}
}
private boolean hasShowingChild(Node n) {
if (n == null) {
return false;
}
if (n.isHover()) {
lastHideBlockingNode = n;
return true;
}
try {
Method showingMethod = ClassDescriptions.getMethod(n.getClass(), "isShowing");
if (showingMethod != null && (Boolean) showingMethod.invoke(n)) {
lastHideBlockingNode = n;
return true;
}
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// do nothing
}
if (n instanceof Parent) {
return ((Parent) n).getChildrenUnmodifiable().stream().anyMatch(this::hasShowingChild);
}
return false;
}
@Override
public void start(Stage primaryStage) throws Exception {
SettingsLoader settingsLoader = new SettingsLoader();
settingsLoader.settingsLoaderThread.join();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/homewindow/HomeWindow.fxml"));
Parent homeWindow = loader.load();
Stage dashboardStage = new Stage();
ThemeManager.setTheme(homeWindow);
Rectangle2D screenBounds = Screen.getPrimary().getBounds();
dashboardStage.setWidth(screenBounds.getWidth() * 0.83);
dashboardStage.setHeight(screenBounds.getHeight() * 0.74);
dashboardStage.getIcons().add(new Image(getClass().getResource("/assets/Logo.png").toExternalForm()));
dashboardStage.setScene(new Scene(homeWindow));
dashboardStage.setTitle(APP_NAME);
dashboardStage.show();
}
@Override
public void start(Stage stage) throws Exception {
// set up the scene
FXMLLoader loader = new FXMLLoader(getClass().getResource("/map_reference_scale/main.fxml"));
Parent root = loader.load();
controller = loader.getController();
Scene scene = new Scene(root);
// set up the stage
stage.setTitle("Map Reference Scale Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();
}
private Parent createContent() {
Pane root = new Pane();
root.setPrefSize(800, 600);
NotificationPane pane = new NotificationPane(200, 600);
pane.setTranslateX(800 - 200);
Button btn = new Button("Animate");
btn.setOnAction(e -> {
pane.animate();
});
root.getChildren().addAll(btn, pane);
return root;
}
@Override
public void start(Stage myStage) {
Optional<Parent> root = Optional.empty();
try {
root = Optional.of(FXMLLoader.load(
Main.class.getResource("/views/MainWindow.fxml")
));
} catch (IOException e) {
logger.error(e);
}
root.ifPresent(parent -> {
Scene scene = new Scene(parent);
scene.getStylesheets().add("org/kordamp/bootstrapfx/bootstrapfx.css");
myStage.setMinWidth(900);
myStage.setMinHeight(450);
myStage.setTitle("Image Cipher");
myStage.setScene(scene);
myStage.show();
logger.info("Showing MainWindow");
});
}
public Stage getBuildStage() {
if (buildStage == null) {
try {
Parent root = FXMLLoader.load(getClass().getResource("fxml/apk_build.fxml"));
buildStage = new Stage();
buildStage.setTitle(Main.TITLE);
buildStage.setScene(new Scene(root));
buildStage.initModality(Modality.NONE);
buildStage.initStyle(StageStyle.UNIFIED);
buildStage.setResizable(false);
buildStage.initOwner(Main.stage);
buildStage.setX(Main.stage.getX());
buildStage.setY(Main.stage.getY() + Main.stage.getHeight());
buildStage.setOnShown((event) -> {
});
} catch (Exception e) {
e.printStackTrace();
buildStage = null;
}
}
return buildStage;
}
/**
* Returns the {@link InfiniteCanvas} of the viewer where this action is
* installed.
*
* @return The {@link InfiniteCanvas} of the viewer.
*/
protected InfiniteCanvas getInfiniteCanvas() {
Parent canvas = getViewer().getCanvas();
if (canvas instanceof InfiniteCanvas) {
return (InfiniteCanvas) canvas;
}
return null;
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("Backpressure.fxml"));
stage.setTitle("Reactive-gRPC Backpressure Demo");
stage.setScene(new Scene(root, 800, 450));
stage.show();
}
private Scene getScene(Parent root) {
Scene scene = new Scene(root);
if (QueleaProperties.get().getUseDarkTheme()) {
scene.getStylesheets().add("org/modena_dark.css");
}
return scene;
}
@Override
public void start(Stage stage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/main.fxml"));
stage.setScene(new Scene(root));
} catch (IOException e) {
e.printStackTrace();
}
stage.initStyle(StageStyle.UNDECORATED);
App.stage = stage;
stage.show();
}
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("hellofx.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 400, 300));
primaryStage.show();
}
/**
* 启动一个Activity
*
* @param url 界面布局文件url
* @param pos 界面位置
*/
public static void startActivity(URL url, Pos pos){
try {
Parent view = FXMLLoader.load(url);
StackPane.setAlignment(view, pos);
getRootView().getChildren().add(view);
} catch (IOException e) {
e.printStackTrace();
}
}
private void showDebugWindow(Scene scene, Injector injector) {
ViewLoader viewLoader = injector.getInstance(ViewLoader.class);
View debugView = viewLoader.load(DebugView.class);
Parent parent = (Parent) debugView.getRoot();
Stage stage = new Stage();
stage.setScene(new Scene(parent));
stage.setTitle("Debug window"); // Don't translate, just for dev
stage.initModality(Modality.NONE);
stage.initStyle(StageStyle.UTILITY);
stage.initOwner(scene.getWindow());
stage.setX(this.stage.getX() + this.stage.getWidth() + 10);
stage.setY(this.stage.getY());
stage.show();
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/genuinecoder/main/main.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Genuine Coder");
stage.show();
}
@FXML
private void addPokemonAction() throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getClassLoader().getResource("pokemonregister/View/PokemonDisplay.fxml"));
Parent root = loader.load();
PokemonDisplayController displayController = loader.getController();
displayController.setScreenData(stage, DisplayMode.CREATE_POKEMON);
Scene scene = new Scene(root);
stage.setScene(scene);
}
public void restoreWindow(FxWindow w)
{
String windowPrefix = lookupWindowPrefix(w);
LocalSettings settings = LocalSettings.find(w);
if(settings != null)
{
String k = windowPrefix + FxSchema.SFX_SETTINGS;
settings.loadValues(k);
}
FxSchema.restoreWindow(windowPrefix, w);
Parent p = w.getScene().getRoot();
FxSchema.restoreNode(windowPrefix, p, p);
}
@Override
public void start(Stage primaryStage) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("EntitasGenerator.fxml"));
Parent root = loader.load();
primaryStage.setTitle("CodeGenerator");
primaryStage.setScene(new Scene(root, 560, 575));
primaryStage.setResizable(false);
primaryStage.show();
stage = primaryStage;
}
@Override
public void start(Stage stage) throws IOException {
// set up the scene
FXMLLoader loader = new FXMLLoader(getClass().getResource("/terrain_exaggeration/main.fxml"));
Parent root = loader.load();
controller = loader.getController();
Scene scene = new Scene(root);
// set up the stage
stage.setTitle("Terrain Exaggeration Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("靓号助手");
Parent root = FXMLLoader.load(getClass().getResource("/app.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/scan.ico")));
primaryStage.show();
}
@Override
protected void unregister() {
if (zoomListener == null) {
throw new IllegalStateException(
"Zoom listener not yet registered.");
}
Parent canvas = getViewer().getCanvas();
if (canvas instanceof InfiniteCanvas) {
((InfiniteCanvas) canvas).getContentTransform().mxxProperty()
.removeListener(zoomListener);
zoomListener = null;
}
}