JavaFX browser Swing Gui Application in Java Eclipse
JavaFX swing 2016
package program_from; import java.awt.Color; import java.awt.EventQueue; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; import javafx.scene.web.WebView; public class demo { private JFrame frame; private JPanel panel_36; private JFXPanel javafxPanel; public JTabbedPane tabbedPane; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { demo window = new demo(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public demo() { initialize(); initSwingComponents(); loadJavaFXScene(); } /** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 1000, 694); // set size frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setForeground(new Color(0, 0, 128)); tabbedPane.setBounds(0, 0, 1000, 694); frame.getContentPane().add(tabbedPane); } public void initSwingComponents() { javafxPanel = new JFXPanel(); javafxPanel.setBounds(0, 0, 1000, 694); // Set size google panel_36 = new JPanel(); panel_36.setLayout(null); panel_36.add(javafxPanel); tabbedPane.addTab("Google", new ImageIcon("C:\\Users\\Lonely\\workspace\\ProjectDTD\\icon\\Google-Chrome-icon.png"), panel_36); } public void loadJavaFXScene() { Platform.runLater(new Runnable() {@ Override public void run() { BorderPane borderPane = new BorderPane(); WebView webComponent = new WebView(); webComponent.getEngine().load("http://google.vn"); borderPane.setCenter(webComponent); Scene scene = new Scene(borderPane); javafxPanel.setScene(scene); webComponent.autosize(); } }); } }
0 nhận xét:
Post a Comment