指定字体的标题边框java2012版.doc_第1页
指定字体的标题边框java2012版.doc_第2页
指定字体的标题边框java2012版.doc_第3页
指定字体的标题边框java2012版.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

指定字体的标题边框关键技术:创建复杂的标题边框完整参数的标题边框构造方法可以指定标题文本、对齐方式、标题位置、还可以指定内嵌边框以及标题字体和颜色。public TitleBorder(Border border,String title,int titleJustification,int titlePosition,Font titleFont,Color titleColor)border嵌套的其他边框title标题titleJustification标题的水平对齐方式titlePosition标题的垂直位置titleFont标题文字的字体对象titleFont标题文本的颜色对象package llt.swing09;import java.awt.BorderLayout;import java.awt.Color;import java.awt.EventQueue;import java.awt.Font;import javax.swing.ButtonGroup;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.border.TitledBorder;import javax.swing.UIManager;import java.awt.FlowLayout;import javax.swing.JRadioButton;import javax.swing.BoxLayout;import java.awt.GridLayout;import javax.swing.JButton;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;public class ShowTitleBorder extends JFrame private JPanel contentPane; private ButtonGroup bg; private Font font = null; private TitledBorder titledBorder; private JPanel panel; /* * Launch the application. */ public static void main(String args) try UIManager .setLookAndFeel(com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel); catch (Throwable e) e.printStackTrace(); EventQueue.invokeLater(new Runnable() public void run() try ShowTitleBorder frame = new ShowTitleBorder(); frame.setVisible(true); catch (Exception e) e.printStackTrace(); ); /* * Create the frame. */ public ShowTitleBorder() setTitle(指定字体的标题边框); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 322, 221); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5); contentPane.setLayout(new BorderLayout(0, 0); setContentPane(contentPane); panel = new JPanel();/ 创建面板 font = new Font(黑体, Font.BOLD, 18);/ 初始化字体对象 titledBorder = new TitledBorder(null, 自定义字体标题, TitledBorder.LEADING, TitledBorder.TOP, font, new Color(255, 0, 0);/ 创建标题边框对象 panel.setBorder(titledBorder);/ 设置面板的边框 contentPane.add(panel); panel.setLayout(null); JRadioButton radioButton = new JRadioButton(黑体);/ 创建黑体单选按钮 radioButton.setActionCommand(radioButton.getText(); radioButton.setSelected(true);/ 默认为选择状态 radioButton.setBounds(14, 31, 104, 32); panel.add(radioButton); JRadioButton radioButton_1 = new JRadioButton(宋体);/ 创建宋体单选按钮 radioButton_1.setActionCommand(radioButton_1.getText(); radioButton_1.setBounds(14, 63, 104, 32); panel.add(radioButton_1); JRadioButton radioButton_2 = new JRadioButton(隶书);/ 创建隶书单选按钮 radioButton_2.setActionCommand(radioButton_2.getText(); radioButton_2.setBounds(14, 95, 104, 32); panel.add(radioButton_2); JRadioButton radioButton_3 = new JRadioButton(仿宋);/ 创建仿宋单选按钮 radioButton_3.setActionCommand(radioButton_3.getText(); radioButton_3.setBounds(14, 127, 104, 32); panel.add(radioButton_3); bg = new ButtonGroup();/ 创建按钮组 bg.add(radioButton);/ 把4个单选按钮添加到按钮组中 bg.add(radioButton_1); bg.add(radioButton_2); bg.add(radioButton_3); JButton button = new JButton(设置);/ 创建设置按钮 button.addActionListener(new ActionListener() / 为设置按钮添加事件监听器 public void actionPerformed(ActionEvent e) do_button_actionPerformed(e); ); button.setBounds(161, 128, 90, 30); panel.add(button); protected void do_button_actionPerformed(ActionEvent e) / 获取被选择的单选按钮的文本 String command = bg.getSelection().getActionCom

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论