She lives in St. Prior to her assignment at Oracle, she worked as a technical writer in different IT companies. The embedded browser component is based on WebKit , an open source web browser engine. DOM Support for domain names written in national languages Embedded Browser API The embedded browser inherits all fields and methods from the Node class, and therefore, it has all its features.
|Published (Last):||13 March 2011|
|PDF File Size:||9.63 Mb|
|ePub File Size:||12.57 Mb|
|Price:||Free* [*Free Regsitration Required]|
She lives in St. Prior to her assignment at Oracle, she worked as a technical writer in different IT companies.
The embedded browser component is based on WebKit , an open source web browser engine. DOM Support for domain names written in national languages Embedded Browser API The embedded browser inherits all fields and methods from the Node class, and therefore, it has all its features. The classes that constitute the embedded browser reside in the javafx. Figure 1 shows the architecture of the embedded browser and how it relates to other JavaFX classes. It supports user interaction such as navigating links and submitting HTML forms, although it does not interact with users directly.
The WebEngine class handles one web page at a time. Two constructors enable you to create a WebEngine object: an empty constructor and a constructor with the specified URL. If you instantiate an empty constructor, the URL can be passed to a WebEngine object through the load method. User style sheets replace the default styles on the pages rendered in this WebEngine instance with user-defined ones.
The getEngine method called on a WebView object returns a web engine associated with it. Example 1 shows the typical way to create WebView and WebEngine objects in your application. When you need to open a new browser window in your application, the instances of this class are passed into pop-up handlers registered on a WebEngine object by using the setCreatePopupHandler method as shown in Example 2. To open the target document in another window, specify the WebEngine object of another web view.
When you need to block the pop-up windows, return the null value. The WebViewSample class of the application creates the scene and adds a Browser object to the scene. Example 3 shows how to add the WebView component to the application scene. Example 3 Creating a Browser import javafx.
Application; import javafx. HPos; import javafx. VPos; import javafx. Node; import javafx. Scene; import javafx. HBox; import javafx. Priority; import javafx. Region; import javafx. Color; import javafx. WebEngine; import javafx. WebView; import javafx.
The WebView object that contains this web engine is added to the application scene by using the getChildren and add methods. The createSpacer, layoutChildren, computePrefWidth, and computePrefHeight methods perform layout of the WebView object and the control elements in the application toolbar. When you add, compile, and run this code fragment, it produces the application window shown in Figure 2.
Study the modified code of the Browser class shown in Example 4. It adds URLs for alternative web resources including Oracle products, blogs, Java documentation, and the partner network.
The code fragment also creates a toolbar and adds the hyperlinks to it. Example 4 Creating a Toolbar import javafx. ActionEvent; import javafx. EventHandler; import javafx. Hyperlink; import javafx. Image; import javafx. ImageView; import javafx. The setOnAction method defines the behavior of the hyperlinks.
When a user clicks a link, the corresponding URL value is passed to the load method of the webEngine. When you compile and run the modified application, the application window changes as shown in Figure 3. The modified application code in Example 5 creates an additional button to hide and show the Java SE documentation for the previous releases.
The button is added to the toolbar only when the Documentation page is selected. Example 5 Adding the Toggle Previous Docs button import javafx. ChangeListener; import javafx. ObservableValue; import javafx.
State; import javafx. Event; import javafx. Pos; import javafx. Button; import javafx. Methods that initiate loading return immediately after scheduling a background job.
For the WebViewSample application, you create the Help toolbar item that leads to the help. By clicking the Exit the Application link in the help. Modify the application, as shown in Example 7 , to implement this functionality. Platform; import javafx. Stage; import netscape.
The page contains links to the Java tutorials, developer guides, and API documentation. Popular resources and membership opportunities. Figure 6 Help Icon Click Help to load the help. Examine the content of the file, then click the Exit the Application link, shown in Figure 7 , to close the WebViewSample application. Figure 7 Help.
Figure 8 shows a context menu a user can open by right-clicking any link. Figure 8 Pop-Up Window To specify a new browser window for the target document, use the PopupFeatures instance as shown in the modified application code in Example 9. PopupFeatures; import javafx. Stage; import javafx.
Callback; import netscape. This behavior is defined by the setCreatePopupHandler method, which returns the web engine of an alternative browser to notify the application where to render the target page.
The result of compiling and running the modified application is shown in Figure 9. To disable a context menu for a particular WebView instance, pass the false value to the setContextMenuEnabled method: browser. It represents a session history associated with a WebEngine object.
Use the WebEngine. The history is basically a list of entries. Each entry represents a visited page and it provides access to relevant page info, such as URL, title, and the date the page was last visited.
The list can be obtained by using the getEntries method. The history list changes as users navigate through the web. You typically use a standard or custom UI control to display the history list. Example 10 shows how to obtain a history items and present them in the ComboBox control.
When users select any item in the combo box, the web engine is navigated to the URL defined by the history entry item, which position in the list is defined by the offset value.
A negative offset value specifies the position preceding the current entry, and a positive offset value specifies the position following the current entry. Example 11 shows the complete code of the modified application. ListChangeListener; import javafx. Change; import javafx. ComboBox; import javafx. WebHistory; import javafx. Entry; import javafx. To further enhance this application, you can apply effects, transformations and animated transitions, and even add more WebView instances.
Related API Documentation.
Subscribe to RSS
Die Anleitung zu JavaFX WebView und WebEngine
Release: JavaFX 2.2