JTextPane 设置其中的字体样式

当设置字体样式后,JTextPane中的所有字体都会改变:

	/**
	 * 设置聊天信息输入框中字体的属性
	 */
	private void initMsgInputTextPaneFont() {
		StyledDocument doc = msgInputTxtPane.getStyledDocument();
		SimpleAttributeSet arrSet = new SimpleAttributeSet();
		StyleConstants.setFontFamily(arrSet, msgFont.getFontFamily());
		StyleConstants.setFontSize(arrSet, msgFont.getFontSize());
		StyleConstants.setBold(arrSet, msgFont.isBold());
		StyleConstants.setItalic(arrSet, msgFont.isItalic());
		StyleConstants.setUnderline(arrSet, msgFont.isUnderline());
		StyleConstants.setForeground(arrSet, msgFont.getColor());
		//设置已经输入的文字属性
		doc.setCharacterAttributes(0, doc.getLength(), arrSet, false);
		//设置将输入的属性
		msgInputTxtPane.setCharacterAttributes(arrSet, false); 
	}

 

你可能感兴趣的:(Swing,java)