现在我想要实现的目标是让 HTML 链接(每个链接都有一个专用于它们的选项卡)触发 setSelectedComponent JTabbedPane 函数。换句话说,我不想跳到“全部”选项卡上的部分(这是页面的 html 版本所做的),我希望它切换选项卡。请注意,如果这是不可能的,是否可以让它们像在浏览器中那样跳到这些部分(因为这也不能在 native 中工作)?
<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
预先感谢您对此提供的任何帮助! :)
最佳答案
好吧,我刚刚查了一下,评论里的好像被截断了:P
关于java - HTML 触发 JTabbedPane 切换选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11727964/