JavaJavaFX在MouseOver上闪烁(最近重新绘制)并带有集成Swing
我尝试将javaFX应用程序集成到Swing应用程序中,并成功地完成了
但问题是,我无法解决鼠标悬停在按钮上时javaFX相关面板闪烁(重新绘制速度太慢)的问题
有没有解决方案,或者我会尝试将Swing集成到javaFX中?这会很烦人
private void initFX(JFXPanel fxPanel) throws IOException {
// This method is invoked on the JavaFX thread
scene = createScene();
fxPanel.setScene(scene);
}
public MainFrame() {
Panel container = new Panel();
container.setLayout(null);
try {
final JFXPanel panel = new JFXPanel();
Insets insets = container.getInsets();
container.add(panel);
JApplet mapApplet = (JApplet)Class.forName("samples.mainApp.MainApplet").newInstance();
container.add(mapApplet); //Display Applet
add(container);
mapApplet.setBounds(800, 0, 566, 720);
panel.setBounds(0, 0, 800, 720);
mapApplet.init();
mapApplet.start();
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
initFX(panel);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
} catch (InstantiationException | IllegalAccessException
| ClassNotFoundException e) {
e.printStackTrace();
}
//button.setVisible(false);
catch (Exception e) {
e.printStackTrace();
}
}
private Scene createScene() throws IOException {
root = new Group();
scene = new Scene(root, Color.ALICEBLUE);
Button btn1 = new Button("Connect");
root.getChildren().addAll(btn1);
}
# 1 楼答案
从未见过这种情况,也从未出现过闪烁(不知道如何运行,从您发布的代码中模拟)
为了获得更好的帮助,请尽快发布一个SSCCE/MCVE,简短、可运行、可编译、由a.m.引起并描述了问题(请注意测试并查看
SwingUtilities.invokeLater
和Platform.runLater
的用法)