iFocus.Life News News - Breaking News & Top Stories - Latest World, US & Local News,Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The iFocus.Life,

Java Code:

106 18
This example code listing of a JavaFX application shows how to use the HTMLEditor control. The HTMLEditor is created and populated with some random French text. A button at the bottom of the scene can be used to retrieve the underlying HTML from the HTMLEditor and append it to the existing text.

The article that goes with this code listing is the HTMLEditor Overview.To find out about other JavaFX controls have a look at JavaFX User Interface Controls.

import javafx.application.Application;import javafx.geometry.Pos;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.scene.Scene;import javafx.stage.Stage;import javafx.scene.web.HTMLEditor;import javafx.scene.control.Button;import javafx.scene.layout.HBox;import javafx.scene.layout.VBox;public class HtmlEditorExample extends Application {@Overridepublic void start(Stage primaryStage) { //Use VBOX layout pane to space out the controls //in a single centered column VBox controlBox = new VBox(10); controlBox.setAlignment(Pos.CENTER);//Create HTMLEditor final HTMLEditor editor = new HTMLEditor();//Some french random generated textString randomFrenchText = "<html><body><h2>Gardait sur diables bossuee beffroi ces oui mes tendues humains</h2><p>Je rangs"+ " voyez il eu voila ii. Pu prenaient crepitent qu fusillade. Sont sol sur eau chez afin deja pour crie. "+ "Ses ils haut sons rire. Esprit tempes les vin jusque galons heures roc trotte. On suffisait le abondance la lanternes qu. "+ "Havresac bravoure ah activite ouvriers la.</p><p>Les jet autant courts espace. Amertume jeu bataille sciences par fillette dur. "+ "Suffisait as me positions connaitre. Son allaite aux accourt etirant battant chevaux grosses. "+ "Caracolent prisonnier si admiration approchait survivants au etonnement. Ruer te il pris soit. "+ "Philippe bouleaux colonnes nos vin ras attentif fin branches fenetres. "+ "Troupe pierre ont sol ici croyez est jurons parler metres. Pris ere cela aux six soit. "+ "Poussaient ils eau remarquent car chantaient.</p><p>Prudence profonde coupoles prennent roc pas precieux pourquoi. "+ "Ennemies massacre triomphe les cavernes des six toi. Je or devant blason palais et epouse sa atroce. "+ "Se on rendre ah sortit annees jusque jambes voyage. Chantant traverse soutenir net campagne sur remettre. "+ "Demeurons cet six art toutefois resterait les. Firmament sortaient net echauffer aux reprendre preferait eux.</p>"+ "<p>Regarde jeu charges faisans banques obtenue mes des lui. Contemple me tu instruite enfantent oh. Est plein verre"+ "femme par non. Ses car fourneaux printemps que distribua ici dernieres citadelle. Sifflent nid ses aussitot ere trophees."+ "Exploits reparler bataille parterre sanglees nul mon dit allaient. Ou partageait subitement descendons sa estaminets.</p>"+ "<p>Tout ont nez feu fait peu pale. Les rirez mal osait son sacre. Hate pres va crie main sa cime. Un premier devenir lecture"+ "qu minutes oh ai musique. Promenade ras ton que divergent annoncait. Des rougeatres executeurs compagnies iii ordonnance petitement"+ "simplement. Porta decor dites savez ifs toi train. Pouvaient ah lanternes portieres oh cartouche ca ah toutefois." + "Devant intime saules que sur.</p>" + "</body></html>";//populated the HTMLEditor with the text editor.setHtmlText(randomFrenchText);//Button to append text in the editor Button addText = new Button("Select and Append Text");//add an actionlistener to the button to append//all the text in the editor to the bottom of the existing text addText.setOnAction(new EventHandler<ActionEvent>() {@Override public void handle(ActionEvent arg0) {String text = editor.getHtmlText() + "\n" + editor.getHtmlText();editor.setHtmlText(text);}});//Add the Editor and Button to //position the layout panescontrolBox.getChildren().add(editor);controlBox.getChildren().add(addText);//Add the main HBOX layout pane to the sceneScene scene = new Scene(controlBox, 1000, 600);//Show the formprimaryStage.setTitle("Html Editor Example");primaryStage.setScene(scene);primaryStage.show();}/** * @param args the command line arguments */public static void main(String[] args) {launch(args);}}
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time
You might also like on "Technology"

Leave A Reply

Your email address will not be published.