MooHa
MooHa

Reputation: 849

JEditorPane component text alignment and background

GUI with 2 JEditorPane Components

Hey All, I have two JEditorPane in my GUI, from the image the two with hyperlinks. Although in NetbeansIDE I align them together, the page editorpane appears to be shifting right everytime and its pretty annoying. I'm also trying to remove the pointless white background but failing.

Here's some setup for them:

        private void initEditorPane(JEditorPane editorPane) {
        editorPane.setBorder(null);
        editorPane.setContentType("text/html");
        editorPane.setEditable(false);
        editorPane.setOpaque(false);
        editorPane.addHyperlinkListener(new HyperlinkListener() {
            @Override
            public void hyperlinkUpdate(HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    launchHyperLink(e);
                }
            }
        });
    }

I am not sure if it's the above causing the problems, or this:

pageTxtComp.setText("<html>&nbsp;<a href='" + ac.getPage() + "'>" + ac.getPage() + "</a>&nbsp;</html>");


emailTxtComp.setText("<html>&nbsp;<a href='mailto://" + ac.getEmail() + "'>" + ac.getEmail() + "</a>&nbsp;</html> ");
  1. How can I improve the alignment?

  2. How can I remove the white background? In Properties, I've tried choosing a matching background colour with panel, does not do the trick.

Upvotes: 0

Views: 1267

Answers (1)

StanislavL
StanislavL

Reputation: 57421

You can get Document from the pane. Cast it to StyledDocument and use setParagraphAttributes() setting desired alignment or change alignment by adding < p > < / p > tags specifying the alignment there.

For background try to set opaque to false for the pane.

Upvotes: 1

Related Questions