an application generates some HTML pages that should be displayed in the application itself.
These HTML pages contain some forms that would be used by the user to enter some values.
So far I've used a JTextPane which renders the HTML perfectly, but I do not know how to interact with the form to retrieve the values entered by the user.
_
Is it possible to do so with a JTextPane / JEditorPane ?
If no, do you now any other way to interact with an HTML form ?
_
EDIT : following tulskiy instructions here is the result :
package tests;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.html.*;
import org.junit.Test;
public class JTextPaneTests
{
@Test
public void testForms() throws Exception
{
javax.swing.SwingUtilities.invokeLater(
new Runnable()
{
public void run()
{
javax.swing.JFrame jf = new javax.swing.JFrame();
jf.setSize(300,300);
jf.setVisible(true);
jf.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
JTextPane textPane = new JTextPane();
textPane.setContentType("text/html");
textPane.setEditable(false);
textPane.setText(
"<html>" +
"<body>" +
"<form action=\"#\">" +
"<input name=\"input1\" type=\"text\" />" +
"<input name=\"input2\" type=\"text\" /><br/>" +
"<input name=\"cb1\" type=\"checkbox\" /><br/>" +
"<input name=\"rb1\" type=\"radio\" /><br/>" +
"<input type=\"submit\" value=\"go\" />" +
"</form>" +
"</body>" +
"</html>");
jf.getContentPane().setLayout(new BoxLayout(jf.getContentPane(), BoxLayout.Y_AXIS));
jf.getContentPane().add(textPane);
HTMLEditorKit kit = (HTMLEditorKit)textPane.getEditorKit();
kit.setAutoFormSubmission(false);
textPane.addHyperlinkListener(new HyperlinkListener()
{
@Override
public void hyperlinkUpdate(HyperlinkEvent e)
{
if (e instanceof FormSubmitEvent)
{
System.out.println(((FormSubmitEvent)e).getData());
}
}
});
}
}
);
System.in.read();
}
}
Depending on the user inputs the output will be like :
input1=Some+text&input2=More+text&cb1=on&rb1=on
Note that the "action" attribute is mandatory, otherwise an exception is thrown.
_
Thanks in advance for any hint.