gpt4 book ai didi

Java - 无法加载相同的 url 并将其显示在编辑器 Pane 中两次?

转载 作者:太空宇宙 更新时间:2023-11-04 08:32:44 25 4
gpt4 key购买 nike

这是我用来在编辑器 Pane 中显示 url 内容的代码


 import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.net.*;


public class header extends JFrame {

private void initComponents() {

jTextField2 = new JTextField();
jTextField3 = new JTextField();
jButton1 = new JButton();
jScrollPane1 = new JScrollPane();
jTextArea1 = new JEditorPane();

setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("Load");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jTextArea1.setEditable(false);
jScrollPane1.setViewportView(jTextArea1);
setSize(418,300);
setVisible(true);
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, 277, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField3, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
.addContainerGap())
);

pack();
}// </editor-fold>

private void jButton1ActionPerformed(ActionEvent evt) {
try {
URL header = new URL(jTextField2.getText());
jTextArea1.setPage(header);
}catch(MalformedURLException e){} catch(IOException e){}
}


/**
* @param args the command line arguments
*/
public static void main(String args[]) {
header gui = new header();
gui.initComponents();
}
// Variables declaration - do not modify
private JButton jButton1;
private JScrollPane jScrollPane1;
private JEditorPane jTextArea1;
private JTextField jTextField2;
private JTextField jTextField3;
// End of variables declaration
}

我只是无法让它刷新并显示相同 url 的内容两次。当我点击加载按钮时它会加载内容,但如果我再次点击加载按钮,它不会加载 url 或显示内容..我做错了什么?我对java很陌生,如果它是一个简单的解决方案,那么抱歉,如果您能指出我解决这个问题的正确方向,那就太好了,谢谢!

最佳答案

我依稀记得你需要强制编辑器面板重新加载页面。

只是猜测,但您可以尝试:

setContentType("");

或者
setDocument(null);

关于Java - 无法加载相同的 url 并将其显示在编辑器 Pane 中两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7158310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com