열쇠는 Monospaced
font
을 사용해야합니다.
코드 버전 :
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;
/**
*
* @author blj0011
*/
public class JavaFXApplication42 extends Application {
@Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
Label label = new Label("Hello World");
label.setFont(Font.font("Monospaced"));
label.setWrapText(true);
label.setMinWidth(1);
label.setPrefWidth(1);
label.setMaxWidth(1);
root.getChildren().add(label);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
FXML 버전 :
?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label layoutX="296.0" layoutY="81.0" prefHeight="198.0" prefWidth="0.0" text="HELLO WORLD" wrapText="true" />
</children>
</Pane>
텍스트 래핑 사용 – Mordechai
@MouseEvent가 label5.setWrapText (true)를 예로 들자면, – Matt