Java:JScrollPane JLabel太接近边缘了

时间:2014-04-21 20:51:15

标签: java html swing jlabel scrollpane

我在jscrollpane里面有一个jlabel,用html格式化它。代码在github上here问题是,即使向右对齐,两个h1标签内的文本也太靠近左边。任何帮助将不胜感激:)

package malgm.minecraft.versioninstaller.ui.tabs.credits;

import java.awt.BorderLayout;

import javax.swing.*;

import malgm.minecraft.versioninstaller.*;
import malgm.minecraft.versioninstaller.ui.TechUI;
import malgm.minecraft.versioninstaller.ui.controls.TiledBackground;

public class CreditsInfoPanel extends TiledBackground {

    private static final long serialVersionUID = 1L;

    private static ResourceFinder resFinder = new ResourceFinder();
    private Data data = new Data();

    public CreditsInfoPanel(ResourceLoader loader) {
        super(loader.getImage(resFinder.background()));

        BorderLayout layout = new BorderLayout();
        setLayout(layout);

        // Welcome text
        JLabel text = new JLabel("<html>"
                + "<div align=\"right\">"
                + "<h1>" + data.getMVIName() +" build "+ data.getMVIBuild() +"</h1>"
                + "</div>"
                + "<center>"
                + "<h3>Development team:</h3>"
                + "<p>malgm (Jamie)</p>"
                + "<h3>Special thanks to:</h3>"
                + "<p>The Technic Team without them I wouldn't have this design.</p>"
                + "<p>Github for having such a wonderful service.</p>"
                + "<br />"
                + "</center>"
                + "<div align=\"right\">"
                + "<h1>" + data.getMMLName() +" build "+ data.getMMLBuild() +"</h1>"
                + "</div>"
                + "<center>"
                + "<h3>Development team:</h3>"
                + "<p>malgm (Jamie)</p>"
                + "</center></html>");
        text.setForeground(TechUI.COLOR_WHITE_TEXT);

        JScrollPane s = new JScrollPane(text);
        s.setOpaque(false);
        s.getViewport().setOpaque(false);
        s.setBorder(null);

        add(s, BorderLayout.CENTER);
    }

}

2 个答案:

答案 0 :(得分:1)

尝试添加margin-left

"<div style='margin-left: 10px;'>"

答案 1 :(得分:1)

试试这个: text.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));