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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:18:00+00:00 2026-05-21T19:18:00+00:00

Hi there I’m trying to format HTML content in Swing. Formattings such as color

  • 0

Hi there
I’m trying to format HTML content in Swing. Formattings such as color or text-decoration are working fine. But when it comes to margin of links it is not working at all.

This is all the CSS syntax I’m using:

StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("a {font : arial; text-decoration: none; color: #0174DF; margin-left: 50px}");

everything, except the margin-left is working. I tested the syntax in a Browser and it works fine there. I also tried using text-align: left or display: block becouse I found some articles pointing out that margin of links would not work without.

The following HTML code is used:

<html><head></head><body><div>
<a href="http://www.zhaw.ch" style="font-size: 50.24324324324324px">akamaitechnologies.com</a>
<a href="http://www.zhaw.ch" style="font-size: 17.37837837837838px">amazonaws.com</a>
<a href="http://www.zhaw.ch" style="font-size: 18.243243243243242px">cotendo.net</a>
<a href="http://www.zhaw.ch" style="font-size: 24.08108108108108px">facebook.com</a>
<a href="http://www.zhaw.ch" style="font-size: 17.594594594594597px">google.ch</a>
<a href="http://www.zhaw.ch" style="font-size: 55.0px">heise.de</a>
<a href="http://www.zhaw.ch" style="font-size: 16.08108108108108px">ip-plus.net</a>
<a href="http://www.zhaw.ch" style="font-size: 21.054054054054056px">ligatus.com</a>
</div></body></html>

The HTML code is generated by a library and can’t be modified.

From my understanding of HTML/CSS it is not possible to add margin style information to an inline object like a link becouse margin-top or margin-bottom is not possible. margin-left oder margin-right however should not be a problem.

thx

edit: by the way, I’m using HTMLEditorKit.

  • 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-21T19:18:01+00:00Added an answer on May 21, 2026 at 7:18 pm

    This is my last attempt before I give up or go mad (or both).

    TestHtmlIndent.java

    import javax.swing.*;
    
    class TestHtmlIndent {
    
        public static void main(String[] args) {
            String raw =
                "<html><head></head><body><div>" +
                "<a href=\"http://a.b\" style=\"font-size: 20px\">akamaitechnologies.com</a>" +
                "<a href=\"http://a.b\" style=\"font-size: 17px\">amazonaws.com</a>" +
                "<a href=\"http://a.b\" style=\"font-size: 18px\">cotendo.net</a>" +
                "<a href=\"http://a.b\" style=\"font-size: 24px\">facebook.com</a>" +
                "<a href=\"http://a.b\" style=\"font-size: 17px\">google.ch</a>" +
                "<a href=\"http://a.b\" style=\"font-size: 25px\">heise.de</a>" +
                "<a href=\"http://a.b\" style=\"font-size: 16px\">ip-plus.net</a>" +
                "<a href=\"http://a.b\" style=\"font-size: 21px\">ligatus.com</a>" +
                "</div></body></html>";
            String style =
                "<style type='text/css'>" +
                "body {width: 600px;}" +
                ".cloudLink {text-decoration: none; color: #0174DF; " +
                "font-family: helvetica, arial, sans-serif;}" +
                "</style>";
            raw = raw.replace("<head></head>", "<head>" +  style + "</head>");
            String space4 = "&nbsp;&nbsp;&nbsp;&nbsp";
            String space20 = space4 + space4 + space4 + space4 + space4;
            final String processed1 = raw.replace(
                "<a ", space20 + "<a class='cloudLink' ");
    
            Runnable r = new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(null, processed1);
                }
            };
            SwingUtilities.invokeLater(r);
        }
    }
    

    Screenshot

    enter image description here

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

Sidebar

Related Questions

There seems to be a similar question to this on here but with the
There is a text file with 1,000,000 lines of code floating around and Ctrl+F
there's a drop down html element for date for the current month (January 1
There are many tutorials that talk about deleting index.php from the url. But I
There must be a simple solution to this, but after 4 hours of browsing
There's a lot of reading on self referencing problems, but I can't seem to
There are things like f.call(...) f.apply(...) But then there's this (1, alert)('Zomg what is
There are many great solutions for mobile detection out on the web such as
There are so many different ways to include JavaScript in a html page. I
There is a perforce bundle for TextMate but I can't get to auto-check out

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.