Как заставить StackPane заполнить BorderPane в JavaFXJAVA

Программисты JAVA общаются здесь
Anonymous
Как заставить StackPane заполнить BorderPane в JavaFX

Сообщение Anonymous »

У меня есть простой класс JavaFX, который для этого вопроса структурирован следующим образом.

Код: Выделить всё

BorderPane
StackPane
FlowPane
BorderPane содержит StackPane, который содержит FlowPane.

Теперь я уже несколько дней пытаюсь заполнить эту StackPane его родительский элемент BorderPane, но, похоже, ничего не работает. Конечным результатом должен стать красный фон StackPane.

Код:

Код: Выделить всё

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
*
* @author A4XX-COLCRI
*/
public class LogicGatesSimulator extends Application {
/**
* The root node of the application.
*/
Group root;
/**
* This is the top-level container child of root.
*/
BorderPane mainContainer;
/**
* Contains the canvas and represents the drawing area.
*/
Pane canvasContainer;
/**
* Defines where all the shapes will be drawn.
*/
Canvas canvas;
/**
* Defines the toolbox pane.
*/
StackPane toolboxPane;
/**
* Defines the toolbox flowpane.
*/
FlowPane toolbox;
/**
* Defines the top bar menu.
*/
MenuBar menu;

@Override
public void start(Stage primaryStage) {
// Inizializzazione degli elementi grafici
root = new Group();
mainContainer = new BorderPane();
canvasContainer = new Pane();
canvas = new Canvas();
toolboxPane = new StackPane();
toolboxPane.setStyle("-fx-background-color: red; ");
toolbox = new FlowPane(Orientation.VERTICAL);
toolbox.setPrefWrapLength(250);
toolbox.minWidth(Region.USE_COMPUTED_SIZE);
toolbox.minHeight(Region.USE_COMPUTED_SIZE);
toolbox.maxWidth(Region.USE_COMPUTED_SIZE);
toolbox.maxHeight(Region.USE_COMPUTED_SIZE);
toolbox.prefHeight(Region.USE_COMPUTED_SIZE);
//toolbox.setStyle("-fx-background-color: red;");

// Inizializzazione scena
Scene scene = new Scene(root, 1280, 800);
primaryStage.setTitle("Logic Gates Simulator");
primaryStage.setScene(scene);

// Menu
menu = new MenuBar();
Menu menuFile = new Menu("File");
Menu menuEdit = new Menu("Edit");
Menu menuView = new Menu("View");
Menu menuAbout = new Menu("About");
menu.getMenus().addAll(menuFile, menuEdit, menuView, menuAbout);

// Porte logiche nella toolbox
ImageView andImage = new ImageView(getClass().getResource("images/and.png").toExternalForm());
ImageView nandImage = new ImageView(getClass().getResource("images/nand.png").toExternalForm());
ImageView orImage = new ImageView(getClass().getResource("images/or.png").toExternalForm());
ImageView norImage = new ImageView(getClass().getResource("images/nor.png").toExternalForm());
ImageView xorImage = new ImageView(getClass().getResource("images/xor.png").toExternalForm());
ImageView xnorImage = new ImageView(getClass().getResource("images/xnor.png").toExternalForm());
ImageView notImage = new ImageView(getClass().getResource("images/not.png").toExternalForm());

// Strutturazione
toolboxPane.getChildren().add(toolbox);
mainContainer.setLeft(toolboxPane);
mainContainer.setRight(canvasContainer);
toolbox.getChildren().addAll(andImage, nandImage, orImage, norImage, xorImage, xnorImage, notImage);
canvasContainer.getChildren().add(canvas);
root.getChildren().add(mainContainer);

// Mostra la scena
primaryStage.show();
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Фото моего работающего приложения

Изображение


Итак, по сути, эта левая область должна полностью заполнять левую часть моей BorderPane, таким образом фон должен правильно покрывать его область.
Я также пробовал изменить его со StackPane на AnchorPane и установить для TopAnchor, LeftAnchor и т. д. значение 0, но это не работает.
Спасибо.

Подробнее здесь: https://stackoverflow.com/questions/414 ... -in-javafx

Вернуться в «JAVA»