Search code examples
javahtmlswingjtabbedpanejeditorpane

HTML to fire JTabbedPane switch tab


Right now the goal I would like to acheieve is to have the HTML links(which each have a tab dedicated to them) fire the setSelectedComponent JTabbedPane function. In other words rather than jump down to the section on the "All" tab(which is what the html version of the page does) I want it to switch tabs. Please note, if this is not possible, is it possible to have them jump down to the sections like it does in a browser(because this isn't working natively either)?

<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>

enter image description here

Here is the relevant code that creates this image. The large section of code above this parses my website and seperates the HTML into only the body of the page (varaible: htmlContent) and each help section (variable: 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);
}

In case anyone wants to take a look at the html I'm parsing it is:

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

Thanks in advance for any help with this! :)


Solution

  • Okay, I just looked this up, appears that the one in the comments got truncated :P

    Following Hypertext Links