重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
可以用这个函数setFont(Font f);
成都创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、成都网站设计、德惠网络推广、小程序制作、德惠网络营销、德惠企业策划、德惠品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联公司为所有大学生创业者提供德惠建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com
里面有很多的字体,可以参加这个函数的调用
我有个数字时钟,实现了字体的改变...
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class ClockDemo extends JFrame implements Runnable
{
Thread clock;
public ClockDemo()
{
super("数字时钟");
setFont(new Font("Times New Roman", Font.BOLD, 60));
this.setFont(Font f);
start();
setSize(280,100);
}
public void start() {
if (clock == null) {
clock = new Thread(this);
clock.start();
}
}
public void run() {
while (clock != null)
{
repaint();
try
{
Thread.sleep(1000);
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
}
}
public void stop()
{
clock=null;
}
public void paint(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
Calendar now=new GregorianCalendar();
String timeInfo="";
int hour=now.get(Calendar.HOUR_OF_DAY);
int minute=now.get(Calendar.MINUTE);
int second=now.get(Calendar.SECOND);
if(hour=9)
timeInfo+="0"+hour+":";
else
timeInfo+=hour+":";
if(minute=9)
timeInfo+="0"+minute+":";
else
timeInfo+=minute+":";
if(second=9)
timeInfo+="0"+second;
else
timeInfo+=second;
g.setColor(Color.white);
Dimension dim=getSize();
g.fillRect(0,0,dim.width,dim.height);
g.setColor(Color.orange);
g.drawString(timeInfo,20,80);
}
public static void main(String[] args)
{
ClockDemo my=new ClockDemo();
my.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
my.setVisible(true);
}
}
字体效果如下....
你可以使用Spire.Doc for Java在Java应用程序中为word文档添加艺术字并设置样式和效果。
import com.spire.doc.*;import com.spire.doc.documents.*;import com.spire.doc.fields.ShapeObject;import java.awt.*;public class WordArt {
public static void main(String[] args) throws Exception {
//创建word文档
Document doc = new Document();
//添加一个section
Section section = doc.addSection();
//添加一个段落到section
Paragraph paragraph = section.addParagraph();
//添加一个shape,并设置其大小和样式
ShapeObject shape = paragraph.appendShape(250, 70, ShapeType.Text_Wave_4);
//设置shape的位置
shape.setVerticalPosition(80);
shape.setHorizontalPosition(100);
//写入艺术字文本
shape.getWordArt().setText("艺术字效果");
//设置文字填充颜色
shape.setFillColor(Color.RED);
shape.setStrokeColor(Color.GRAY);
//保存文档
doc.saveToFile("output/wordart.docx", FileFormat.Docx_2013);
}}
通常情况下,Word2013文档中包含有多种格式,包括字体、字号、字符间距等格式设置。用户可以在“显示格式”任务窗格中查看当前Word文档或选定文本的格式。默认情况下,Word2013的功能区中未显示“显示格式”按钮。用户可以将其放置到“快速访问工具栏...
html
head
style type="text/css"
h1 {font-size:60px;}//改变字体的大小
h2 {font-size:40px;}
p {font-size:14px;}
/style
/head
body
h1This is heading 1/h1
h2This is heading 2/h2
pThis is a paragraph./p
pThis is a paragraph./p
p.../p
/body
/html
java读取word文件,并输出红色字体,主要采用的是开源的读取框架,例如Jword,示例如下:
package com.xxx.common;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.rtf.RtfWriter2;
public class WordUtil {
private static Document document;
private static BaseFont baseFont;
//创建word,并设置纸张文档
private static void openWordFile(String fileName) throws DocumentException,
IOException {
document = new Document(PageSize.A4);
RtfWriter2.getInstance(document, new FileOutputStream(fileName));
document.open();
baseFont = BaseFont.createFont();
}
//设置标题
private static boolean setTitle(String title) throws DocumentException {
Font font = new Font(baseFont, 12, Font.BOLD);
Paragraph pTitle = new Paragraph(title + "\n");
pTitle.setFont(font);
pTitle.setAlignment(Element.ALIGN_CENTER);
return document.add(pTitle);
}
//设置文档内容,以及字体颜色
private static boolean setContent(String content) throws DocumentException {
Font font = new Font(baseFont, 10, Font.NORMAL);
Paragraph pContent = new Paragraph(content);
pContent.setFont(font);
pContent.setAlignment(Element.ALIGN_LEFT);
pContent.setSpacingAfter(5);
pContent.setFirstLineIndent(20);
return document.add(pContent);
}
//对外使用的接口
public static boolean CreateWordFile(String url, String title,
ListString contents) {
boolean returnValue = false;
try {
openWordFile(url);
returnValue = setTitle(title);
for (int i = 0; i contents.size(); i++) {
returnValue = returnValue setContent(contents.get(i));
}
document.close();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return returnValue;
}
//对外使用的接口
public static boolean CreateWordFile(String url, String title,
String content) {
boolean returnValue = false;
try {
openWordFile(url);
returnValue = setTitle(title);
returnValue = returnValue setContent(content);
document.close();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return returnValue;
}
public static void main(String[] args ) {
WordUtil wordUtil = new WordUtil();
ListString strList = new ArrayListString();
//传入内容为字符串
wordUtil.CreateWordFile("e:\\word.doc", "标题居中", "我爱Java");
//传入内容为字符串List
//wordUtil.CreateWordFile("e:\\word.doc", "标题居中", strList);
}
}
使用style对象的setFont方法,如下代码
HSSFCellStyle style = wb.createCellStyle();
HSSFFont font = wb.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
style.setFont(font);//选择需要用到的字体格式