public void caretUpdate(CaretEvent e)
	{
		if (e.getSource() instanceof JTextPane)
		{
			final JTextPane tp = (JTextPane) e.getSource();

			Runnable r = new Runnable()
			{
				public void run()
				{
					for (int i = 0; i < sFontStyleNames.length; i++)
					{
						String buttonName = sFontStyleNames[i];
						JToggleButton button = (JToggleButton) mButtons
								.get(buttonName);
						button.setSelected(false);
					}
					mAlignmentGroup.setSelected(mNullButtonModel, true);

					JToggleButton button1 = (JToggleButton) mButtons
							.get(sFontStyleNames[0]);
					button1.setSelected(AttributeChecker.isBold(tp));

					JToggleButton button2 = (JToggleButton) mButtons
							.get(sFontStyleNames[1]);
					button2.setSelected(AttributeChecker.isItalic(tp));

					JToggleButton button3 = (JToggleButton) mButtons
							.get(sFontStyleNames[2]);
					button3.setSelected(AttributeChecker.isUnderline(tp));

					/*
					 * Check for alignment attribute and select relevant alignment button.
					 */
					int align = AttributeChecker.checkAlignment(tp);

					if (align != -1)
					{
						JToggleButton button = (JToggleButton) mButtons
								.get(AttributeChecker.ALIGNMENT_NAMES[align]);
						mAlignmentGroup.setSelected(button.getModel(), true);
					}
					mLastColor = AttributeChecker.checkColour(tp);

					mFontFamily.setSelectedItem(AttributeChecker
							.checkFontFamily(tp));
					mFontSize.setSelectedItem(AttributeChecker
							.checkFontSize(tp));

					RepaintManager rm = RepaintManager.currentManager(mTB);
					rm.markCompletelyDirty(mTB);
					rm.paintDirtyRegions();

					AttributeChecker.checkAttributes(tp);
				}
			};

			// Perform at end of swing event queue to allow JTextPane Caret position to be updated first.
			SwingUtilities.invokeLater(r);
		}
	}