您需要使用JTextPane并使用属性。以下应该使所有文本居中:
Styleddocument doc = textPane.getStyleddocument();SimpleAttributeSet center = new SimpleAttributeSet();StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);doc.setParagraphAttributes(0, doc.getLength(), center, false);
编辑:
据我所知,不支持垂直居中。以下是一些可能会有用的代码:JTextPane的垂直对齐



