Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5965799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:41:23+00:00 2026-05-22T19:41:23+00:00

an application generates some HTML pages that should be displayed in the application itself.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:41:24+00:00Added an answer on May 22, 2026 at 7:41 pm

    I believe if you have a submit button on your form, it should work and send data to server. I’m not sure if you can interact with it in the code. Those elements are rendered as swing component, so in theory you get all components from the JTextPane and find your button and input fields.

    EDIT To do this is in JEditorPane, you need to set auto for submition property to false

    ((HTMLEditorKit)textPane.getEditorKit()).setAutoFormSubmission(false);
    

    then you will be able to register a hyperlink listener with the editor pane and you will be receiving a FormSubmitEvent. It has url and method, so you can decode some data from it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: we have an application that generates reports from HTML (that may or may
Is there an application out there that Generates an HTML form from a PDF
I need to make an application which dynamically generates some number of forms and
We have an application that generates simulated data for one of our services for
I'm using a custom-built inhouse application that generates a standard set of reports on
I'm using C# and i have written a locally installed application that dynamically generates
I have an application that for one of its pages returns an XML string
I would like to know if there's any templating engine that is used for
I've got some HTML which has some dynamically generated forms which are submitted via
I'm writing a JavaScript that generates some data. I intend to use it as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.