W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵(lì)
HTMLEditor控件是一個(gè)富文本編輯器,具有以下功能。
HTMLEditor類返回HTML字符串中的編輯內(nèi)容。
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.web.HTMLEditor; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage stage) { HTMLEditor htmlEditor = new HTMLEditor(); htmlEditor.setPrefHeight(245); Scene scene = new Scene(htmlEditor); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }
上面的代碼生成以下結(jié)果。
要將內(nèi)容設(shè)置為HTMLEditor類,請使用setHtmlText方法。
htmlEditor.setHtmlText(INITIAL_TEXT);
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.web.HTMLEditor; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage stage) { HTMLEditor htmlEditor = new HTMLEditor(); htmlEditor.setPrefHeight(245); String INITIAL_TEXT = "Lorem ipsum dolor sit " + "amet, consectetur adipiscing elit. Nam tortor felis, pulvinar " + "aliquam sagittis gravida eu dolor. Etiam sit amet ipsum " + "sem."; htmlEditor.setHtmlText(INITIAL_TEXT); Scene scene = new Scene(htmlEditor); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }
上面的代碼生成以下結(jié)果。
我們可以使用此字符串中的HTML標(biāo)記為最初渲染的內(nèi)容應(yīng)用特定的格式。
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.web.HTMLEditor; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage stage) { HTMLEditor htmlEditor = new HTMLEditor(); htmlEditor.setPrefHeight(245); String INITIAL_TEXT = "Lorem ipsum dolor sit " + "amet, consectetur adipiscing elit. <i>Nam tortor felis</i>, pulvinar " + "<UL><li>a</li><li>a</li><li>a</li></UL>" + "aliquam sagittis gravida <b>eu dolor</b>. Etiam sit amet ipsum " + "sem."; htmlEditor.setHtmlText(INITIAL_TEXT); Scene scene = new Scene(htmlEditor); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }
上面的代碼生成以下結(jié)果。
import javafx.application.Application; import javafx.event.ActionEvent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.VBox; import javafx.scene.web.HTMLEditor; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage stage) { HTMLEditor htmlEditor = new HTMLEditor(); htmlEditor.setPrefHeight(245); String INITIAL_TEXT = "Lorem ipsum dolor sit " + "amet, consectetur adipiscing elit. <i>Nam tortor felis</i>, pulvinar " + "<UL><li>a</li><li>a</li><li>a</li></UL>" + "aliquam sagittis gravida <b>eu dolor</b>. Etiam sit amet ipsum " + "sem."; htmlEditor.setHtmlText(INITIAL_TEXT); Button showHTMLButton = new Button("Produce HTML Code"); showHTMLButton.setOnAction((ActionEvent arg0) -> { System.out.println(htmlEditor.getHtmlText()); }); VBox vbox = new VBox(); vbox.getChildren().addAll(htmlEditor,showHTMLButton); Scene scene = new Scene(vbox); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }
上面的代碼生成以下結(jié)果。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: