Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中下划线字体的常量值是多少?_Java_Class_Fonts_Bold_Underline - Fatal编程技术网

Java中下划线字体的常量值是多少?

Java中下划线字体的常量值是多少?,java,class,fonts,bold,underline,Java,Class,Fonts,Bold,Underline,Java中下划线字体的常量值是多少 Font.BOLDBOLDFont 字体。斜体 下划线字体常量是多少? 我尝试了所有可用的常量,但都不起作用。下划线不是字体的属性,而是文本段的属性。渲染时,文本以指定的字体渲染,然后在其下方绘制一条线。根据您正在使用的框架,这可以使用属性为您完成,也可以由您自己完成。对于SWT,您可以使用: StyledText text = new StyledText(shell, SWT.BORDER); text.setText("0123456789 ABCDEF

Java中下划线字体的常量值是多少

Font.BOLDBOLDFont

字体。斜体

下划线字体常量是多少?
我尝试了所有可用的常量,但都不起作用。

下划线不是字体的属性,而是文本段的属性。渲染时,文本以指定的字体渲染,然后在其下方绘制一条线。根据您正在使用的框架,这可以使用属性为您完成,也可以由您自己完成。

对于SWT,您可以使用:

StyledText text = new StyledText(shell, SWT.BORDER);
text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");
// make 0123456789 appear underlined
StyleRange style1 = new StyleRange();
style1.start = 0;
style1.length = 10;
style1.underline = true;
text.setStyleRange(style1);
查看,似乎没有用于下划线的常量

但是,使用构造函数,可以为它提供一个
映射
,其中包含要使用的和值,以便指定字体属性。(请注意,
texttribute
类是
AttributedCharacterIterator.Attribute
的子类)

似乎是感兴趣的
texttribute


编辑:在中的部分中有一个使用
texttribute
的示例。

假设您想要一种带下划线和粗体的衬线字体,size=12

Map<TextAttribute, Integer> fontAttributes = new HashMap<TextAttribute, Integer>();
fontAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
Font boldUnderline = new Font("Serif",Font.BOLD, 12).deriveFont(fontAttributes);
MapFontAttributes=newHashMap();
fontAttributes.put(TextAttribute.UNDERLINE,TextAttribute.UNDERLINE\ON);
字体粗体下划线=新字体(“衬线”,Font.BOLD,12)。衍生字体(fontAttributes);

如果不希望使用粗体,请使用Font.PLAIN而不是Font.BOLD。不要使用Font类的getAttributes()方法。它将为您提供一个疯狂的通配符参数化类型
Map
,您将无法调用put()方法。有时Java会像那样令人讨厌。如果您对原因感兴趣,可以查看此网站:

stackoverflow ftw。我今天也在找这个。我已经使用html来获得这个结果有一段时间了,但这带来了许多其他问题。有趣的是,如果你试图关闭下划线,你将找不到一个
underline\u off
常量。但您可以使用value
-1
来执行此操作。例如:
fonttributes.put(texttribute.UNDERLINE,-1)+1表示
put
不工作。我刚刚遇到它:)我最终使用了
AttributeMap att=(AttributeMap)font.getAttributes(),因为
Font.getAttribute()
使用它。@Blake我实现了下划线的代码,但我看不到下划线。我使用的是AWT标签,正如您所解释的,我想在其中放置带下划线的字符串。