Tartalomjegyzék

< Java FX

JavaFX - Operációs rendszer

Kilépés

import javafx.application.Platform;
//...
Button exitButton = new Button("Kilépés");
exitButton.setOnAction(event -> {
    Platform.exit();
});
Button exitButton = new Button("Kilépés");
exitButton.setOnAction(event -> {
    System.exit(0);
});

Vágólap

Másolás

MainController.java
package com.example;
 
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
 
public class MainController {
 
    @FXML
    private TextArea editorArea;
 
    @FXML
    void onClickCopyButton(ActionEvent event) {
        startCopy();
    }
    private void startCopy() {
        String editorText = editorArea.getSelectedText();
        Clipboard clipboard = Clipboard.getSystemClipboard();
        ClipboardContent content = new ClipboardContent();
        content.putString(editorText);
        clipboard.setContent(content);
    }
 
}

Beillesztés

    @FXML
    void onClickPasteButton(ActionEvent event) {
        startPaste();
    }
 
    private void startPaste() {
        Clipboard clipboard = Clipboard.getSystemClipboard();
        String content = clipboard.getString();
        int cursorPosition = editorArea.getCaretPosition();
        editorArea.insertText(cursorPosition,content);
    }

Kivágás

    @FXML
    void onClickCutButton(ActionEvent event) {
        startCut();
    }
 
    private void startCut() {
        String editorText = editorArea.getSelectedText();
        editorArea.deleteText(editorArea.getSelection());
        Clipboard clipboard = Clipboard.getSystemClipboard();
        ClipboardContent content = new ClipboardContent();
        content.putString(editorText);
        clipboard.setContent(content); 
    }