java中如何调出字体对话框_java 字体对话框

本人不才!花了很长时间写了这个代码。不是很好,比起Windows自带的字体对话框差一点。

不过已经够用了。等将来有时间了,在进行完善。

如果有什么好的建议,可以提。本人再补。

预览效果如下图:

package styleDispose;

import java.awt.GraphicsEnvironment;

import javax.swing.JDialog;

import javax.swing.JFrame;

import javax.swing.ListModel;

import java.awt.Font;

import javax.swing.JPanel;

import java.awt.Rectangle;

import javax.swing.JScrollPane;

import javax.swing.BorderFactory;

import javax.swing.border.TitledBorder;

import java.awt.Color;

import javax.swing.JList;

import javax.swing.JLabel;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.JTextField;

import javax.swing.border.BevelBorder;

import javax.swing.border.SoftBevelBorder;

import javax.swing.JButton;

import javax.swing.SwingConstants;

public class FontChooserDialog extends JDialog {

/**

*

*/

private static final long serialVersionUID = 1L;

/**

* 界面设计需要

* */

private JPanel jPanel = null;

private JScrollPane jScrollPane = null;

private JPanel jPanel1 = null;

private JLabel jLabel = null;

private JLabel jLabel1 = null;

private JLabel jLabel2 = null;

private JTextField fontNameText = null;

private JTextField fontItalicText = null;

private JTextField fontSizeText = null;

private JList fontNameList = null;

private JList fontItalicList = null;

private JList fontSizeList = null;

private JPanel jPanel2 = null;

private JButton okButton = null;

private JButton regitButton = null;

private JButton cancleButton = null;

private JScrollPane jScrollPane1 = null;

private JScrollPane jScrollPane2 = null;

private JScrollPane jScrollPane3 = null;

private static JLabel fontStyle = null;

/**

* 字体默认变量

* */

private Font defaultFont = new Font("\u5b8b\u4f53", Font.PLAIN, 12);

/**

* 返回字体变量

* */

private static Font returnFont = null;

/**

* Boolean 变量,判断是否正常返回,是否用户选择了字体

* */

private static boolean judge = false;

/**

* 以防止事件重复调用或不必要的更改,定义两个boolean变量分别

* 为:fontNameList和fontSizeList判断

* 等于true则循环调用,false则不

* */

private boolean nameJuge = true;

private boolean sizeJuge = true;

public FontChooserDialog(){

this(null);

}

public FontChooserDialog(JFrame jframe){

this(jframe,true);

}

public FontChooserDialog(JFrame jframe,boolean boo){

this(jframe,boo,null);

}

public FontChooserDialog(JFrame jframe,boolean boo,Font font){

super(jframe,boo);

initialize();

initializeFont(font);

this.setLocationRelativeTo(jframe);

}

/**

* This method initializes this

*

*/

private void initialize() {

this.setContentPane(getJPanel());

this.setFont(new Font("\u5b8b\u4f53", Font.PLAIN, 12));

this.setBounds(new Rectangle(0, 0, 430, 335));

this.setTitle("字体选择对话框");

this.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e) {

judge = false;

closeWindow();

}

});

}

public static Font showDialog(JFrame jframe,

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值