Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 网页赢得';不能使用任何工具或窗格_Java_User Interface_Webpage_Jeditorpane - Fatal编程技术网

Java 网页赢得';不能使用任何工具或窗格

Java 网页赢得';不能使用任何工具或窗格,java,user-interface,webpage,jeditorpane,Java,User Interface,Webpage,Jeditorpane,好的,大家好,我还在学习Java,只是在玩一些东西,我制作了一个GUI,并有一个JEditorPane,当按下“Go”按钮时显示一个网页 无法工作的代码: private void goActionPerformed(java.awt.event.ActionEvent evt) { String URL = url.getText(); JEditorPane.setEditable(

好的,大家好,我还在学习Java,只是在玩一些东西,我制作了一个GUI,并有一个JEditorPane,当按下“Go”按钮时显示一个网页

无法工作的代码:

    private void goActionPerformed(java.awt.event.ActionEvent evt) {                                   
            String URL = url.getText();
    JEditorPane.setEditable(false);   

    try {
      JEditorPane.setPage("www.google.com");
    }catch (IOException e) {
      JEditorPane.setContentType("text/html");
      JEditorPane.setText("<html>Could not load " + URL);
    } 
}   
private void goActionPerformed(java.awt.event.ActionEvent evt){
字符串URL=URL.getText();
JEditorPane.setEditable(false);
试一试{
JEditorPane.setPage(“www.google.com”);
}捕获(IOE异常){
setContentType(“text/html”);
JEditorPane.setText(“无法加载”+URL);
} 
}   

欢迎任何帮助,谢谢

试试这样的方法:

    JFrame frame = new JFrame();
    JTextField field = new JTextField();
    frame.add(field);
    frame.pack();
    frame.setVisible(true);

    JEditorPane pane = new JEditorPane();
    try {
        pane.setPage(field.getText());
        ...
    }
    catch (IOException e) {
        pane.setContentType("text/html");
        pane.setText("<html>Could not load ");
    }
...
JFrame=newjframe();
JTextField=新的JTextField();
帧。添加(字段);
frame.pack();
frame.setVisible(true);
JEditorPane=新的JEditorPane();
试一试{
setPage(field.getText());
...
}
捕获(IOE异常){
pane.setContentType(“text/html”);
pane.setText(“无法加载”);
}
...

setPage
需要有效的协议前缀

jEditorPane.setPage("http://www.google.com");

确保您的文本字段也有this前缀(或者至少URL link参数格式正确)

URL
URL对象吗?如果是这样,您可能需要使用“toString()”?您是否显示了任何错误?你能在这里发布吗?这是一个JTextField,如果这是你的意思的话(新的)我更新了代码以保留在主窗口中,即使有一个已经放置好的URL它也不会工作。这让我走得更远,但看起来是的,不幸的是
JEditorPane
只支持HTML 3.2。您可以嵌入JavaFX的WebView。下面是Oracle的问题:有没有办法通过Swing添加webview?因为这是我唯一的选择。我明白,但是我没有一个“网络视图”工具来进行我的swing。你的意思是你没有
Webview
类。您需要类路径上的javafxjar。看见