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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:36:53+00:00 2026-06-02T20:36:53+00:00

I am rendering some images that are layered in a JEditorPane. I’ve read that

  • 0

I am rendering some images that are layered in a JEditorPane. I’ve read that JEditorPane is pretty rocky at best, however I am hoping that this is an issue with either my HTML code or something else. Here’s how my content looks in the browser:

enter image description here

And how it looks in a JScrollBar(JEditorPane):

enter image description here

The HTML code: http://pastebin.com/EixG3WLH

The Java code:

File f = new File("index.html");
JEditorPane jep = new JEditorPane(f.toURI().toURL());
JScrollPane sp = new JScrollPane(jep);

JFrame frame = new JFrame();
frame.add(sp);
jep.setEditable(false);

frame.setVisible(true);
frame.setSize(500, 500);
frame.setTitle(wpj.getParse().getTitle());

I’d really rather not use FlyingSaucer if this issue can be resolved in a JEditorPane!

  • 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-06-02T20:36:56+00:00Added an answer on June 2, 2026 at 8:36 pm

    You can do it… but it’s not really simple… because JEditorPane doesn’t have CSS absolute positioning… so, you must first at all, recognize if some element had the position:absolute or position:fixed attribute extending the ViewFactory, something like:

    public class ExtendedHTMLEditorKit extends HTMLEditorKit{
    //.... other code here
        public class MyHTMLFactory extends HTMLFactory{
          //other code here
          @Override
          public View create(Element elem) {
              if (isLayered(elem)){ //it means, it has position attribute
                 return new PositionedView(elem);
              }
              else 
                return super.create(elem);
          }
    
          boolean isLayered(Element elem){
              SimpleAttributeSet sas = new  SimpleAttributeSet(elem);
              StyleSheet styles = (HTMLDocument elem.getDocument).getStyleSheet();
              Tag tag = element.getAttributes().getAttribute(AttributeSet.NameAttribute);
              sas.addAttributes(styleSheet.getRule(tag, element));
              return sas.isDefined("position") 
                && !sas.getAttribute("position").toString().equalsIgnorecase("static");
          }
        }
    }
    

    In this case, we need then to build a correct view for your element… I don’t know if you’re only positioning images (in this case, it could be simple) or a lot of things… I can see on your code, you’re using divs…

    Let me explain more or less what I do: I’ve created a ComponentView, and returning as a component a new JEditorPane, where I put the innerCode of the original element… and after that, move it on correct position of parent editor…

    To synchronize this is really dificult to allow edit, but if you only whant to use them to display, it must be more simple…

    ok.. the view must be like:

    public class PositionedView extends ComponentView{
       private JEditorPane view;
       private JEditorPane parent;
    
        @Override
        public Component createComponent(){
           if (view == null){
             view = new JEditorPane();
           }
           String innerText = dumpInnerText(getElement());
           view.setText(innerText);
           view.setLocation(getAbsoluteX(), getAbsoluteY());
           parent.add(view);
        }
    
        @Override
        public void setParent(View parent) {
          if (parent != null) {
    
            java.awt.Container host = parent.getContainer();
            if (host != null && host instanceof JEditorPane) {
                parent = (JEditorPane) host;
            }
          }
    
        super.setParent(parent);
       }
    
        protected int getAbsoluteX() {
         //search for the attribute left or right and calculate the position over parent
        }
    
        protected int getAbsoluteY(){
         //search for the attribute top or bottom and calculate the position over parent
        }
    
        protected String dumpInnerText(Element element){
         //there are several ways to do it, I used my own reader/writer, 
         //because I've need add special tags support...
        }
    }
    

    I hope this helps you… Ah! there are another thing: if you do this, you must secure your view is not opaque, and it means, all the view elements, on the other case, you will have a blank rect for your elements.

    Another thing, you maybe need to check for the correct dimension of the view… do as getAbsoluteX / getAbsoluteY to obtain width / height attributes.

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

Sidebar

Related Questions

I have a spring action that I am rendering some json from the controller,
I noticed that I get too many database hits whilst rendering some complicated pages
It seems that none of these solutions eliminate the lag associated with rendering images
I want to do pixel-true rendering of some images on my Canvas. Right now,
I'm looking at some older code which is rendering some images, animations, etc... for
I would like to generate some images dynamicaly. For that, I intend to create
I know that a method for rendering pdf pages into images is available natively
I'm having some difficulty rendering my UITabBar in the language I want. I'm developing
I've been using the jQuery.svg plugin to do some SVG rendering and it works
For some reason the HTML2PDF/TCPDF is not rendering the PDF... and I have no

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.