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 6768477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:04:47+00:00 2026-05-26T15:04:47+00:00

I am using non-editable JTextPane to show some data in HTML format. I have

  • 0

I am using non-editable JTextPane to show some data in HTML format. I have set contentType to “text/html” and it works. Now I wanted to add HTML checkboxes in JTextPane, and listen to their change, and be able to retrieve if a specific checkBox is selected. Is this possible?

The text of JTextPane is in this format:

<html><form>
<input type="checkbox" name="checkbox1" value="value" /> checkbox1<br />
</form></html>

Should I be using JTextPane for this purpose at all, or is there a better control? Regular check boxes are not an option, because I need a HTML format for styling it easily.

  • 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-26T15:04:48+00:00Added an answer on May 26, 2026 at 3:04 pm

    Generally you would use a JEditorPane to display HTML.

    Depending on your requirement there are two ways to go about this:

    1. Swing components are actually added to the editor pane. So once the docuemnt has been parsed and the editor pane has been revalidated() you should be able to just get a list of all the components added to the editor pane. You can check the class name to find the components you want.

    2. The HTMLDocument contains attributes about each component added including the components model. So you can search the document to get the model for every checkbox.

    Here is some general code to get your started:

    import java.awt.*;
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    
    public class GetComponent extends JFrame
    {
        public GetComponent()
            throws Exception
        {
            FileReader reader = new FileReader("form.html");
    
            JEditorPane editor = new JEditorPane();
            editor.setContentType( "text/html" );
            editor.setEditable( false );
            editor.read(reader, null);
    
            JScrollPane scrollPane = new JScrollPane( editor );
            scrollPane.setPreferredSize( new Dimension(400, 300) );
            add( scrollPane );
    
            setDefaultCloseOperation( EXIT_ON_CLOSE );
            pack();
            setLocationRelativeTo( null );
            setVisible(true);
    
            //  display the attributes of the document
    
            HTMLDocument doc = (HTMLDocument)editor.getDocument();
            ElementIterator it = new ElementIterator(doc);
            Element element;
    
            while ( (element = it.next()) != null )
            {
                System.out.println();
    
                AttributeSet as = element.getAttributes();
                Enumeration enumm = as.getAttributeNames();
    
                while( enumm.hasMoreElements() )
                {
                    Object name = enumm.nextElement();
                    Object value = as.getAttribute( name );
                    System.out.println( "\t" + name + " : " + value );
    
                    if (value instanceof DefaultComboBoxModel)
                    {
                        DefaultComboBoxModel model = (DefaultComboBoxModel)value;
    
                        for (int j = 0; j < model.getSize(); j++)
                        {
                            Object o = model.getElementAt(j);
                            Object selected = model.getSelectedItem();
                            System.out.print("\t\t");
    
                            if ( o.equals( selected ) )
                                System.out.println( o + " : selected" );
                            else
                                System.out.println( o );
                        }
                    }
                }
            }
    
            //  display the components added to the editor pane
    
            for (Component c: editor.getComponents())
            {
                Container parent = (Container)c;
                System.out.println(parent.getComponent(0).getClass());
            }
        }
    
        public static void main(String[] args)
            throws Exception
        {
            EventQueue.invokeLater(new Runnable()
            {
                public void run()
                {
                    try
                    {
                        GetComponent frame = new GetComponent();
                    }
                    catch(Exception e) { System.out.println(e); }
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm inserting some non-server controls (plain html controls) dynamically into an update panel using
I have a DataGridView with read-only mode set to true (non-editable) which takes values
What is the quickest most efficient way to search text for words using non-casesensitive
I have a page that is using a non-standard font and arial as a
I'm using the following code to have a non-JS navigation: <ol id=navigation> <li id=home><a
I have a fairly pedestrian non-editable NSOutlineView setup. In the bindings for the outline
I have a few field in my entity that i wish to be non-editable.
What is your opinion about using non valid attributes on html elements for easier
I have a non-editable DataTable built with PrimeFaces. The table is initially filled with
I'd like to have a group of HTML text <input> 's that can be

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.