< Java FX

JavaFX - Operációs rendszer

Szerző: Sallai András

Copyright © 2024, Sallai András

Licenc: CC BY-SA 4.0

Web: https://szit.hu

Kilépés

Button exitButton = new Button("Kilépés"); exitButton.setOnAction(event -> { Platform.exit(); System.exit(0); // A JVM-t kikapcsolása });

Vágólap

Másolás

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); }