This example
runs fine only once, but if you run it again FXML doesn't work, you need to restart JFOREX for it to work again.
What am I missing here?
package jforex.guitests;
import javax.swing.*;
import com.dukascopy.api.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
// FXML
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class FXML implements IStrategy {
private IUserInterface userInterface;
private final String tabName = "FXML Test";
public void onStart(IContext context) throws JFException {
this.userInterface = context.getUserInterface();
JPanel myTab; myTab = userInterface.getBottomTab(tabName);
final JButton btn = new JButton("Test Button");
myTab.add(btn);
// FXML
final JFXPanel fxPanel = new JFXPanel();
myTab.add(fxPanel);
Platform.runLater(new Runnable() {
@Override
public void run() {
initFX(fxPanel);
}
});
// FXML
}
// FXML
private static void initFX(JFXPanel fxPanel) {
// This method is invoked on JavaFX thread
Scene scene = createScene();
fxPanel.setScene(scene);
}
private static Scene createScene() {
Group root = new Group();
Scene scene = new Scene(root, Color.BLUE);
Text text = new Text();
text.setX(40);
text.setY(100);
text.setFont(new Font(25));
text.setText("Welcome JavaFX!");
root.getChildren().add(text);
return (scene);
}
// FXML
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onStop() throws JFException {
userInterface.removeBottomTab(tabName);
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
}