「java字体名称」java字体设置怎么比较好看
本篇文章给大家谈谈java字体名称,以及java字体设置怎么比较好看对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、java 字体设置
- 2、java 中怎样只设置指定文字的字体,如宋体等,而不是字号什么的都设置,text.setfont("宋体");报错,
- 3、你们在编写java的代码的时候一般用什么样的字体
- 4、Java中设置字体
- 5、java 设置字体格式
java 字体设置
1、对字体的操作
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setFontFamily(attr, family);
setCharacterAttributes(editor, attr, false);
family为字体
2、对字体大小的操作
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setFontSize(attr, size);
setCharacterAttributes(editor, attr, false);
size为字号
3、是否是粗体的操作
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
boolean bold = (StyleConstants.isBold(attr)) ? false : true;
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setBold(sas, bold);
setCharacterAttributes(editor, sas, false);
4、是否是斜体的操作
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
boolean italic = (StyleConstants.isItalic(attr)) ? false : true;
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setItalic(sas, italic);
setCharacterAttributes(editor, sas, false);
5、是否有下划线的操作
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
boolean underline = (StyleConstants.isUnderline(attr)) ? false
: true;
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setUnderline(sas, underline);
setCharacterAttributes(editor, sas, false);
6、左中右对齐的处理
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setAlignment(attr, a);
setParagraphAttributes(editor, attr, false);
public static final void setParagraphAttributes(JEditorPane editor,
AttributeSet attr, boolean replace) {
int p0 = editor.getSelectionStart();
int p1 = editor.getSelectionEnd();
StyledDocument doc = getStyledDocument(editor);
doc.setParagraphAttributes(p0, p1 - p0, attr, replace);
}
a:0:左,1:中,2:右
7、文本字体颜色的设置
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setForeground(attr, fg);
setCharacterAttributes(editor, attr, false);
fg:为color
8、文本背景颜色的设置
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setBackground(attr, bg);
setCharacterAttributes(editor, attr, false);
java 中怎样只设置指定文字的字体,如宋体等,而不是字号什么的都设置,text.setfont("宋体");报错,
一般有一个Font类,然后应用到相应位置object.setFont(new Font());
Java.awt.Font
设计字体显示效果 Font mf = new Font(String 字体,int 风格,int 字号);
字体:TimesRoman, Courier, Arial等
风格:三个常量 lFont.PLAIN, Font.BOLD, Font.ITALIC
字号:字的大小(磅数)
设置组件当前使用的字体:setFont(Font fn)
获取组件当前使用的字体:getFont()
你们在编写java的代码的时候一般用什么样的字体
一般适合用作程序代码显示的字体,有下列几个:
(1):Courier New 9pt, Verdana, Lucida Console (宋体,新宋体等不在讨论之列)
首先说说Courier New, 这个字体虽说经典,但总体感觉其实不好。因为是等宽字体,所以对编程而言,其优点是每个字符区分的十分清楚,方便查找程序中的输入错误。不好的地方在于,因为是等宽字体,特别浪费显示空间,在看代码的时候恨不得显示器变成 21寸的才好。总之就是感觉用来看那种大的框架的源代码的时候,非常不适合。一屏只能看到很少的几句代码,有只见树木,不见森林之感,不利于从宏观角度理解代码的逻辑。另外在 VS.NET 2003 里面该字体显示的中文特别大,而且很丑陋 -_-!
(2):Verdana: 非等宽字体。总体可读性好些,但是小的错误,比如多一个少一个空格之类的,很难排查。
Lucida Console 是等宽字体。可读性也不错,但是 vs.Net 显示出来有锯齿。
serif 字体通常不同笔顺的粗细有别,且起笔落笔处有多余的小折线。
sans-serif 字体笔画不论方向粗细相同,且起笔落笔没有多余折线。
中文字体中,可以与此类比:宋体相当于 serif 字体,黑体相当于 sans-serif 字体。
正文中应该用 serif 字体以提高可读性,标题可以用 sans serif 字体以示强调。
(3):serif 字体在视觉上强调单词的整体,因此作为正文更可读;而 sans serif 强调单个的字母。
研究显示,在 web 中 sans-serif 字体更易阅读。正文字体比较好的选择:Arial 9.75 或 MS Sans Serif 9.75。为了提高阅读准确性和速度,最好的字体大小是 8.25, 9.0, 或 9.75("MS Serif 8.25" 除外)。
(4)养眼的编辑器配色
环境:VS2005
字体:Verdana, 10pt
普通文本背景色:238,239,230 (#E6EFEE)
Java中设置字体
java中没有自带的字体对话框,这需要自己来编写。
text.setFond("字体名字",字形(如,fond.bold),大小)
import java.awt.*;
import java.awt.event.*;
import javax.swing.JColorChooser;
//import javax.swing.border.*;
class ff extends Frame implements ActionListener
{
Choice font,size,bolder;
Button bb;
ff(String s)
{
setTitle(s);
font=new Choice();
bolder=new Choice();
size=new Choice();
//bolder.add加监视器
//font.add加监视器
//size.add加监视器
Panel p1=new Panel();
Panel p2=new Panel();
bb=new Button("点击打开");
bb.addActionListener(this);
p1.setLayout(new GridLayout(4,1));
p2.setLayout(new GridLayout(4,1));
GraphicsEnvironment gg=GraphicsEnvironment.getLocalGraphicsEnvironment();
String ss[]=gg.getAvailableFontFamilyNames();
String bold[]={"Font.BOLD","Font.CENTER_BASELINE","Font.CENTER_BASELINE","Font.ITALIC",
"Font.PLAIN","Font.ROMAN_BASELINE","Font.TRUETYPE_FONT"};
for(int i=126;iss.length;i++)
font.add(ss[i]);
for(int i=12;i=64;i+=2)
{
String w=String.valueOf(i);
size.add(w);
}
for(int i=0;ibold.length;i++)
{
bolder.add(bold[i]);
}
p1.add(new Label("请选择字体"));
p1.add(font);
p1.add(new Label("请选择大小"));
p1.add(size);
p2.add(new Label("请选择字型"));
p2.add(bolder);
p2.add(new Label("请选择字体颜色"));
p2.add(bb);
add(p2,BorderLayout.WEST);
add(p1,BorderLayout.EAST);
setSize(250,150);
setVisible(true);
pack();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent ee)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
Color cc=JColorChooser.showDialog(this,"颜色对话框",null);
bb.setBackground(cc);//应用举例
}
}
public class font
{
public static void main(String[] args)
{
new ff("字体对话框");
}
}
java 设置字体格式
Java Swing中可以给每个控件设置字体格式和其他属性的设置,示例如下:
submit= new JButton("登陆");
submit.setFont(new Font("宋体", Font.PLAIN, 16));
三个参数分别表示: 字体,样式(粗体,斜体等),字号
submit.setForeground(Color.RED);
这个表示给组件上的文字设置颜色Color.RED表示红色
当然你也可以自己给RGB的值 比如 submit.setForeground(new Color(215,215,200));
关于java字体名称和java字体设置怎么比较好看的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。