【问题标题】:HTML to fire JTabbedPane switch tab触发 JTabbedPane 切换选项卡的 HTML
【发布时间】:2012-07-28 12:03:44
【问题描述】:

现在我想要实现的目标是让 HTML 链接(每个链接都有一个专用的选项卡)触发 setSelectedComponent JTabbedPane 函数。换句话说,与其跳到“全部”选项卡上的部分(这是页面的 html 版本所做的),我希望它切换选项卡。请注意,如果这是不可能的,是否可以让他们像在浏览器中那样跳到各个部分(因为这也不是本机工作的)?

<nav>
    [ <a href="gameplayhelp.php#Basic">Basic</a> | 
    <a href="gameplayhelp.php#Maps">Maps</a> | 
    <a href="gameplayhelp.php#Quests">Quests</a> | 
    <a href="gameplayhelp.php#NPCs">NPCs</a> | 
    <a href="gameplayhelp.php#Monsters">Monsters</a> | 
    <a href="gameplayhelp.php#Items">Items</a> | 
    <a href="gameplayhelp.php#Marketplace">Marketplace</a> | 
    <a href="gameplayhelp.php#Skills">Skills</a> | 
    <a href="gameplayhelp.php#Storage">Storage</a> ]
</nav>

这是创建此图像的相关代码。上面的大部分代码会解析我的网站并将 HTML 分成页面主体(变量:htmlContent)和每个帮助部分(变量:helpSection)。

JScrollPane scrollPane = new JScrollPane();
JEditorPane editorPane = new JEditorPane();
scrollPane.setViewportView(editorPane);
editorPane.setEditorKit(kit);
editorPane.setEditable(false);
editorPane.setContentType("text/html");
editorPane.setText(htmlContent);
editorPane.setCaretPosition(0);
tabbedPane.addTab("All", null, scrollPane, "All gameplay help");

for(String s: navLinks){
    tabbedPane.addTab(s, null, new JScrollPane(new JEditorPane("text/html", helpSection.get(0))), s + " gameplay help");
    helpSection.remove(0);
}

如果有人想看看我正在解析的 html,它是:

http://www.kisnardonline.com/gameplayhelp.php

提前感谢您对此提供的任何帮助! :)

【问题讨论】:

  • 看看apl.jhu.edu/~hall/java/Swing-Tutorial/…,第二部分“关注超文本链接”
  • 未找到请求的 URL /~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html‌​ 在此服务器上找不到。
  • @MadProgrammer 你有新链接吗??
  • 查看答案,可能会更好:P
  • 谢谢,我明天去看看。该睡了。感谢您找到链接,非常感谢。现在让我们希望我能读懂它,消化它,然后把它变成好的东西。

标签: java html swing jtabbedpane jeditorpane


【解决方案1】:

这是我的最终解决方案:

public void hyperlinkUpdate(HyperlinkEvent event) {
    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        Pattern p = Pattern.compile(".*?(?:[a-z][a-z]+).*?(?:[a-z][a-z]+).*?((?:[a-z][a-z]+))",Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        Matcher m = p.matcher(event.getDescription());
        if (m.find()){
            String word1=m.group(1);
            System.out.println(word1);
            if (navLinks.contains(word1)){
                tabbedPane.setSelectedIndex(navLinks.indexOf(word1)+1);
            }
        }
    }
  }

【讨论】:

    【解决方案2】:

    好的,我刚刚查了一下,似乎 cmets 中的那个被截断了:P

    Following Hypertext Links

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-30
      • 2017-03-09
      相关资源
      最近更新 更多