「java定义font」Java定义接口

博主:adminadmin 2022-12-22 02:18:09 62

今天给各位分享java定义font的知识,其中也会对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 字体设置 Font

你查一下小四是多少号字体就可以啦,然后把小四替换成你要的字体就行了吧,应该是12号吧

Java Font设置问题

Font的构造方法其中有一个是Font(String name, int style, int size)

,根据指定名称、样式和磅值大小,创建一个新 Font。

中间那个参数是指文字的样式,Font.CENTER_BASELINE具体指什么样式我不太清楚,需要测试下,样式就是诸如:Font.BOLD是指粗体样式、Font.PLAIN指普通样式,一类的参数。

有关JAVA的问题,求解答。在JAVA中如何设置字体类?即是如何使用Font类和获得Font类啊?

比如:

JLabel la1=new JLabel("你好");

la1.setFont(new font("楷体",0,24));

Font有三个参数:new Font(String ,int ,int)

第一个String是字体名称,第二个int是字形,0代表正常、1代表粗体、2代表斜体、3代表粗斜体,第三个int代表字号,即字体的大小

请问java中怎样设置字体的颜色?

定义Font可以为控件设置字体样式。

Font

font=new

Font("宋体",Font.ITALIC|Font.BOLD,16);

就可以定义出一个粗体加斜体,16号的宋体Font

再为需要的标签设置Font即可。

因为这个Font类是在awt包中的,所以一般用起来都是为控件进行设置字体样式的。

要为控件上的字体设置颜色,可以设置该控件的前景色,比如Button控件,就可以利用其中的方法setForeground(Color)来设置。

如果是要设置applet中的字体颜色就更好办了,直接利用g.setColor()方法,再用g来绘制字符串就可以了。

你的这个问题问的不太清楚,也不知道是不是想要设置控件上的字体颜色。

Java 关于Font类的字体设置

import java.awt.BorderLayout;

import java.awt.Choice;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.Frame;

import java.awt.GraphicsEnvironment;

import java.awt.Label;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;import javax.swing.JLabel;public class Test_24 extends Frame implements ItemListener { private static final long serialVersionUID = 1L;

Choice c;

JLabel l; public static void main(String[] args) {

new Test_24(); } public Test_24() {

super();

initialize();

} private void initialize() {

this.setSize(300, 200);

this.setTitle("Frame");

GraphicsEnvironment g = GraphicsEnvironment

.getLocalGraphicsEnvironment();

String fontName[] = g.getAvailableFontFamilyNames();

c = new Choice();

for (int i = 0; i fontName.length; i++)

c.add(fontName[i]);

l = new JLabel("", JLabel.CENTER);

this.add(c, BorderLayout.NORTH);

this.add(l, BorderLayout.CENTER);

this.setVisible(true);

c.addItemListener(this);

this.addWindowListener(new java.awt.event.WindowAdapter() {

public void windowClosing(java.awt.event.WindowEvent e) {

System.exit(0);

}

});

} public void itemStateChanged(ItemEvent e) {

String name = (String) e.getItem();

System.out.println(name);

Font f = new Font(name, Font.ITALIC, 40);

l.setForeground(Color.red);

l.setFont(f);

l.setText("测试字体");

double x=l.getLocation().getX();

double y=l.getLocation().getY();

int h = l.getSize().height;

int w = l.getSize().width;

System.out.println(x+","+y);

System.out.println(h+","+w);

}}

关于java定义font和Java定义接口的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-12-22,除非注明,否则均为首码项目网原创文章,转载请注明出处。