Very good, I have a problem I am making an application to obtain and treat maps on google maps. My problem is that if I make a loadconten of a webengine the page does not load, that has to be explained a bit more
If I make a Java program with its corresponding main everything works fine, it shows a frame and in it the JavaScrip code will appear, if I remove that main and I do a library I compile it in a Jar to call it from a Bean this does not work, that is, everything is done correctly but the webengine does not show the content that happened to it
import java.awt.*;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class VentanaSiriusBrowser extends javax.swing.JFrame {
private static final long serialVersionUID = 1L;
public VentanaSiriusBrowser(String Uri,int AnchoVentana,int AltoVentana) {
initComponents(AnchoVentana,AltoVentana);
SiriusBrowser browser = new SiriusBrowser();
browser.loadURL(Uri);
// browser.setBounds(1, 1, jPanel1.getWidth() - 1, jPanel1.getHeight() - 1);
browser.setBounds(1, 1, AnchoVentana, AltoVentana );
jPanel1.add(browser);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents(int AnchoVentana,int AltoVentana) {
jPanel1 = new javax.swing.JPanel();
setTitle("Sirius Visualizador de Mapas");
setResizable(false);
jPanel1.setPreferredSize(new java.awt.Dimension(AnchoVentana, AltoVentana));
jPanel1.setAutoscrolls(true);
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
//jPanel1.setBounds(PosX, PosY, ancho-Resto, alto-Resto);
jPanel1.setLayout(new FlowLayout(FlowLayout.CENTER));
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel1.setLayout(new FlowLayout(FlowLayout.CENTER));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 676, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 474, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel jPanel1;
// End of variables declaration//GEN-END:variables
}
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
public class SiriusBrowser extends JFXPanel {
private static final long serialVersionUID = 1L;
private WebEngine engine;
//Constructor de la clase
public SiriusBrowser() {
Platform.runLater(new Runnable() {
@Override
public void run() {
WebView view = new WebView();
engine = view.getEngine();
setScene(new Scene(view));
}
});
setVisible(true);
}
//Método para cargar la URL de la página web
public void loadURL(final String url) {
Platform.runLater(new Runnable() {
@Override
public void run() {
engine.setJavaScriptEnabled(true);
System.out.println("=========================================================");
System.out.println(url);
System.out.println("=========================================================");
engine.loadContent(url);
}
});
}
}