导航:首页 > 编程语言 > java字体大小设置

java字体大小设置

发布时间:2022-06-23 17:17:04

java中控制字体大小的设置

改成这样就可以了

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class controlString extends Applet implements ActionListener {

Button btn1, btn2;

int i = 20;

TextArea tx;

public void init() {
btn1 = new Button("big");
btn2 = new Button("small");
tx = new TextArea(50, 50);
add(btn1);
add(btn2);
add(tx);
tx.setFont(new Font("SansSerif", Font.BOLD, i));
btn1.addActionListener(this);
btn2.addActionListener(this);

}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn1 && i < 60) {
i = i + 4;
tx.setFont(new Font("SansSerif", Font.BOLD, i));

tx.setText("i is changed to" + i);

} else if (e.getSource() == btn2 && i > 4) {
i = i - 4;
tx.setFont(new Font("SansSerif", Font.BOLD, i));
tx.setText("i is changed to" + i);
}

}
}

------------------
Font font1=new Font("SansSerif",Font.BOLD,i);
在这里 你创建了一个对象font1,然后其属性都在这里定义了;之后你增加了变量i,但是这并不影响对象中的属性,对象的属性还是和之前定义时一样;所以不会改变。。。

❷ java的编程环境里怎么去设置中文的字体大小


MyEclipse
的工具栏中选择
Window

Preferences
选项:
在弹出框中选择第一个
General
下的->
Appearance
下的->
Colors
and
Fonts
->
在左边选择
Java
下的->
Java
Editor
Text
Font
,选中后右边有一个
Change
,点击它会弹出一个字体对话框
里面可设置编程时,代码的字体、字形、大小等,选择后确定即可!

❸ 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如何设置文字的格式,例如大小,颜色,字体··等等!

reset.setFont(new Font("",1,18));

你这里的""不能这样写,里边是字体名称,要么宋体或其它字体的名称或者写null,这些字体必须是你电脑上有的

❺ 如何把java工作区的字体调大

看你的是什么编译器,
要是jcreator的话,在菜单栏中点击configue,选择opinion进入java/font即可更改字体大小也就是中文版的配置/选象/java/字体
要是Eclipse的话,在菜单栏中点击串口,选择首选项,点常规,点外观,点颜色和字体,点Java,点Java编译器文本字体
要实MyEclipse的话,Window --> Preferences --> General --> Appearance --> Colors and Fonts --> Basic --> Text Font --> Change
要是你的是别的编译器,把名字发上来,我帮你解答

❻ Java中怎么设置JLabel的字体样式,大小,颜色

1、打开Myeclipse的相关界面,在Window那里点击Preferences。

❼ 怎么调整Java-Eclipse编辑框和控制台的字体大小

  1. 打开Eclipse,选择windows(系统)选项

  2. 然后点开--->preferences(首选项)

  3. 弹出首选项的窗口点击Appearance(外观)

  4. 再点击color and font (颜色和字体)

  5. 再点击Java---->Java editor text font(java 编辑器文本字体)

  6. 再点击Edit进行编辑

  7. 设置字体大小

  8. 控制台的字体设置点击Debug----->点击console font(控制台字体)步骤同上面一样点击Edit,进行字体大小设置

  9. 点击Apply>ok,不要粗心大意点错了!祝你好运!

❽ java里面怎么设置字体大小

JTextArea t = new JTextArea();
Font font = new Font("Default",Font.PLAIN,size);
t.setFont(font);
//其中size 就是字体的大小,可以设置。只要再用t.setFont()安装新的字体就行了。

❾ 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字体大小设置相关的资料

热点内容
设计道pdf 浏览:615
单片机kill4软件下载收费吗 浏览:846
苹果手机怎么连接RMS服务器 浏览:603
cisco路由器基本配置命令 浏览:186
android状态栏颜色透明 浏览:116
db2编译工具 浏览:181
腾讯云服务器创建环境 浏览:567
监管资金怎么解压 浏览:671
荣耀手机内存清理文件夹 浏览:175
外派程序员方案 浏览:554
安卓怎么把桌面的软件变成卡通 浏览:885
鲁班锁解压吗 浏览:395
打包发送文件如何加密 浏览:213
centos解压缩zip 浏览:388
我的世界怎么用命令风块取消指令 浏览:1000
安卓软件请求超时怎么办 浏览:476
androidapp调用另一个app 浏览:621
数控铣床法兰克子程序编程 浏览:174
linux打包命令targz 浏览:997
抖音app是哪个 浏览:407