当前位置: 代码迷 >> J2SE >> j2se 上拉框变化字体
  详细解决方案

j2se 上拉框变化字体

热度:9601   发布时间:2013-02-25 00:00:00.0
j2se 下拉框变化字体
package com.channelsoft.eps.test.epg;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class BtnFont extends JApplet implements ItemListener {
Container cp = getContentPane();
JLabel lb = new JLabel("班级:");
String str[] = { "101班", "102班", "103班", "104班", "105班" };
JButton bt = new JButton("请选择");
JComboBox cb = new JComboBox(str);

public void init() {
cp.setLayout(new FlowLayout());
cp.add(lb);
cp.add(bt);
cp.add(cb);
cb.addItemListener(this);
}

public void itemStateChanged(ItemEvent e) {
String str;
str = (String) e.getItem();
Font font = new Font("宋体", Font.PLAIN, 30);
bt.setText(str);
bt.setFont(font);
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BtnFont bt = new BtnFont();
bt.init();
}

}

结果: