1.我使用JTable存储一个Boolean字段,显示的时候用JCheckBox。自定义的TableModel实现了下面的两个函数。
/**
   *<br>方法说明:实现这个方法使得最后一列不是显示true和false。而是使用检查盒
   *<br>输入参数:
   *<br>返回类型:
   */
  public Class getColumnClass(int c) {
    if (getValueAt(0, c) != null) {
      return getValueAt(0, c).getClass();
    }
    else {
      return new String().getClass();
    }
  }  /**
   *<br>方法说明:单元格是否可可编辑
   *<br>输入参数:rowIndex:int 行 columnIndex:int 列
   *<br>返回类型:true or false
   */
  public boolean isCellEditable(int rowIndex, int columnIndex) {
    if (columnIndex == 1) {
      return true;
    }
    else {
      return false;
    }
  }
当点击JCheckBox的时候,JTable会改变Boolean的值。我想把它修改后的值写回数据库应该怎么办。应该如何得到JTable自动修改的事件。
2.我使用下面的函数得到网页的字符串,并且将得到的字符串写入JDataStore数据库,然后再从数据库中取出放到Jtable中。现在的问题是如果网页编码是GB2312没问题,但是如果如果网页编码是UTF-8,显示的字符串会变成乱码,应该如何转换?
  public static String getHtmlText(String strUrl) {
    if (strUrl == null || strUrl.length() == 0) {
      return null;
    }    String strHtml = "";
    String strLine = "";
    try {      //链接网络得到网页源代码
      URL url = new URL(strUrl);
      HttpURLConnection pconn = (HttpURLConnection) url.openConnection();
      pconn.addRequestProperty("User-Agent", "IcewolfHttp/1.0");
      pconn.addRequestProperty("Accept",
                               "www/source; text/html; image/gif; */*");      pconn.connect();
      //System.out.println("Connect status:"+pconn.getResponseCode());
      //if(HttpURLConnection.HTTP_ACCEPTED == pconn.getResponseCode())
      //InputStream in = url.openConnection();      InputStream in = pconn.getInputStream();
      //System.out.println("Get status:"+pconn.getResponseCode());
      BufferedInputStream buff = new BufferedInputStream(in);
      Reader r = new InputStreamReader(buff);
      BufferedReader br = new BufferedReader(r);      while ( (strLine = br.readLine()) != null) {
        strHtml += strLine;
      }
      //strHtml = UnToWC(strHtml);
      br.close();
      buff.close();
      in.close();
      pconn.disconnect();
    }
    catch (MalformedURLException mfe) {
      System.err.println("url is not a parsable URL");
    }
    catch (IOException ioe) {
      System.err.println(ioe);
    }    return strHtml;
  }
3.使用JTextpane显示网页字符串(由于显示经常要更新,所以不能用setPage),如何能够响应单击链接事件,新建IE,打开网页。如果不行,有别的方法吗。
tpJtp.setContentType("text/html");
tpJtp.setText("<a href=www.csdn.net>www.csdn.net</a>");
tpJtp.repaint();

解决方案 »

  1.   

    第2个问题把:
         Reader r = new InputStreamReader(buff);
    写成:
         Reader r = new InputStreamReader(buff,"UTF-8");
    就OK了.我刚遇到过编码问题.如果写成:
         Reader r = new InputStreamReader(buff,"gb2312");
    就按gb2312的方式读取.
    如果还不行,把页面点开用另存为看看下面的编码是否是你要的编码,如果还不行看看你的
    工具软件的默认编码对不对,比如eclips有个edit菜单下面有个set encoding选项.
    我也是新手,说错了后面的大大帮忙指出下.
      

  2.   

    我有开了一帖,大家可以看看。
    http://community.csdn.net/Expert/TopicView.asp?id=4911773