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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:25:34+00:00 2026-05-30T08:25:34+00:00

http://weblogs.java.net/blog/aim/archive/2007/07/embedding_swing.html http://docs.oracle.com/javase/1.5.0/docs/api/index.html?javax/swing/text/html/ObjectView.html I add html code to JEditorPane: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01

  • 0

http://weblogs.java.net/blog/aim/archive/2007/07/embedding_swing.html
http://docs.oracle.com/javase/1.5.0/docs/api/index.html?javax/swing/text/html/ObjectView.html

I add html code to JEditorPane:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <body>
          <table width="90%" height="90%" align="center">
              <tr align="center">
                  <td align="center">
                      <object classid="javax.swing.JButton" label="just do it">
                      </object>
                  </td>
              </tr>
          </table>
      </body>
    </html>

image

How can I control this button? (Change size, color, add listener e.t.c)

I solved the problem, a working example:

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.html.HTMLEditorKit;
    import javax.swing.text.ViewFactory;
    import javax.swing.text.AttributeSet;
    import javax.swing.text.Element;
    import javax.swing.text.html.ObjectView;
    import javax.swing.text.AbstractDocument;
    import javax.swing.text.View;
    import javax.swing.text.StyleConstants;

    import javax.swing.text.*;
    import javax.swing.text.html.HTML;
    import javax.swing.text.html.HTMLEditorKit;
    import java.net.URL;

    public class EditorPaneTest extends JFrame
    {
public EditorPaneTest()
{
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocationByPlatform(true);        

    JEditorPane editPane = new JEditorPane();
    JScrollPane scrollPane = new JScrollPane(editPane);     

editPane.setContentType("text/html");
editPane.setEditable(false);
    editPane.setEditorKit(new CompEditorKit()); // install our hook

editPane.setText("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"+
"<html>"+
"<body>"+
"<object classid=\"javax.swing.JLabel\" label=\"just do it\">"+
"</object>"+
"</body>"+
"</html>");
    add(scrollPane, BorderLayout.CENTER);
    setSize(400, 300);
    setVisible(true);
}

public static void main(String... args)
{
    SwingUtilities.invokeLater(new Runnable()
    {
        public void run()
        {
            new EditorPaneTest();
        }
    });
}
protected class CompEditorKit extends HTMLEditorKit {
    @Override
    public ViewFactory getViewFactory() {
        return new CompFactory();
    }       
}   
protected class CompFactory extends HTMLEditorKit.HTMLFactory {
    public CompFactory() {
        super();
    }
    @Override
    public View create(Element element) {
        AttributeSet attrs = element.getAttributes();
    Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
    Object o = (elementName != null) ? null : attrs.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {       
            if ((HTML.Tag) o == HTML.Tag.OBJECT) {
                return new CompView(element); 
            }
        }
        return super.create(element);
    }
}   
protected class CompView extends ObjectView {
    public CompView(Element element) {
        super(element);
    }
    @Override
    protected Component createComponent() {
        Component component = super.createComponent();  // COMPONENT IS CREATED HERE
    System.out.println(component);
    JLabel layeredPane = (JLabel)component;
    layeredPane.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("images/9.gif"))));
    return component;   
    }
}
    }

But now another problem. I can not get the Jlabel coordinates
System.out.println(layeredPane.getLocation()+ "|"+layeredPane.getSize() +"|"+ layeredPane.getY());
Return 0 0 0

  • 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-30T08:25:36+00:00Added an answer on May 30, 2026 at 8:25 am

    May be this could help
    http://java-sl.com/custom_tag_html_kit.html

    About coordinates. The JLabel is placed in a container. Size and bounds are set during layout/paint of the pane’s content.

    When all content is properly visible you can get the label’s parent container and use getBounds() to obtain real bounds.

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

Sidebar

Related Questions

Garbage First (G1) garbage collector http://weblogs.java.net/blog/opinali/archive/2009/02/here_comes_jdk.html Do you think this garbage collector is better
http://weblogs.java.net/blog/kgh/archive/2004/10/multithreaded_t.html argues that multithreaded GUI frameworks are a failed dream. What about non-GUI frameworks?
Yesterday,I read the glassfish embed example this address is: http://weblogs.java.net/blog/arungupta/archive/2008/11/totd_56_simple.html but I running the
I'm creating new Site Definitions using this method: http://weblogs.asp.net/paulballard/archive/2007/04/09/creating-a-custom-sharepoint-2007-portal-site-definition-using-the-portalprovisioningprovider-class.aspx and when they get created,
Hi i was using HttpModule to Perform Extension-Less URL Rewriting as explained at http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Like this one? http://weblogs.asp.net/dwahlin/archive/2007/09/09/c-3-0-features-object-initializers.aspx Person p = new Person() { FirstName = John, LastName
I'm working through the ASP.NET MVC article at http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx . (Note: Some of the
I would like to test my custom fxrules. I've seen this post : http://weblogs.asp.net/rosherove/archive/2007/02/24/writing-real-unit-tests-for-your-custom-fxcop-rules.aspx
I read ScottGu's blog entry ( http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx ) a while back, and it seems
I'm trying to create something almost similar to this [1]: http://weblogs.asp.net/infinitiesloop/archive/2007/09/17/inline-script-inside-an-asp-net-ajax-updatepanel.aspx The problem I

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.