Java JEditorPane组件文本对齐和背景
嘿,大家好,我的GUI中有两个Java JEditorPane组件文本对齐和背景,java,swing,user-interface,jcomponent,jeditorpane,Java,Swing,User Interface,Jcomponent,Jeditorpane,嘿,大家好,我的GUI中有两个JEditorPane,这两个图像带有超链接。尽管在NetbeansIDE中,我将它们对齐在一起,但是editorpane页面似乎每次都在向右移动,这很烦人。我还试图删除毫无意义的白色背景,但失败了 以下是他们的一些设置: private void initEditorPane(JEditorPane editorPane) { editorPane.setBorder(null); editorPane.setCon
JEditorPane
,这两个图像带有超链接。尽管在NetbeansIDE
中,我将它们对齐在一起,但是editorpane
页面似乎每次都在向右移动,这很烦人。我还试图删除毫无意义的白色背景,但失败了
以下是他们的一些设置:
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);
}
}
});
}
我不确定是上述原因导致了问题,还是:
pageTxtComp.setText("<html> <a href='" + ac.getPage() + "'>" + ac.getPage() + "</a> </html>");
emailTxtComp.setText("<html> <a href='mailto://" + ac.getEmail() + "'>" + ac.getEmail() + "</a> </html> ");
pageTxtComp.setText(“”);
emailTxtComp.setText(“”);
如何改进对齐
如何删除白色背景?在属性中,我尝试过选择与面板匹配的背景色,但并没有做到这一点
您可以从窗格中获取文档
。将其强制转换为StyledDocument
并使用setParagraphAttributes()
设置所需的对齐方式,或通过添加指定对齐方式的标记来更改对齐方式
对于背景,请尝试将窗格的“不透明”设置为false。不透明在“属性”工具栏上以及代码中都已为false,仍将出现。这与编辑器窗格本身无关(即,您发布的代码与问题无关)。布局管理器可能会出现问题。我不使用IDE创建表单,所以我不确定您的问题是什么。可能IDE在编辑器窗格前插入了一个不可见的组件。或者,您可能以某种方式更改了IDE中的一个属性,导致编辑器窗格右对齐。