How to get the IDs of nodes inside HTMLEditor, JavaFX - java

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?

Related

Can I change Scene using JavaFX automatically?

I am trying to make a game as my term final project. So when life level of one player is less or equal zero then I am trying to load another fxml file on the existing stage automatically. But I can't . I am not sure that if-else logic can change one scene to another. It will be helpful if anyone can give a way to change a scene automatically.
enter image description here
Thanks in advance.
if(Controller.lifeDekhao2<=0){
Parent is = FXMLLoader.load(getClass().getResource("/FXMLPack/First1.fxml"));
Scene isScene = new Scene(is);
Stage window = (Stage) ((Node) (event.getSource())).getScene().getWindow();
window.setScene(isScene);
window.show();
Controller.time_end = System.currentTimeMillis();
}

How to set a window always on top of another specific window in javafx

I have a toolbox that needs to stay always on top of the main window, but not of any other windows. So what I would need is a .setAlwaysOnTop(true) but for a specific window. How do I do that?
When you create the second Stage you have to call initOwner and initModality with Modality.WINDOW_MODAL. Then the new stage is always on top of the other but you can't interact with the parent stage.
For example:
public void createNewStage(Window parent) {
//... all the other stuff
Stage onTop = new Stage();
onTop.initOwner(parent);
onTop.initModality(Modality.WINDOW_MODAL);
onTop.show();
}

How to set background color of StackPane node to transparent using javafx/css and fxml

Trying to create a drop-shadow to my BorderPane. I need to use a StackPane to allow room for the drop-shadow. The problem is I cannot seem to set the background of StackPane to transparent. I am using transparent style for my primiaryStage.
There are other example using javaFX which work but, I can't figure it out when using fxml.
.StackPane{
-fx-background-color: transparent;
}
This still shows a white background behind my BorderPane
public class Main extends Application {
public static Stage Window;
#Override
public void start(Stage primaryStage) throws IOException{
Main.Window = primaryStage;
Window.initStyle(StageStyle.TRANSPARENT);
Window.setResizable(false);
FXMLLoader loader = new FXMLLoader(getClass().getResource("Homepage.fxml"));
Parent root = loader.load();
Window.setScene(new Scene(root));
root.getStylesheets().add(getClass().getResource("main.css").toExternalForm());
Window.show();
}
I found that when using a scroll pane it would dynamically create stack panes under it during runtime. Using scenic view I was able to see the style class name as 'viewport' and could change the background color that way.
Setting the window style might not work because the OS you are working on doesnt suppot that style. The documentation says about this:
On some platforms decorations might not be available.
But for a workaround for the stackpane, you should provide an example image of what you are aiming for. Right now its rather unclear what exactually you are trying to accomplish.

Switching Scenes with several FXML files

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?

How to show new content on button click in JavaFX?

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).

Categories