I have a problem with Scene Builder. I want to add ContextMenu on a Button. When I drag and drop the ContextMenu on a Button, it works fine (it appears in the Hierarchy tab). But when I click on the pre-defined MenuItem (under the ContextMenu) in the Hierarchy tab, Scene Builder freezes and I have to shut it down.
Could someone please help me with it? I know that I can create a ContextMenu in Java code, but i wanted to do it in Scene Builder (I want to make the ContextMenu pop up when you hover over the Button, so I also somehow need to edit it's trigger - could someone please tell me how to do it?).
I am using Java 13 and Scene Builder 11. As you can see, the program is not responding.
I appreciate any help. Thanks.
EDIT: This is what i got from EventViewer. I also looked in Scene Builder and according to 'About JavaFX Scene Builder', there should be a log file called scenebuilder-11.0.0.log (C:\Users\ZD\AppData\Local\Temp\scenebuilder-11.0.0.log). But there is no log file (even searching in file explorer did not find anything).
Source
OpenJDK Platform binary
Summary
The program stopped responding and was terminated.
Description
The problem caused that this program stopped working with Windows. Path to the failing application: C:\Program Files\SceneBuilder\SceneBuilder.exe
Problem signature
The name of the problem event: AppHangB1
Application name: SceneBuilder.exe
Application version: 11.0.1.0
Application time stamp: 5bf25cd1
Signature of process failure: c858
Type of process failure: 134217728
Operating system version: 10.0.18362.2.0.0.256.121
Another process failure signature 1: c858a8fd12ba3c4e845361b2e92ff131
Another process failure signature 2: 9431
Another process failure signature 3: 9431e8f7e11013654814c09debfafb79
Another process failure signature 4: c858
Another process failure signature 5: c858a8fd12ba3c4e845361b2e92ff131
Another process failure signature 6: 9431
Another process failure signature 7: 9431e8f7e11013654814c09debfafb79
More information about this issue
Set ID: 772d0501a48434cd5a8430efceaeecf6 (1910705948434820342)
This is Sample.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.canvas.Canvas?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.paint.LinearGradient?>
<?import javafx.scene.paint.Stop?>
<?import javafx.scene.text.Font?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="611.0" prefWidth="990.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
<children>
<AnchorPane id="k" fx:id="mainPanel" prefHeight="602.0" prefWidth="893.0" styleClass="root" stylesheets="@application.css">
<children>
<Button fx:id="button" layoutX="14.0" layoutY="14.0" mnemonicParsing="false" onAction="#handleButton" prefHeight="407.0" prefWidth="403.0" styleClass="MyButton" stylesheets="@application.css" text="Button" AnchorPane.bottomAnchor="190.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="573.0" AnchorPane.topAnchor="14.0">
<font>
<Font name="System Bold" size="83.0" />
</font>
<textFill>
<LinearGradient endX="0.5095238095238095" endY="0.8428571428571429" startX="0.5285714285714286" startY="0.26666666666666666">
<stops>
<Stop color="BLACK" />
<Stop color="#97b83e" offset="0.27147766323024053" />
<Stop color="#97b83e" offset="0.5154639175257733" />
<Stop color="WHITE" offset="1.0" />
</stops>
</LinearGradient>
</textFill>
</Button>
<ChoiceBox fx:id="choiceBox" accessibleText="lůůůůůůůůůů" layoutX="428.0" layoutY="14.0" prefHeight="25.0" prefWidth="329.0" />
<ScrollPane layoutX="428.0" layoutY="49.0" prefHeight="555.0" prefWidth="552.0">
<content>
<FlowPane prefHeight="704.0" prefWidth="727.0">
<children>
<Canvas fx:id="canvas" height="705.0" onDragOver="#mouseDrag" onMouseClicked="#canvasClicked" onMouseDragged="#mouseDrag" width="727.0" />
</children>
</FlowPane>
</content>
</ScrollPane>
</children>
</AnchorPane>
<AnchorPane fx:id="blackPanel" prefHeight="200.0" prefWidth="200.0" styleClass="blackPanel" stylesheets="@application.css">
<children>
<Button fx:id="backBtn" layoutX="356.0" layoutY="208.0" mnemonicParsing="false" onMouseClicked="#backBtnClick" prefHeight="195.0" prefWidth="278.0" styleClass="MyButton" text="Go back">
<font>
<Font name="System Bold" size="48.0" />
</font>
<textFill>
<LinearGradient endX="1.0" endY="1.0">
<stops>
<Stop color="#1be3a9" />
<Stop color="#083797" offset="1.0" />
</stops>
</LinearGradient>
</textFill>
</Button>
</children>
</AnchorPane>
</children>
</StackPane>
And this is Controller.java:
public class Controller {
private GraphicsContext gc;
private TranslateTransition tt;
@FXML private Button button;
@FXML private Button backBtn;
@FXML private ChoiceBox<String> choiceBox;
@FXML private Canvas canvas;
@FXML private AnchorPane mainPanel;
@FXML private AnchorPane blackPanel;
@FXML private ContextMenu popup;
public void initialize() {
choiceBox.setItems(FXCollections.observableArrayList("Výběr1", "Výběr2", "Výběr3", "Výběr4", "Výběr5"));
gc = canvas.getGraphicsContext2D();
double x = backBtn.getTranslateX();
double y = backBtn.getTranslateY();
tt = new TranslateTransition(Duration.seconds(5), backBtn);
tt.setToY(-200);
tt.setToX(-100);
tt.play();
tt.setOnFinished((ae) -> {
backBtn.setTranslateX(x);
backBtn.setTranslateY(y);
});
}
@FXML
private void handleButton() {
mainPanel.setVisible(false);
blackPanel.setVisible(true);
}
@FXML
private void backBtnClick() {
tt.stop();
mainPanel.setVisible(true);
blackPanel.setVisible(false);
}
@FXML
private void canvasClicked(MouseEvent me) {
gc.fillOval(me.getX() - 15, me.getY() -15, 30, 30);
}
@FXML
private void mouseDrag(MouseEvent mde) {
gc.fillOval(mde.getX() - 15, mde.getY() - 15, 30, 30);
}
}
The same issue here, I found a non-perfect solution, try to remove
fx:controllerfrom the fxml file and open Scene builder asAdministrateur.