-
2021-04-23 06:18:22
package com.yidu.demo;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Enumeration;
import javax.swing.ImageIcon;
import javax.swing.JColorChooser;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextPane;
import javax.swing.KeyStroke;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
import javax.swing.text.StyleConstants.ColorConstants;
import javax.swing.text.StyleConstants.FontConstants;
import sun.font.FontFamily;
public class MainFrame extends JFrame {
JTextPane editorPane=new JTextPane();
Socket socket;
public MainFrame(){
JMenuBar bar=new JMenuBar();
this.setJMenuBar(bar);
JMenu menuFile=new JMenu("编辑");
bar.add(menuFile);
JMenuItem itemSend=new JMenuItem("发送");
menuFile.add(itemSend);
try {
socket=new Socket("127.0.0.1",1000);
} catch (UnknownHostException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
itemSend.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
try {
OutputStream os= socket.getOutputStream();
ObjectOutputStream objectOutputStream=new ObjectOutputStream(os);
objectOutputStream.writeObject(editorPane);
objectOutputStream.flush();
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
www.2cto.com
});
JMenuItem itemGet=new JMenuItem("得到内容");
menuFile.add(itemGet);
itemGet.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
Document document= editorPane.getDocument();
editorPane.insertIcon(new ImageIcon("MessageReading.gif"));
}
});
JMenuItem itemColor=new JMenuItem("颜色");
itemColor.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
JColorChooser colorChooser=new JColorChooser();
Color color= colorChooser.showDialog(null, "字体颜色", Color.BLACK);
Document document= editorPane.getDocument();
try {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,StyleConstants.Foreground, color);
Font font=new Font("隶书",Font.BOLD,30);
aset=sc.addAttribute(aset, StyleConstants.Family, font.getFamily());
aset=sc.addAttribute(aset, StyleConstants.FontSize, 30);
int start= editorPane.getSelectionStart();
int end=editorPane.getSelectionEnd();
String str= document.getText(start,end-start);
document.remove(start, end-start);
document.insertString(start, str, aset);
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
menuFile.add(itemColor);
itemColor.setMnemonic('C');
//设置快捷键
itemColor.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.ALT_MASK));
this.add(editorPane);
editorPane.setText("测试");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* @param args
*/
public static void main(String[] args) {
MainFrame mainFrame=new MainFrame();
mainFrame.setSize(400, 300);
mainFrame.setVisible(true);
}
}
摘自 zyqyz520的专栏
http://www.dengb.com/Javabc/544136.htmlwww.dengb.comtruehttp://www.dengb.com/Javabc/544136.htmlTechArticlepackage com.yidu.demo; import java.awt.Color; import java.awt.Font; import java.awt.Image; import java.awt.MenuItem; import java.awt.event.ActionEvent; import java.awt.event.Action...
更多相关内容 -
FontVerter:Java字体转换器库
2021-05-13 14:09:26Java库,用于转换和处理各种字体格式,规范无效字体并从PDF中提取字体。 目前支持 裸CFF-> OpenType / OTF和WOFF 1.0和2.0 OpenType / OTF / TTF-> WOFF 1.0和2.0 WOFF 1.0-> OpenType和WOFF 2.0 EOT(仅未压缩... -
linux或java环境缺少缺少字体 字体.zip
2021-07-31 13:57:231 给JAVA_HOME增加字体 2 给redhat系统增加字体 -
java字体有哪些
2021-02-27 11:58:10java字体有:1、Serif是有衬线;2、【Sans-serif】是无衬线;3、Monospaced是等宽;4、Dialog是对话框;5、DialogInput是对话框输入。Java 使用逻辑字体映射到运行平台上对应的物理字体这种方法来处理字体的显示。...java字体有:1、Serif是有衬线;2、【Sans-serif】是无衬线;3、Monospaced是等宽;4、Dialog是对话框;5、DialogInput是对话框输入。
Java 使用逻辑字体映射到运行平台上对应的物理字体这种方法来处理字体的显示。
Java 定义了五种逻辑字体:Serif(有衬线) 、Sans-serif(无衬线) 、Monospaced(等宽) 、Dialog(对话框)、DialogInput(对话框输入)。每种字体对应有四种字体风格:plain(扁平)、bold(粗体)、 italic(斜体)、bolditalic(粗斜)。
我们可以选择逻辑字体、大小和颜色,但不能选择具体的物理字体,对应的物理字体需要在 JRE 的字体配置文件里设置。
影响图形字体的主要因素有:当前语言代码页、数据库字符集、安装的字体和字体配置文件
1、语言代码页
语言代码页为当前所用的语言环境,在 Linux 和 UNIX 环境下用 .profile 文件配置,在 Windows 下要查看活动代码页设置,请键入:chcp,出现类似于下面内容的消息:Active code page: 437,要将活动代码页更改为 850(多语言),请键入:chcp 850,如果指定的代码页无效,则会显示以下错误消息:Invalid code page。
2、数据库字符集
用具体命令可以查看当前数据库实例所用的字符集,还可以设置字符集。(注意:在 Windows 命令行下设置后要退出重新运行另一个命令行会话才生效)。
3、已安装的字体
在 Windows 平台下可以在“控制面板-> 字体”里查看安装的字体。另外,JRE 也自带了几种字体在 %JAVAHOME%/lib/fonts。
注:%JAVAHOME% 指 Java 安装的根目录。
4、字体配置文件
Java可以JRE中对字体进行配置,在JRE的不同版本下字体配置文件是不太一样的,可以用 %JAVAHOME%/bin/java -version 命令查看安装的具体 JRE 版本。可以在sun官方的网站上具体查阅配置方法:请先来到Java SE中,选Technologies标签,可以在总框架图中找到查找“Intl Support”窗口,进入后寻找“The Font Configuration Files”。相关免费学习推荐:java基础教程
-
java字体包资源官网下载TOP10
2017-11-16 14:44:01java字体包,程序员最喜欢的字体都在文档里,排名前10,文档中有每个字体的官网链接,分享给大家! -
java 字体对话框
2019-03-20 03:22:03NULL 博文链接:https://mengdejun.iteye.com/blog/790826 -
详解Eclipse 字体、字号的设置、最佳字体推荐
2021-02-26 21:29:35Eclipse 最佳字体 推荐:步骤:Eclipse->Windows[窗口]->Preferences[首选项]->General[常规]->Appearance[外观]->Colors and Fonts[颜色和字体]->Java->JavaEditor Text Font[JAVA编辑器文本...Eclipse 最佳字体 推荐:
步骤:Eclipse->Windows[窗口]->Preferences[首选项]->General[常规]->Appearance[外观]->Colors and Fonts[颜色和字体]->Java->Java Editor Text Font[JAVA编辑器文本字体]
如下图所示: 改成 courier new 字体最好。英文和中文的大小 都很适合。
如果 这个 页面选项卡 中 没有 Courier New 字体选项,是因为 操作系统 将其隐藏了。 则在控制面板 中 找到 字体选项,将这个字体 显示 出来即可。则 其他 所有软件 都能 使用该字体了。如图:
ps:eclipse 中使用等宽字体 inconsolata
一直以来,就感觉使用 eclipse 时的那几种字体很难看,而且非等宽,空格宽度很小,排版很乱。
搜索并试用了一下,发现了字体inconsolata。 这是一个很适合编程的字体,效果如下:
非常漂亮。
然后在 eclipse 中依次点击 windows->preferences -> Genral -> Appearance -> Colors and Fonts -> 找到 java editor text font 点击 edit, 找到inconsolata 确定即可。
到此这篇关于详解Eclipse 字体、字号的设置、最佳字体推荐的文章就介绍到这了,更多相关Eclipse 字体字号的设置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
-
centos中文字体库 解决JAVA 绘图 Linux下中文乱码问题使用到的字体库
2021-02-26 07:15:36解决JAVA 绘图 Linux下中文乱码问题使用到的字体库 -
Linux 中文字体,Java中文乱码解决
2019-04-19 20:13:46Linux ,Java 创建文件乱码,中文乱码,下载字体后,可参考以下博文: http://www.cnblogs.com/hannuo/articles/9675296.html -
Java获得Windows字体信息.rar
2019-07-10 18:32:54Java获得Windows字体信息,通过Font 类的getFamily()、getFontName()、getName() 可以得到字体的族名、字体名和逻辑名。 -
Java获得系统字体信息
2021-03-16 06:19:45摘要:Java源码,系统相关,获取字体 Java获得系统字体信息,通过Java获取系统的字体信息。窗口上的表格列出了所有的作者机器上的字体及相关信息。本代码关于字体的信息都包含在Font 对象中,通过Font 类的getFamily()... -
java获取系统路径字体、得到某个目录下的所有文件名、获取当前路径
2020-09-04 12:50:46主要介绍了java获取系统路径字体、得到某个目录下的所有文件名、获取当前路径,需要的朋友可以参考下 -
Java平台字体显示效果演示示例
2021-03-16 06:03:45摘要:Java源码,图形操作,字体样式 Java平台字体演示示例,演示不同字体在不同样式和不同字体大小情况下的显示效果。所有的字体都是程序运行平台上的字体。具体的绘制过程中用到了Graphics2D 类中的drawString()方法... -
java字体设置
2021-03-06 04:00:11import java.awt.BorderLayout;import java.awt.Color;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JEditorPane;import javax.swing.J...import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.text.AttributeSet;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.StyledEditorKit;
public class NewJFrame extends javax.swing.JFrame implements ActionListener {
private JPanel jp1;
private JButton color;
private JTextPane jep;
private JScrollPane jsp;
private JButton font;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
NewJFrame inst = new NewJFrame();
inst.setVisible(true);
}
public NewJFrame() {
super();
initGUI();
}
private void initGUI() {
try {
BorderLayout thisLayout = new BorderLayout();
getContentPane().setLayout(thisLayout);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jp1 = new JPanel();
getContentPane().add(jp1, BorderLayout.NORTH);
{
font = new JButton();
font.addActionListener(this);
jp1.add(font);
font.setText("font");
}
{
color = new JButton();
jp1.add(color);
color.addActionListener(this);
color.setText("color");
}
}
{
jsp = new JScrollPane();
getContentPane().add(jsp, BorderLayout.CENTER);
{
jep = new JTextPane();
jsp.setViewportView(jep);
jep.setDocument(new DefaultStyledDocument());
}
}
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void setFontSize(JEditorPane editor, int size) {
if (editor != null) {
if ((size > 0) && (size < 512)) {
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setFontSize(attr, size);
setCharacterAttributes(editor, attr, false);
} else {
UIManager.getLookAndFeel().provideErrorFeedback(editor);
}
}
}
public static void setForeground(JEditorPane editor, Color fg) {
if (editor != null) {
if (fg != null) {
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setForeground(attr, fg);
setCharacterAttributes(editor, attr, false);
} else {
UIManager.getLookAndFeel().provideErrorFeedback(editor);
}
}
}
public static final void setCharacterAttributes(JEditorPane editor,
AttributeSet attr, boolean replace) {
int p0 = editor.getSelectionStart();
int p1 = editor.getSelectionEnd();
if (p0 != p1) {
StyledDocument doc = getStyledDocument(editor);
doc.setCharacterAttributes(p0, p1 - p0, attr, replace);
}
StyledEditorKit k = getStyledEditorKit(editor);
MutableAttributeSet inputAttributes = k.getInputAttributes();
if (replace) {
inputAttributes.removeAttributes(inputAttributes);
}
inputAttributes.addAttributes(attr);
}
protected static final StyledDocument getStyledDocument(JEditorPane e) {
Document d = e.getDocument();
if (d instanceof StyledDocument) {
return (StyledDocument) d;
}
throw new IllegalArgumentException("document must be StyledDocument");
}
protected static final StyledEditorKit getStyledEditorKit(JEditorPane e) {
EditorKit k = e.getEditorKit();
if (k instanceof StyledEditorKit) {
return (StyledEditorKit) k;
}
throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if (obj == font) {
JEditorPane editor = jep;
setFontSize(editor, 20);
}
if (obj == color) {
JEditorPane editor = jep;
setForeground(editor, Color.red);
}
}
}
其他操作如下:
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窗体字体样式
2016-02-01 17:46:00这是一个用Java做的小窗体,选择字体样式可以改变 -
Java 在Excel单元格中应用一种/多种字体样式(实例代码)
2020-08-25 05:06:48主要介绍了Java 在Excel单元格中应用一种/多种字体样式,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下 -
java获取系统安装字体
2015-12-14 15:25:00java获取系统安装字体,这是一个工具类,能实现从系统中获取本系统安装的所有字体并返回显示。 -
java生成pdf字体和模板
2017-07-24 22:31:46java生成pdf字体和模板 -
java 显示多种字体
2014-03-09 10:42:21实现多种字体展示,展示黑体,斜体,粗体以及各种字号 -
java生成PDF字体库包+PDF包亲测成功
2017-11-13 12:19:34java生成PDF字体库包+PDF包 完美匹配 itext-4.2.0.jar itext-asian-5.2.0.jar 亲测成功 -
java字体选择程序
2011-04-11 20:27:04用java做的一个字体选择程序,实现了其中的大部分功能,可以拿去直接用了。 -
Java读取Windows字体并演示字体样式效果.rar
2019-07-10 09:48:18Java读取Windows字体并演示字体样式效果,程序读取Windows系统所安装的字体,然后允许用户对字体样式进行自定义,最后使用Graphics2D 类中的drawString()绘制输出字体效果,如演示截图所示的运行结果。 -
java读取word文档内容以及字体大小和颜色
2018-11-05 16:32:57java读取不同版本文档的内容以及字体大小,实现对文档格式进行匹配! -
java实现仿windows 字体设置选项卡实例
2020-09-01 10:09:52本篇文章介绍了java仿windows 字体设置选项卡,可实现类似windows字体设置效果,需要的朋友可以参考下。 -
用Java语言设置字体的格式
2014-06-15 09:36:16用Java语言设置字体的格式,比如:宋体、黑体等。 -
java-jasper-reports-custom-font:在Java中将自定义字体与Jasper报告一起使用-我有一个项目,要求Jasper...
2021-05-03 06:14:40在Java中将自定义字体与Jasper报告一起使用-我有一个项目,要求Jasper报告以pdf格式开票。 除非在项目中添加自定义字体,否则Jasper报告与Java的集成并不重要。 由于社区对在Java中整合jasper报表的支持并没有多大... -
Java怎么设置字体
2021-02-12 11:40:59Java设置字体的方法:首先依次点击【General】→【Appearance】→【colors and Fonts】;然后在菜单栏中选择要修改的字体;接着点击【Edit】修改;最后点击【Apply】应用,点击【ok】即可。在我们使用编程工具时,会... -
Java设置字体颜色
2021-03-07 14:21:15import javax.swing.*;import javax.swing.text.AttributeSet;import javax.swing.text.SimpleAttributeSet;import javax.swing.text.StyleConstants;import javax.swing.text....import java.awt.*;/*** ... -
linux java 中文字体
2011-10-28 15:02:39linux java 中文字体 linux java 中文字体