Reputation: 740
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>
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! :)
Upvotes: 2
Views: 391
Reputation: 740
Here is my final solution:
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);
}
}
}
}
Upvotes: 0
Reputation: 347314
Okay, I just looked this up, appears that the one in the comments got truncated :P
Upvotes: 2