新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java怎么设置字体代码,Java怎么调字体

java用什么方法设置label的字体

Java设置label字体代码如下:

我们注重客户提出的每个要求,我们充分考虑每一个细节,我们积极的做好成都网站建设、网站建设服务,我们努力开拓更好的视野,通过不懈的努力,创新互联赢得了业内的良好声誉,这一切,也不断的激励着我们更好的服务客户。 主要业务:网站建设,网站制作,网站设计,微信小程序,网站开发,技术开发实力,DIV+CSS,PHP及ASP,ASP.Net,SQL数据库的技术开发工程师。

ublic class SetColor extends JFrame{

JLabel jlabel = new JLabel("颜色,大小");

public SetColor(){

this.setLayout(null);

jlabel.setBounds(0, 0, 200, 40);

jlabel.setFont(new Font("",1,30));//设置字体大小

jlabel.setForeground(Color.BLUE);//设置字体颜色

this.add(jlabel);

this.setSize(200,200);

this.setVisible(true);

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

SetColor sc = new SetColor();

}}

怎么在java里面加改变字体的代码

setTextColor(0xFF0000FF);

//0xFF0000FF是int类型的数据,分组一下0x|FF|0000FF,0x是代表颜色整 数的标记,ff是表示透明度,0000FF表示颜色,注意:这里0xFF0000FF必须是8个的颜色表示,不接受0000FF这种6个的颜色表示。

setTextColor(Color.rgb(255, 255, 255));

setTextColor(Color.parseColor("#FFFFFF"));

//还有就是使用资源文件进行设置

setTextColor(this.getResources().getColor(R.color.blue));

//通过获得资源文件进行设置。根据不同的情况R.color.blue也可以是R.string.blue或者

//另外还可以使用系统自带的颜色类

setTextColor(android.graphics.Color.BLUE);

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中设置字体

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做网页的代码中改变字体的代码怎么写,新手求助

用样式定义,如:对p标签下的字体:p {font-family: "微软雅黑,新宋体,宋体";},而且可以定义多个字体,如果第一个字体支持就用第一个,第一个没有用第二个,依次类推。


本文题目:java怎么设置字体代码,Java怎么调字体
转载源于:http://www.wjwzjz.com/article/hsspde.html
在线咨询
服务热线
服务热线:028-86922220
TOP