現在我希望acheieve的目標是讓HTML鏈接(每個都有一個專用於它們的選項卡)觸發setSelectedComponent JTabbedPane函數。換句話說,而不是跳到「全部」選項卡(這是頁面的html版本)的部分,我希望它切換選項卡。請注意,如果這是不可能的,是否有可能讓它們跳到像在瀏覽器中那樣的部分(因爲它本身不工作)?要觸發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分離爲頁面主體(varaible: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
預先感謝任何幫助! :)
看一看http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html,第二部分「關注超文本鏈接」 – MadProgrammer 2012-07-30 20:47:10
未找到 請求的URL /〜hall/java/Swing的教程/ Swing的教程,JEditorPane.h在此服務器上找不到tml「。 – KisnardOnline 2012-07-30 23:17:17
@MadProgrammer你有一個新的鏈接? – KisnardOnline 2012-07-30 23:17:32