How to invoke HSQLDB DatabaseManager Swing app in JavaFX Swingnode? - java

I am trying to embed the HSQLDatabaseManager Swing App in my own JavaFX project.
public class SQLTool extends Application {
#Override
public void start (Stage stage) {
final SwingNode swingNode = new SwingNode();
createSwingContent(swingNode);
StackPane pane = new StackPane();
pane.getChildren().add(swingNode);
stage.setTitle("Swing in JavaFX");
stage.setScene(new Scene(pane, 800, 600));
stage.show();
stage.centerOnScreen();
}
private void createSwingContent(final SwingNode swingNode) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
JPanel panel = new JPanel();
DatabaseManagerSwing dbms = new DatabaseManagerSwing();
panel.add(dbms);
swingNode.setContent(panel);
}
});
}
Getting a Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: java/sql/SQLException
Looks like the jar file couldn't be found. It's placed under resources/lib/sqltool. I am using latest JDK14.
Thanks for the help!

Related

JavaFX: java.lang.module.ResolutionException: Modules sqltool and hsqldb export package org.hsqldb.lib to module javafx.graphicsEmpty

I am learning JavaFX and I m trying to use external libraries (HSQLDB and the corresponding Datamanager GUI Tool) which I imported with Maven. My goal is to open an instance of the Datamanager GUI Tool which is a Swing application.
public class SQLTool extends Application {
#Override
public void start (Stage stage) {
final SwingNode swingNode = new SwingNode();
createSwingContent(swingNode);
StackPane pane = new StackPane();
pane.getChildren().add(swingNode);
stage.setTitle("Swing in JavaFX");
stage.setScene(new Scene(pane, 640, 480));
stage.show();
stage.centerOnScreen();
}
private void createSwingContent(final SwingNode swingNode) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
//swingNode.setContent(new JButton("Click me!"));
**swingNode.setContent(new SwingForm());**
}
});
}}
class SwingForm extends JPanel {
public SwingForm(){
JPanel innerPanel = new JPanel();
**DatabaseManagerSwing dbms = new DatabaseManagerSwing();**
innerPanel.add(dbms);
add(innerPanel);
}}
Getting
java.lang.NoClassDefFoundError: java/sql/SQLException
at com...SQLTool$SwingForm.<init>(SQLTool.java:45)
at com...SQLTool$1.run(SQLTool.java:34)
Thanks for the help!

How to embed JPanel into JavaFX pane for graph visualization

How can I add a swingNode to a specific pane using my controller class?
I'm trying to add a JPanel that loads a network graph created using the JUNG software library I'm not sure how to do it.
You can achieve what you want to do using SwingNode class. Here is an example code where a JButton (swing component) is added to a StackPane (JavaFX component):
public class SwingFx extends Application {
#Override
public void start(Stage stage) {
final SwingNode swingNode = new SwingNode();
createAndSetSwingContent(swingNode);
StackPane pane = new StackPane();
pane.getChildren().add(swingNode);
stage.setScene(new Scene(pane, 100, 50));
stage.show();
}
private void createAndSetSwingContent(final SwingNode swingNode) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
swingNode.setContent(new JButton("Click me!"));
}
});
}
public static void main(String[] args) {
launch(args);
}
}
Source: http://download.java.net/jdk8/jfxdocs/javafx/embed/swing/SwingNode.html

How to embed JPanel into JavaFX pane?

How can I add a swingNode to a specific pane?
I'm actually trying to add a JPanel that loads an applet to the transparent area of the following and I'm not sure how to do it.
SwingNode is a javafx scene node and can be added to any javafx scene layouts.
To add a JPanel to a Pane and display it on JavaFX stage:
Add JPanel to a SwingNode
Assign the swingnode as a child to any of the layouts (which includes Pane).
Set the layout as the root of the scene
Set the scene to the stage and display it
A very simple code sample to show how you can add it to a Pane is (from SwingNode Javadoc):
public class SwingNodeExample extends Application {
#Override
public void start(Stage stage) {
final SwingNode swingNode = new SwingNode();
createAndSetSwingContent(swingNode);
Pane pane = new Pane();
pane.getChildren().add(swingNode); // Adding swing node
stage.setScene(new Scene(pane, 100, 50));
stage.show();
}
private void createAndSetSwingContent(final SwingNode swingNode) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
JPanel panel = new JPanel();
panel.add(new JButton("Click me!"));
swingNode.setContent(panel);
}
});
}
public static void main(String[] args) {
launch(args);
}
}

Creating multiple buttons in java scene

I am attempting to create a scene with multiple buttons and I am having some issues.
What I have now is this:
public class Tester extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Button btn1 = new Button();
btn1.setText("Start Game");
Button btn2 = new Button();
btn2.setText("Exit");
btn2.setOnAction(new EventHandler<ActionEvent>());
btn1.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Game Start");
}
});
Pane root = new Pane();
btn1.setLayoutX(500);
btn1.setLayoutY(530);
root.getChildren().add(btn1);
primaryStage.setScene(new Scene(root, 1024, 768));
primaryStage.show();
I am trying to figure out what I need to do to have a second button. At the moment, I cant seem to have a second event handler.
Any help will be greatly appreciated.
Here is an update to your program to:
Define an action (display "Wumpus Hunt Complete!") for the second button.
Add the second button to the scene so that it can be seen.
The event handler for taking action for a button is an example of an anonymous inner class.
Sample Code:
Button btn1 = new Button();
btn1.setText("Start Game");
Button btn2 = new Button();
btn2.setText("Exit");
btn2.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Wumpus Hunt Complete!");
}
});
btn1.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Game Start");
}
});
Pane root = new Pane();
btn1.setLayoutX(500);
btn1.setLayoutY(530);
root.getChildren().add(btn1);
btn2.setLayoutX(500);
btn2.setLayoutY(630);
root.getChildren().add(btn2);
primaryStage.setScene(new Scene(root, 1024, 768));
primaryStage.show();

Java applet using JavaFx

I'm developing an applet. I want to use JavaFx to create the controls. Currently, I'm using An JFXPanel. Here is the code:
private JFXPanel jfxPanel;
private Canvas canvas;
private Scene scene;
private BorderPane borderPane;
public void init() {
jfxPanel = new JFXPanel();
Platform.runLater(new Runnable() {
#Override
public void run() {
jfxPanel.setScene(createScene());
add(jfxPanel);
}
});
}
public Scene createScene() {
borderPane = new BorderPane();
scene = new Scene(borderPane, 400, 800);
canvas = new Canvas();
canvas.getGraphicsContext2D().setFill(Color.RED);
borderPane.setCenter(canvas);
return scene;
}
public void paint(Graphics g) {
}
The problem is that it doesn't work. I can't see anything. Do you have any idea?
Maybe it's too late to answer, but...
Try to add this line below to your init()
getContentPane().add(jfxPanel);

Categories