JavaFX etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
JavaFX etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

16 Aralık 2019 Pazartesi

JavaFX SwingNode Sınıfı

Giriş
JavaFX içinde Swing kullanabilmeyi sağlar.

setContent metodu
JavaFX içinde belirtilen swing bileşeni gösterir.

Örnek
Şu satırı dahil ederiz.
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.embed.swing.SwingNode;

import javax.swing.JFileChooser;
import javax.swing.SwingUtilities;
Şöyle yaparız.
public class JunkFx extends Application {
  public void openDialog(MouseEvent event) {
    JFileChooser fileChooser = new JFileChooser("why");
    SwingNode swingNode = new SwingNode();

    SwingUtilities.invokeLater(() -> {
      swingNode.setContent(fileChooser);
    });

    BorderPane pane = new BorderPane();
    pane.setCenter(swingNode);

    Stage stage = new Stage();

    Scene scene = new Scene(pane, 500, 500);
    stage.setScene(scene);
    stage.show();

    fileChooser.addActionListener(evt->{
      System.out.println(evt.getActionCommand());
      System.out.println(fileChooser.getSelectedFile());
      Platform.runLater(stage::hide);
    });

  }

  @Override
  public void start(Stage stage) throws Exception {
    Button b = new Button("click");
    b.setOnMouseClicked(this::openDialog);
    Scene scene = new Scene(new StackPane(b), 640, 480);
    stage.setTitle("open a dialog");
    stage.setScene(scene);
    stage.show();
  }

  public static void main(String[] args){
    launch(args);
  }
}

20 Kasım 2019 Çarşamba

JavaFX FXMLLoader Sınıfı

Giriş
Bu sınıfın yüklediği bileşen Scene ile kullanılabilir. Açıklaması şöyle. 
... you can create a JavaFX user-interface by taking two different approaches:

1. Define all objects in pure Java code.
2. Use XML-based layout files (FXML) that integrate with Java code.
Örnek
Şöyle yaparız.
Parent root = FXMLLoader.load(...);
Scene scene = new Scene(root);
Örnek
Ana ekranı açmak için şöyle yaparız.
FXMLLoader fxmlLoader = new FXMLLoader(chartResource.getURL());
Parent parent = fxmlLoader.load();
Stage stage = ...
stage.setScene(new Scene(parent, 800, 600));
stage.show();
load metodu
Örnek
Dosyadan yüklemek için şöyle yaparız.
FXMLLoader.load(new URL("file:////Login.fxml"));
Örnek
Şöyle yaparız.
Parent root = FXMLLoader.load(
  getClass().getClassLoader().getResource("scenes/Login.fxml"));