Java 如何使它看起来很好的句子行距
我开发了一些项目,当我拖动单词并单击特殊按钮时,它可以为单词添加标签 我想做一个单词周围的标签(红色的开始和结束标签)(请参考考试图片,这个) 但当它标记在文本的开始和结束处时,它会占用空空格(如图2)。 当我拖动这些空格时,没有真正的空格(空格或“”或“\nbsp”-不,永远不会),那只是空空格 我不能选择那个空间 图片。链接 下面是我的代码: 属性:Java 如何使它看起来很好的句子行距,java,swing,jtextcomponent,Java,Swing,Jtextcomponent,我开发了一些项目,当我拖动单词并单击特殊按钮时,它可以为单词添加标签 我想做一个单词周围的标签(红色的开始和结束标签)(请参考考试图片,这个) 但当它标记在文本的开始和结束处时,它会占用空空格(如图2)。 当我拖动这些空格时,没有真正的空格(空格或“”或“\nbsp”-不,永远不会),那只是空空格 我不能选择那个空间 图片。链接 下面是我的代码: 属性: static final Color TAG_COLOR = new Color(255, 50, 50); static final Col
static final Color TAG_COLOR = new Color(255, 50, 50);
static final Color PLAIN_TXT_COLOR = new Color(0, 0, 0);
public static SimpleAttributeSet plainAttr = new SimpleAttributeSet();
public static SimpleAttributeSet tagAttr = new SimpleAttributeSet();
StyleConstants.setAlignment(plainAttr, StyleConstants.ALIGN_JUSTIFIED);
StyleConstants.setForeground(plainAttr, PLAIN_TXT_COLOR);
StyleConstants.setFontSize(plainAttr, 11);
StyleConstants.setBold(plainAttr, false);
StyleConstants.setAlignment(tagAttr, StyleConstants.ALIGN_JUSTIFIED);
StyleConstants.setForeground(tagAttr, TAG_COLOR);
StyleConstants.setFontSize(tagAttr, 11);
StyleConstants.setBold(tagAttr, true);
标记功能:
public static void tag_functiont() {
String taggedName = "tagMark";
int start_sel = mainEditText.getSelectionStart();
int end_sel = mainEditText.getSelectionEnd();
String selected = mainEditText.getSelectedText();
StyledDocument doc = mainEditText.getStyledDocument();
if(selected == null || selected.isEmpty()) return;
try {
String bTag = "__B:"+taggedName+"__";
String eTag = "__E:"+ taggedName +"__";
doc.insertString(start_sel, bTag, tagAttr);
doc.insertString(start_sel+bTag.length()+selected.length(), eTag, tagAttr);
} catch (Exception e) {
e.printStackTrace();
}
}
我还研究了所有可能的属性选项。
(某些字体,各种排列;居中、右、左、对齐)
有人能给我一个建议吗
解决了的 我在主源代码中添加了“textPane.setContentType(“html/text”);太愚蠢了。
它触发了
&
标记..因此该段落变糟了。使用HtmlDocument。您可以使用该链接作为示例。我也尝试了该链接,但在我的情况下,“html/text”使整个项目更加困难,因此我正在尝试寻找其他方法,除了用于编辑标题和标记的html.mKorbel//thxs