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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:45:36+00:00 2026-05-15T13:45:36+00:00

Edit – in short, what I’m looking for is a reliable way to add

  • 0

Edit – in short, what I’m looking for is a reliable way to add a left margin to a JEditorPane (read on for the issues I’m having if you’d like).


I am trying to style some text in a JEditorPane, and have been fairly successful. The only problem I’m facing is that it seems impossible to create a margin.

Basically, I’ve extended PlainView and overridden the drawUnselectedText method. For now I just have it coloring the text red and changing the font. I’ve also overridden the drawSelectedText method to color the text.

This works consistently, whether text is selected or not, regardless of cursor position etc. – as long as I don’t have a margin set.

However if I set a margin for the JEditorPane, the JEditorPane only works most of the time. The only case where it doesn’t work is when a selection is made starting at the left-most character of any line. In that case, the margin is simply ignored and the selected text appears to the far left of the JEditorPane.

I know this is a pretty specific issue that most other people probably haven’t experienced, and I have found nothing on the net about this, but I’m hoping someone here will have a solution.

Any ideas? Even anything that would allow me to set a margin using some other method than what I’m doing would be extremely helpful.

  • 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-15T13:45:36+00:00Added an answer on May 15, 2026 at 1:45 pm

    I gave up on finding an elegant solution to this problem. Basically I created a hack which tests whether or not the conditions exist where the bug will occur (selection from left, etc), and if they do it adjusts the rendering of the text.

    I really don’t like hacks as they are often bad for portability and maintainability, but this seems to work, so I suppose I’ll abstract it away and hope it doesn’t break anything.

    In any case, it’s working which is the key point. I didn’t receive any answers, but I’m sure there are some people who at least tried to think of something, so thanks 🙂

    Btw – if someone can come up with an elegant solution I will still accept that instead of my own answer (I can’t anyways for two days).


    Edit: This is one reason I like Java. Hacks are less likely to cause portability issues – even though this is related to rendering (it works through interaction with a Graphics object), it should still work on any OS.

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

Sidebar

Related Questions

(EDIT: I have asked the wrong question. The real problem I'm having is over
Edit: I would like to keep the infrastructure as is, so while the framework
EDIT: Please, please , please read the two requirements listed at the bottom of
Edit I am having an XSLT to convert my xml into html format(I dont
edit: change of question if my code is like this: <form name=login action=https://login.extremebb.net/login method=post
EDIT The question was finding the divisors of numbers like 1,3,6,10,15 which follows n*(n+1)/2
Edit: For personn interested in a cleaner way to implemenent that, have a look
EDIT: This question was exceptionally dumb and made me look like a script kiddie,
EDIT: looking for this: http://diminishing.org/extending-formtastic-with-a-sprinkle-of-jquery (If this works I'll answer my own question) I've
EDIT: Updated thanks to @daroczig's lovely answer below. However, test 2 still feels like

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.