我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

java字体界面代码 java字体格式设置

Java中如何更换窗口标题栏字体(如何通过软件代码修改)

复制以下代码,修改相应地方即可:

成都创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、成都网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的维西网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

private static void loadIndyFont()

{

UIManager.put("CheckBox.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("Tree.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("Viewport.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("ProgressBar.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("RadioButtonMenuItem.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("FormattedTextField.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("ToolBar.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("ColorChooser.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("ToggleButton.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("Panel.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("TextArea.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("Menu.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("RadioButtonMenuItem.acceleratorFont", new java.awt.Font("宋体", 0, 12));

UIManager.put("Spinner.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("Menu.acceleratorFont", new java.awt.Font("宋体", 0, 12));

UIManager.put("CheckBoxMenuItem.acceleratorFont", new java.awt.Font("宋体", 0, 12));

UIManager.put("TableHeader.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("TextField.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("OptionPane.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("MenuBar.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("Button.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("Label.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("PasswordField.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("InternalFrame.titleFont", new java.awt.Font("宋体", 0, 12));

UIManager.put("OptionPane.buttonFont", new java.awt.Font("宋体", 0, 12));

UIManager.put("ScrollPane.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("MenuItem.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("ToolTip.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("List.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("OptionPane.messageFont", new java.awt.Font("宋体", 0, 12));

UIManager.put("EditorPane.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("Table.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("TabbedPane.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("RadioButton.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("CheckBoxMenuItem.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("TextPane.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("PopupMenu.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("TitledBorder.font", new java.awt.Font("宋体", 0, 12));

UIManager.put("ComboBox.font", new java.awt.Font("宋体", 0, 12));

}

java运行的计算器的界面字体显示太小,要添加什么代码可以放大字体,并且拉大边框时字体也随之放大

如果是swing的话

JLabel jl = new JLabel("标签");

jl.setBounds(10, 10, 10, 10);这是控制标签位置;

控制文本的位置,你可以通过在“”里边加空格控制

jl.setFont(new Font("宋体", Font.BOLD, 20));

这是控制文本字体,那个20就是大小选择,可以改变的

一个java初级的界面问题(已有代码,帮忙添加几行就可以)——字体对话框

我在你的基础上稍微添加了一些代码,现在可以改变字体大小了:

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

class FontDialog extends JDialog implements ItemListener, ActionListener {

JComboBox list;

JComboBox listSize; //显示可以选择的字体大小

JTextArea text;

Font font;

JButton yes, cancel;

JComponent com;

FontDialog(JComponent com) {

this.com = com;

setModal(true);

yes = new JButton("Yes");

cancel = new JButton("cancel");

yes.addActionListener(this);

cancel.addActionListener(this);

text = new JTextArea(2, 25);

list = new JComboBox();

listSize = new JComboBox();

GraphicsEnvironment ge = GraphicsEnvironment

.getLocalGraphicsEnvironment();

String fontName[] = ge.getAvailableFontFamilyNames();

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

list.addItem(fontName[i]);

}

//定义字体大小数组,字体大小可以自行定义

int[] fontSize = new int[20];

for (int i = 0; i fontSize.length; i++){

fontSize[i] = i+5;

listSize.addItem(fontSize[i]);

}

list.addItemListener(this);

listSize.addItemListener(this); //为设置字体大小的添加监听器

Container con = getContentPane();

con.setLayout(new FlowLayout());

Box boxH1 = Box.createHorizontalBox(), boxH2 = Box

.createHorizontalBox(), boxH3 = Box.createHorizontalBox();

Box boxBase = Box.createVerticalBox();

boxH1.add(list);

boxH1.add(listSize); //添加字体大小设置到面板中

boxH2.add(text);

boxH3.add(yes);

boxH3.add(cancel);

boxBase.add(boxH1);

boxBase.add(boxH2);

boxBase.add(boxH3);

con.add(boxBase);

setBounds(100, 100, 280, 170);

setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

validate();

}

public void itemStateChanged(ItemEvent e) {

String name = (String) list.getSelectedItem();

Integer size = (Integer) listSize.getSelectedItem(); //获得设置的字体大小

font = new Font(name, Font.PLAIN, size);

text.setFont(font);

text.setText("hello,奥运");

}

public void actionPerformed(ActionEvent e) {

if (e.getSource() == yes) {

com.setFont(font);

setVisible(false);

} else if (e.getSource() == cancel) {

setVisible(false);

}

}

}

class Dwindow extends JFrame implements ActionListener {

JTextArea text;

JToolBar bar;

Container con;

JButton buttonFont;

Dwindow() {

buttonFont = new JButton("设置字体");

text = new JTextArea("显示内容");

buttonFont.addActionListener(this);

bar = new JToolBar();

bar.add(buttonFont);

con = getContentPane();

con.add(bar, BorderLayout.NORTH);

con.add(new JScrollPane(text));

setBounds(60, 60, 300, 300);

setVisible(true);

validate();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent e) {

if (e.getSource() == buttonFont) {

FontDialog dialog = new FontDialog(text);

dialog.setVisible(true);

}

}

}

public class DialogExample {

public static void main(String args[]) {

new Dwindow();

}

}

JAVA的图形用户界面代码

package hao;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.GridLayout;

import java.io.File;

import javax.swing.BorderFactory;

import javax.swing.Box;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

import javax.swing.JTextPane;

import javax.swing.text.BadLocationException;

import javax.swing.text.SimpleAttributeSet;

import javax.swing.text.StyleConstants;

import javax.swing.text.StyledDocument;

public class ChatPanel extends JPanel {

private static final long serialVersionUID = 1L;

JButton send,record,saveRecord,image;

JTextArea inputArea;

JTextPane text;//注意用法****************************************************************************

JComboBox fontName = null, fontSize = null, fontStyle = null, fontColor = null,fontBackColor = null;

public StyledDocument doc = null; JScrollPane scrollPane;JPanel textChat;

JButton music;

public ChatPanel() {

setLayout(new BorderLayout());

text = new JTextPane();

text.setEditable(false);

doc = text.getStyledDocument();//跟踪文本和图片写到该区域的位置*************************************

scrollPane = new JScrollPane(text);

//注意下面对JComboBox的巧用***********************************************************************

String[] str_name = { "宋体", "黑体", "Dialog", "Gulim" };

String[] str_Size = { "12", "14", "18", "22", "30", "40" };

String[] str_Style = { "常规", "斜体", "粗体", "粗斜体" };

String[] str_Color = { "黑色", "红色", "蓝色", "黄色", "绿色" };

String[] str_BackColor = { "无色", "灰色", "淡红", "淡蓝", "淡黄", "淡绿" };

fontName = new JComboBox(str_name);

fontSize = new JComboBox(str_Size);

fontStyle = new JComboBox(str_Style);

fontColor = new JComboBox(str_Color);

fontBackColor = new JComboBox(str_BackColor);

fontName.setBackground(new Color(255,153,255));

fontSize.setBackground(new Color(255,153,255));

fontStyle.setBackground(new Color(255,153,255));

fontColor.setBackground(new Color(255,153,255));

fontBackColor.setBackground(new Color(255,153,255));

Box box = Box.createVerticalBox();//创建一个可以容纳多个Box组件的Box*******************************

Box box_1 = Box.createHorizontalBox();

Box box_2 = Box.createHorizontalBox();

Box box_4 = Box.createHorizontalBox();

box.add(box_1);

box.add(box_2);

box.add(box_4);

JLabel b1= new JLabel("字体~~"), b2 = new JLabel("样式~~"),b3 = new JLabel("字号~~"),b4 = new JLabel("颜色~~"),b5 = new JLabel("背景~~");

b1.setBackground(new Color(255,153,255));

b2.setBackground(new Color(255,153,255));

b3.setBackground(new Color(255,153,255));

b4.setBackground(new Color(255,153,255));

b5.setBackground(new Color(255,153,255));

box_1.add(b1);

box_1.add(fontName);

box_1.add(Box.createHorizontalStrut(8));

box_1.add(b2);

box_1.add(fontStyle);

box_1.add(Box.createHorizontalStrut(8));

box_1.add(b3);

box_1.add(fontSize);

box_2.add(Box.createHorizontalStrut(8));

box_2.add(b4);

box_2.add(fontColor);

box_2.add(Box.createHorizontalStrut(8));

box_4.add(b5);

box_4.add(fontBackColor);

textChat = new JPanel();

textChat.setLayout(new BorderLayout());

textChat.setBackground(new Color(255,153,255));

inputArea = new JTextArea(3, 20);

inputArea.setLineWrap(true); //设置文本区的换行策略。88888*********************************

send = new JButton("发送");

record=new JButton("显示记录");

saveRecord=new JButton("储存记录");

image=new JButton("表情");

send.setBackground(new Color(255,153,255));

record.setBackground(new Color(255,153,255));

saveRecord.setBackground(new Color(255,153,255));

image.setBackground(new Color(255,153,255));

Box box_3 = Box.createHorizontalBox();

box_3.add(send); box_3.add(Box.createHorizontalStrut(8));//设置按钮间距*************************888

box_3.add(record); box_3.add(Box.createHorizontalStrut(8)); //设置按钮间距*************************888

box_3.add(saveRecord); box_3.add(Box.createHorizontalStrut(8));//设置按钮间距*************************888

box_3.add(image);

box.setBorder(BorderFactory.createLineBorder(new Color(102,102,0),5));//设置Box的边框线********************

box_3.setBorder(BorderFactory.createLineBorder(new Color(102,102,0),5));

textChat.add(box,BorderLayout.NORTH);

textChat.add(inputArea,BorderLayout.CENTER);

textChat.add(box_3, BorderLayout.SOUTH);

inputArea.requestFocus(true);

inputArea.setBorder(BorderFactory.createLineBorder(new Color(102,102,0),5));//设置输入窗口边框线*******************

text.setBorder(BorderFactory.createLineBorder(new Color(102,102,0),8));//设置输入窗口边框线*******************

JPanel audioPanel = new JPanel();//最上面的边框************************************************************************

audioPanel.setBackground(new Color(255,153,255));

audioPanel.setLayout(new GridLayout(1,1));

music = new JButton("想听就听");

music.setPreferredSize(new Dimension(320,50));

music.setBorder(BorderFactory.createLineBorder(Color.BLACK,10));//设置输入窗口边框线*******************

audioPanel.add(music);

add(audioPanel, BorderLayout.NORTH);

add(scrollPane,BorderLayout.CENTER);

add(textChat, BorderLayout.SOUTH);

}

void insertIcon(ImageIcon image) {

text.setCaretPosition(doc.getLength());

text.insertIcon(image);

insert(new MessageStyle());//?????????????????????????????????????????????????????????????????????????????/

}

public void insert(MessageStyle attrib) {

try {

doc.insertString(doc.getLength(), attrib.getText() + "\n", attrib.getAttrSet());//写完后接着换行************

} catch (BadLocationException e) {

e.printStackTrace();

}

}

public MessageStyle getMessageStyle(String line) {

MessageStyle att = new MessageStyle();

att.setText(line);

att.setName((String) fontName.getSelectedItem());

att.setSize(Integer.parseInt((String) fontSize.getSelectedItem()));

String temp_style = (String) fontStyle.getSelectedItem();

if (temp_style.equals("常规")) {

att.setStyle(MessageStyle.GENERAL);

}

else if (temp_style.equals("粗体")) {

att.setStyle(MessageStyle.BOLD);

}

else if (temp_style.equals("斜体")) {

att.setStyle(MessageStyle.ITALIC);

}

else if (temp_style.equals("粗斜体")) {

att.setStyle(MessageStyle.BOLD_ITALIC);

}

String temp_color = (String) fontColor.getSelectedItem();

if (temp_color.equals("黑色")) {

att.setColor(new Color(0, 0, 0));

}

else if (temp_color.equals("红色")) {

att.setColor(new Color(255, 0, 0));

}

else if (temp_color.equals("蓝色")) {

att.setColor(new Color(0, 0, 255));

}

else if (temp_color.equals("黄色")) {

att.setColor(new Color(255, 255, 0));

}

else if (temp_color.equals("绿色")) {

att.setColor(new Color(0, 255, 0));

}

String temp_backColor = (String) fontBackColor.getSelectedItem();

if (!temp_backColor.equals("无色")) {

if (temp_backColor.equals("灰色")) {

att.setBackColor(new Color(200, 200, 200));

}

else if (temp_backColor.equals("淡红")) {

att.setBackColor(new Color(255, 200, 200));

}

else if (temp_backColor.equals("淡蓝")) {

att.setBackColor(new Color(200, 200, 255));

}

else if (temp_backColor.equals("淡黄")) {

att.setBackColor(new Color(255, 255, 200));

}

else if (temp_backColor.equals("淡绿")) {

att.setBackColor(new Color(200, 255, 200));

}

}

return att;

}

}


网站名称:java字体界面代码 java字体格式设置
标题链接:http://shouzuofang.com/article/dosjsjh.html

其他资讯