2012-07-01 2 views
1

프로젝트를 끝내고 도움말 메뉴 버튼을 클릭하면 사용자에게 도움말 파일로 표시하려는 일부 이미지와 앵커 링크가있는 간단한 html이 있습니다. 나는 그것을하는 방법을 모른다. 나는 아래의 코드를 시도했는데 어떤 스크롤도없는 프레임에서 나만을 반환하고 링크가 작동하지 않는다.jframe에서 html 파일로드하기

pane = new JEditorPane(getClass().getResource("help.html"));//add the html to be shown 
    pane.setEditable(false); 

간단한 접근 방법이 있습니까? Java를 처음 사용하기 때문에 간단하게 유지하십시오. 감사합니다. 나는 다른 방법으로 그것을 할 관리 할 수 ​​있기 때문에

답변

2

을 읽을 수 기쁘게 나는를 사용하는 것이 더 유용한 발견 기본 사용자 브라우저는 파일을 볼 수 있습니다. 이것이 내 해결책입니다.

helpItem.addActionListener(new ActionListener() { 

     @Override 
     public void actionPerformed(ActionEvent e) { 
      Desktop desktop = null; 
      // Before more Desktop API is used, first check 
      // whether the API is supported by this particular 
      // virtual machine (VM) on this particular host. 
      if (Desktop.isDesktopSupported()) 
      { 
      try 
      { 
       desktop = Desktop.getDesktop(); 
       String thehelpfile= String.valueOf(getClass() 
         .getResource("help.html")); 
       File fileToOpen=new File(thehelpfile.substring(5)); 
       desktop.open(fileToOpen); 
      } catch (IOException ex) 
      { 
       JOptionPane.showMessageDialog(null, 
         ex, "Λάθος", JOptionPane.PLAIN_MESSAGE); 
      } 
      } 
     } 
    }); 
+1

+1 for self_answering – mKorbel

관련 문제