Reputation: 53
I'm trying to extend an existing JavaFX GUI, that includes a ComboBox, with a custom Swing component (just an empty JPanel for this example) in a separate panel. Problem is, once I set the SwingNode's component to this panel, the ComboBox becomes unclickable.
I've broken it down to the minimal code below. Our application is a Swing application, but some forms primarily use JavaFX for their content, that's why it has this strange Swing-in-FX-in-Swing structure. That's not really something that can be avoided though and usually doesn't cause any problems.
Avoiding the outer Swing window and creating an FX stage with that scene directly fixes the issue, but architecturally that isn't an option for our application.
I tried testing this code using the newest JDK 21 and OpenJFX 21, but it's still not fixed there. Has anyone encountered a similar problem and has a suggested workaround? Thanks!
import java.awt.BorderLayout;
import javax.swing.*;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.embed.swing.JFXPanel;
import javafx.embed.swing.SwingNode;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.VBox;
public class BugFrame extends JFrame {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
BugFrame dlg = new BugFrame();
dlg.setVisible(true);
});
}
private BugFrame() {
super();
JFXPanel jfxPanel = new JFXPanel();
jfxPanel.setScene(createScene());
add(jfxPanel, BorderLayout.CENTER);
}
private static Scene createScene() {
ComboBox<String> combo = new ComboBox<>(FXCollections.observableArrayList(
"Item 1", "Item 2"
));
combo.setValue("Item 1");
SwingNode swingNode = new SwingNode();
swingNode.setContent(new JPanel()); // problem disappears when this line is deleted
return new Scene(new VBox(combo, swingNode));
}
}
Upvotes: 2
Views: 75
Reputation: 9949
Consider this as supporting information to your question:
I would not say it is as "unclickable".. but rather would say that the "popup is not showing". Because it is firing all the related events(mouse click, showing..etc) to show the popup.
Indeed the popup is even rendered with items,. but somehow it is not visible on the screen (And I don't know why).
To support my justification, please check the below gif.
I suspect there is something with applyCss or some related kind. And if you ask why it is working when in combination with my tool.. I don't know :)
A lot of stuff happens in my tool code.. and I don't know which one is fixing this ;). Just giving you this info.. may be it can help you to fix this.
Upvotes: 2