My question is possible with Javafx Scene Builder show the webpage or html file?
Thanks a lot.
You can not "browse" the web with JavaFX Scene Builder directly, no.
But you can add the WebView Control element to your scene graph and use this component to browse the internet or local HTML files, see the corresponding documentation of WebView and WebEngine.
It's work.
First step is build to the Scene Builder the AnchorePane thereon StackPane thereon WebView.
The code:
#FXML
private WebView web;
#FXML
private StackPane root;
public void initialize() {
WebEngine engine = web.getEngine();
//engine.load("https://www.google.com/maps");
final URL urlGoogleMaps = getClass().getResource("GoogleMapsV3.html");
engine.load(urlGoogleMaps.toExternalForm());
engine.setJavaScriptEnabled(true);
root.getChildren().add(web);
}
Thanks a lot.
Related
This question already has an answer here:
How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?
(1 answer)
Closed 2 years ago.
I have a file named Home.fxml which is a BorderPane. This component has buttons on the left and an empty TabPane called mainTabPane in the centre. I would like, when a user clicks on any button on the left, to add a tab to mainTabPane. I am able to add one tab when one button is clicked. But when I try to do the same for the second button, I get this error:
java.lang.IllegalStateException: Location not set
Here is the code for HomeController.java, where all is done:
public void initialize(URL loc, Resource Rse) {
createReportsTab();
loadCreateItemTab();
}
/*this is the one which works well*/
#FXML
void CreateReportTab() {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(ReportsController.class.getResource("gui/Reports.fxml"));
Parent parent = loader.load();
Tab reportsTab = new Tab("Reporting Engine");
reportsTab.setClosable(true);
reportsTab.setcontent(parent);
mainTabPane.getTabs().add(reportsTab),
}
/*this is the one which produces the error*/
#FXML
void loadCreateItemTab() {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(AddNewItemController.class.getResource("gui/addNewItem.fxml"));
Parent parent = loader.load();
Tab newItemTab= new Tab("New Item");
newItemTab.setClosable(true);
newItemTab.setcontent(parent);
mainTabPane.getTabs().add(newItemTab),
}
I am confused; why the Reporting Engine loads well but the second one is producing that error above?
Here is my project structure in IntelliJ IDEA:
All controller classes are in the controllers package and all FXML files are in the GUI package. The main class is in Companion package.
Error suggests that addNewItem.fxml is not read. Change:
AddNewItemController.class.getResources("gui/addNewItem.fxml");
to
ReportsController.class.getResources("gui/addNewItem.fxml");
, since this path worked for you already.
I am trying my way through JavaFX and still have many - probably silly - beginner questions.
My problem of the day is the following:
I am creating, in Scene builder and Controller, a FlowPane to which I want to add a right-click option, that opens a Context Menu.
Through the scene builder I have added the function OnContextMenuRequested and defined it in the Controller.
To check, I have added a print commend and a Dialog Box to the function, which work well.
Yet, the Context Menu does not work..
Anybody could help and tell me what am I missing???
Thanks in advance...
public void contextMenu(ContextMenuEvent contextMenuEvent) {
// working fine ..
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Information");
alert.setHeaderText("Look");
alert.setContentText("Message");
alert.showAndWait();
// working fine
System.out.println("Hello");
// Context Menu ......... not working
ContextMenu contextMenu = new ContextMenu();
MenuItem quit = new MenuItem("quit");
MenuItem hello = new MenuItem("hello");
contextMenu.getItems().addAll(quit, hello);
contextMenu.setX(10.0);
contextMenu.setY(10.0);
contextMenu.show();
????.setContextMenu(????)
}
Unless you have a control, you need to show the ContextMenu "manually" using one of the methods defined in ContextMenu:
// contextMenu.setX(10.0);
// contextMenu.setY(10.0);
contextMenu.show((Node) contextMenuEvent.getSource(), contextMenuEvent.getScreenX(), contextMenuEvent.getScreenY());
I'm new to JavaFX and i have a little problem with the UI.
I'm using JavaFX 8 and want to create my UI with FXML files.
I have created a pane with a header, a menubar and the placeholder for the content (This is the place where i want to load the others FXML files in when i press a Button from the menu bar). The content area is a AnchorPane.
I have tryed it with this:
#FXML
private AnchorPane aContent;
#FXML
protected void test(ActionEvent event) {
aContent.getChildren().setAll(FXMLLoader.load("view/ezMovieContent.fxml"));
}
The AnchorPane aContent is the content area in my scene. When i use this code i always get the message on the load() method
The method load(InputStream) in the type FXMLLoader is not applicable for the arguments (String)
Thank you for your help,
With regards, Timo
I'm new at Stackoverflow and Javafx (and Java at all), so my question can be stupid.
I have a .fxml file with main window (it's include LineChart) and Controller.java, binded to it. And I need make new window with chart options (color and thickness of line). I'm making window with options by event, binded on menuItem in main window.
So, how I can change properties of chart in main window from options window?
I don't understand at all how to get access to LineChart in main window!
This is how I open options window:
void showSettings(ActionEvent event)
throws IOException {
Group root = new Group();
Stage stage = new Stage();
AnchorPane frame = FXMLLoader.load(getClass().getResource("options.fxml"));
root.getChildren().add(frame);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
Can anybody help me?
P.S. Sorry for my bad English level :c
Edit1: I need pass params from new window(options) to already existing (main)!
I want to make a button on an AnchorPane without drag it from the library in the FXML file I want to do it progammatically: if the search button clicked, should show a new button not existed in the AnchorPane before I did this code but I don't know what is wrong with it:
private void searchButton(ActionEvent evt) {
Button tab = new Button();
tab.setLayoutX(147);
tab.setLayoutY(102);
tab.setText("Tab1");
tab.setPrefHeight(27);
tab.setPrefWidth(69);
WebView wb = new WebView();
wb.setLayoutX(-1);
wb.setLayoutY(128);
wb.setPrefWidth(1604);
wb.setPrefWidth(700);
}
I am assuming that you searchButton method is in controller attached to some FXML. Then all you need to do is this:
yourAnchorPane.getChildren().add(tab);
If you don't have already published reference to anchorPane in your controller, then add this into your controller
#FXML
AnchorPane yourAnchorPane;
And in SceneBuilder select your anchorPane, go to code tab and enter "yourAnchorPane" as fx:id.
Further info on working with anchorpane is javadoc.
You probably also want to set some constraints on the tab to locate it at a position within the AnchorPane. For instance, the following code will locate your button tab relative to the top left corner of the AnchorPane: Ten pixels down and fifteen pixels to the right.
AnchorPane.setTopAnchor(tab, 10.0);
AnchorPane.setLeftAnchor(tab, 15.0);