JTextPane and weird text issue
===

I am creating a simple chat program that I want to eventually show html links.  My problem right now is that I can't get the text to appear next to the users name as I want it to.

I want the user's name to be bold, and the text to appear right next to it, but for some reason the non bolded text appears centered.

If I do not bold the users name, it works fine.  The top two are how it appears when I have the names bolded, the bottom is when the name is not bolded.  I want it to appear like the bottom two, but with the names bolded.

![enter image description here][1]


Here is the code,  what am I doing wrong?


    package com.test;
    
    import java.awt.BorderLayout;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.WindowConstants;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.SimpleAttributeSet;
    import javax.swing.text.StyleConstants;
    
    public class JTextPaneTest extends JPanel {
    
    	JTextPane pane;
    
    	public JTextPaneTest() {
    		this.setLayout(new BorderLayout());
    
    		pane = new JTextPane();
    		pane.setEditable(false);
    		pane.setContentType("text/html");
    
    		JScrollPane scrollPane = new JScrollPane(pane);
    		this.add(scrollPane, BorderLayout.CENTER);
    
    	}
    
    	public void chatWithBold(String user, String text) {
    
    		SimpleAttributeSet bold = new SimpleAttributeSet();
    		StyleConstants.setBold(bold, true);
    
    		SimpleAttributeSet normal = new SimpleAttributeSet();
    
    		try {
    			pane.getDocument().insertString(pane.getDocument().getLength(),
    					user+": ", bold);
    		} catch (BadLocationException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    		try {
    			pane.getDocument().insertString(pane.getDocument().getLength(),
    					text + "\n", normal);
    		} catch (BadLocationException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    
    	public void chatNoBold(String user, String text) {
    
    		SimpleAttributeSet bold = new SimpleAttributeSet();
    		StyleConstants.setBold(bold, true);
    
    		SimpleAttributeSet normal = new SimpleAttributeSet();
    
    		try {
    			pane.getDocument().insertString(pane.getDocument().getLength(),
    					user+": ", normal);
    		} catch (BadLocationException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    		try {
    			pane.getDocument().insertString(pane.getDocument().getLength(),
    					text + "\n", normal);
    		} catch (BadLocationException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    
    	public static void main(String[] args) {
    		JFrame frame = new JFrame();
    
    		JTextPaneTest chat = new JTextPaneTest();
    		frame.add(chat);
    
    		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    
    		chat.chatWithBold("User1", "Hi everyone");
    		chat.chatWithBold("User2", "Hey.. Hows it going");
    		
    		chat.chatNoBold("User1", "Hi everyone");
    		chat.chatNoBold("User2", "Hey.. Hows it going");
    
    		frame.setSize(400, 400);
    
    		frame.setVisible(true);
    
    	}
    }


  [1]: http://i.stack.imgur.com/HxVpx.png