【发布时间】:2014-06-30 01:13:09
【问题描述】:
我尝试将中心垂直对齐应用于 JEditorPane 中的文本。但是文本仍然与顶部对齐。我哪里搞错了?
JEditorPane editor = new JEditorPane();
editor.setText("..large text block..");
editor.setAlignmentY(JEditorPane.CENTER_ALIGNMENT); // DOESN'T WORK
JFrame frame = new JFrame();
frame.setSize(600, 400);
frame.setVisible(true);
frame.add(editor);
【问题讨论】:
-
请编辑您的问题以包含mcve,以在上下文中显示您的方法。
-
您是否正在寻找
JEditorPane中的文本居中垂直对齐?或者您只想将小部件放在中心? -
Braj,将小部件放置在中心的解决方案更简单。你的答案是有效的,但一个太复杂了。感谢您花时间回答!
-
在这里找到它Centering text vertically in JEditorPane.。有关更多信息,请查看此线程 Vertical Alignment of Text in JEditorPane
标签: java swing jeditorpane