JavaFXطريقة وضع محتوى النافذة في BorderPane
المثال التالي يعلمك طريقة إنشاء كائن من الكلاس BorderPane و وضعه كـ Root Node.
مثال
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
@Override
public void start(Stage stage) {
// في النافذة Root Node و الذي ننوي جعله الـ BorderPane هنا قمنا بإنشاء كائن من الكلاس
BorderPane root = new BorderPane();
// root هنا قمنا بإنشاء جميع الأشياء التي سنضيفها في الكائن
Button buttonCenter = new Button("Center");
Button buttonTop = new Button("Top");
Button buttonRight = new Button("Right");
Button buttonBottom = new Button("Bottom");
Button buttonLeft = new Button("Left");
// root هنا قمنا بتحديد موقع كل شيء سيتم إضافته في الكائن
root.setCenter(buttonCenter);
root.setTop(buttonTop);
root.setRight(buttonRight);
root.setBottom(buttonBottom);
root.setLeft(buttonLeft);
// فيها و تحديد حجمها Node كأول root هنا قمنا بإنشاء محتوى النافذة مع تعيين الكائن
Scene scene = new Scene(root, 350, 250);
// هنا وضعنا عنوان للنافذة
stage.setTitle("JavaFX BorderPane");
// أي وضعنا محتوى النافذة الذي قمنا بإنشائه للنافذة .stage في كائن الـ scene هنا وضعنا كائن الـ
stage.setScene(scene);
// هنا قمنا بإظهار النافذة
stage.show();
}
// هنا قمنا بتشغيل التطبيق
public static void main(String[] args) {
launch(args);
}
}
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
@Override
public void start(Stage stage) {
// في النافذة Root Node و الذي ننوي جعله الـ BorderPane هنا قمنا بإنشاء كائن من الكلاس
BorderPane root = new BorderPane();
// root هنا قمنا بإنشاء جميع الأشياء التي سنضيفها في الكائن
Button buttonCenter = new Button("Center");
Button buttonTop = new Button("Top");
Button buttonRight = new Button("Right");
Button buttonBottom = new Button("Bottom");
Button buttonLeft = new Button("Left");
// root هنا قمنا بتحديد موقع كل شيء سيتم إضافته في الكائن
root.setCenter(buttonCenter);
root.setTop(buttonTop);
root.setRight(buttonRight);
root.setBottom(buttonBottom);
root.setLeft(buttonLeft);
// فيها و تحديد حجمها Node كأول root هنا قمنا بإنشاء محتوى النافذة مع تعيين الكائن
Scene scene = new Scene(root, 350, 250);
// هنا وضعنا عنوان للنافذة
stage.setTitle("JavaFX BorderPane");
// أي وضعنا محتوى النافذة الذي قمنا بإنشائه للنافذة .stage في كائن الـ scene هنا وضعنا كائن الـ
stage.setScene(scene);
// هنا قمنا بإظهار النافذة
stage.show();
}
// هنا قمنا بتشغيل التطبيق
public static void main(String[] args) {
launch(args);
}
}
ستظهر لك النافذة التالية عند التشغيل.