日期:2014-05-20  浏览次数:20703 次

JEditorPane类实现显示URL资源中的HTML文件出问题
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
public class JEditorNet
{
public static void main(String[] args) 
  {new Win();

  }
}
class Win extends Frame implements ActionListener,Runnable
{ Button button ;
  URL url;
  TextField text;
  JEditorPane editPane;
  byte b[]=new byte[1024];
  Thread thread;
 public Win()
  { text=new TextField(20);
  editPane=new JEditorPane();
  editPane.setEditable(false);
button=new Button("确定");
button.addActionListener(this);
thread=new Thread(this);  
Panel p=new Panel();
p.add(new Label("输入网址:"));
p.add(text);
p.add(button);
ScrollPane scroll=new ScrollPane();
add(scroll,BorderLayout.CENTER);
add(p,BorderLayout.NORTH);
setBounds(160,60,360,300);
setVisible(true);
validate();
addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent e){
  System.exit(0);
  }
  });
  }
  public void actionPerformed(ActionEvent e)
  { if(!thread.isAlive())
  { thread=new Thread(this);
 
  }
  try
  { thread.start();
  }
  catch(Exception ee)
  { text.setText("正在读取"+url);
  }
  }
  public void run()
  {try
  { editPane.setText(null);
url=new URL(text.getText().trim());
editPane.setPage(url);
  }
  catch(Exception el){text.setText(""+el);return;}
   
  }
}
上面的程序通过JEditorPane类,显示URL资源中的HTML文件,当我运行程序时,窗口没有显示带滚动条的容

器ScrollPane scroll,当在text中输入百度网址http://www.baidu.com/,容器中没有任何反应,这儿出了

什么问题????


------解决方案--------------------
editPane=new JEditorPane();
editPane.setEditable(false);
你是想 在这里边显示网页内容,但为啥不把此组件放入scrollPanel中呢。。。