Code is at https://bpaste.net/show/b7aa0530f2ac (because of StackOverflow limitations)
I'm currently trying to use
//Menu.java
btn.setOnAction(event -> {
primaryStage.setScene(doubleclick);
});
to change scene from current scene to Scene doubleclick but it isn't found because it is in another class (Mouse.java). Also the variables in that class are needed for it to work. I've tried to copy over the code from Mouse.java to Menu.java but I don't know how to make that work.
So when I click button in the image above I see what is below:
...instead of the first content (main menu).
Related
I am new to Java FX and trying to build up an "easy" application which consists of a header button bar and a "content area" below.
I've managed a big part like that:
MainWindow.fxml with a Borderpane: MenuBar in the Top Area
And a Pane with fx:id: content in the center area.
Several X.fxml files for the content ()
One Controller which creates the obj content:
#FXML
private Pane content;
and switches the content:
content.getChildren().clear();
content.getChildren().add(FXMLLoader.load(getClass().getResource("Navi.fxml")));`
Main file which initializes the parent and scene:
Parent root = FXMLLoader.load(getClass().getResource("MainWindow.fxml"));
Stage Window = primaryStage;
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
Window.setTitle("ICIS - In Car Interactive System");
Window.setScene(scene);
Window.show();`
So far everything works fine!
But now I want to apply a SplitPane and do the "content change" in each side of the Split Pane (TwoWindows.fxml): So I've extended the
Controller with obj. for every Pane of the Split Pane, assigned the fx:id to that pane and want to control them analog to the example before.
#FXML
private Pane SecondWindow1;
SecondWindow1.getChildren().add(FXMLLoader.load(getClass().getResource("Navi.fxml")));
Well, during compilation everything is fine, but while running I get the Null error exception, so that I assume SecondWindow1 (left half of SlitPane) is not known to the controller.
I also assume, it is because I initialize at the beginning only MainWindow.fxml (which includes the content area) but not the TwoWindows.fxml (SplitPane) which inlcude the SecondWindow1 Object.
Well I've tried since hours now to solve it, but apparently I am overlooking sth. Somebody knows how to fix that problem? Do I need one Controller for every FXML File?
I'm working with treeview in javaFx, I want to put an icon to the root node, and other icon for every child. I was trying to put it at least to the root node, but it still shows me the arrow, I declare the node in the next way:
TreeItem<Object> rootNode = new TreeItem<Object>("Agentes");
rootNode.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/images/A.png"))));
I have the image "A.png" in a package called application.images
, and my loader class is Main.java is located in application, this is my directory:
when I run the application this is the treeview that I get:
it doesn't show me error or something like this. I must say, A.png is a image with 16x16Pixels. I don't know what I'm doing wrong, Thanks!
I resolved it, putting setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/images/A.png")))); into the updateItem( Object item, boolean empty ) method in the a class that extends from TreeCell
I am looking to figure out how to set the text of a label on an external Application Window.
What I have:
I have two windows so far. The first one is the main application window that will appear when the user starts the program. The second window is another separate window that I have created specifically to display a custom error window.
The problem: I seem to be unable to call the label that I have created on the error window and set the text to something custom. Why? I want to be able to reuse this window many times! This window is aimed for things like error handling when there is invalid input or if the application cannot read/save to a file.
I was going to post screen shots but you need 10 rep for that. It would have explained everything better.
Here is the code for the label on the Error_dialog window:
Label Error_label = new Label(container, SWT.NONE);
Error_label.setBounds(10, 10, 348, 13);
Error_label.setText("Label I actively want to change!");
Here is the condition I would like to fire off when it is met:
if(AvailableSpaces == 10){
//Set the label text HERE and then open the window!
showError.open();
}
I have included this at the top of the class as well:
Error_dialog showError = new Error_dialog();
Just save the label as a field in your dialog class and add a 'setter' method. Something like:
public class ErrorDialog extends Dialog
{
private Label errorLabel;
... other code
public void setText(String text)
{
if (errorLabel != null && !errorLabel.isDisposed()) {
errorLabel.setText(text);
}
}
You will need to use your dialog like this:
ErrorDialog dialog = new ErrorDialog(shell);
dialog.create(); // Creates the controls
dialog.setText("Error message");
dialog.open();
Note: you should stick to the rules for Java variable names - they always start with lower case.
Further learn to use Layouts. Using setBounds will cause problems if the user is using different fonts.
I am creating a javafx program in which i need to open a new fxml file in new tab dynamically.
I want that When user click on button a new tab is opened with new fxml file.
I Had no idea I can add tab as per design as much as i need but i want to do it dynamically when user click on button then only a new tab open.
I had also seen Questing but not working for me.
Please help me.
Thank you.
You can add tabs dynamically with
myTabPane.getTabs().add(myNewTab);
Create a new Tab with new Tab(), load your FXML and call
myNewTab.setContent(loadedFxmlRoot);
You can add tabs using this code, you need to confirm if your tabPane has this tab or no, else your program invokes SizeOfBounds exception.
if (!MessagePane.getTabs().contains(AllMessageTab)) {
MessagePane.getTabs().add(AllMessageTab);
}
SingleSelectionModel<Tab> selectionModel = MessagePane.getSelectionModel();
selectionModel.select(AllMessageTab);
AllMessageTab.setContent(_YourContentNodeHere);
I wish to remove some of the control buttons from HTMLEditor, since I do not need them. for that I need to reach the desired node. How can I know the IDs of nodes inside HTMLEditor? Please see the following. Thank you!
public class myApp extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("myApp.fxml")); //this fxml has HTMLEditor named htmlEditor.
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
Node someControlInsideHtmlEditor = root.lookup("#htmlEditor").lookup("#what_Is_The_ID_of_This_someControlInsideHtmlEditor")
}
}
Download Scenic View from here
Add this to your application's class path
Add the following line to your start() method's end:
ScenicView.show(scene);
Run the application
Two windows will pop up: the primaryStage with the HTMLEditor and Scenic View's Stage
Now you can visit every node of the Scene Graph. Open the tree at the left pane, and select a Node from the HTMLEditor. You can access the controls by their CSS class.
For example, open HTMLEditor -> ToolBar -> HBox, and select the first Button. Look at "styleClass" in the "Node Details" at the right side. You will need "html-editor-cut". It can be used with this code:
Button cutButton = (Button) root.lookup(".html-editor-cut");
don't know if you're still looking for this answer. In Java 8, and HTMLEditor only has one child, which is a GridPane. The first two children of that are the ToolBars, the third is a WebView. Remove the first two children from the gridpane to do the formatting you want. Does that help?