Search code examples
javaimageswingalignmentjeditorpane

Align html content(image) of a JEditorPane


I have a JEditorPane that is by default 450px X 400px where i put inside an image that is 250px X 250px using HTML in this way :

JEditorPane editorPanePreview = new JEditorPane();
String logosrc = MainWindow.class.getResource("/resources/logo.png").toString();
editorPanePreview.setText("<html><img src='" + logosrc + "' ></img></html>");

the image is shown correctly but it is by default aligned in the top left corner of the JEditorPane, i want to align it in the bottom right corner of the JEditorPane; Is it possible ?

How can align the content of the JEditorPane in the right bottom corner ?


Solution

  • See this http://java-sl.com/tip_center_vertically.html to align content vertically.

    You need another view (body or BlockView) to be overridden for HTMLEditorKit though.