全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
指定字体的标题边框关键技术:创建复杂的标题边框完整参数的标题边框构造方法可以指定标题文本、对齐方式、标题位置、还可以指定内嵌边框以及标题字体和颜色。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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 旅游景区服务标准化提升方案
- 铁路交通防护用品使用说明
- 2025年北京交通职业技术学院教师招聘考试真题及答案
- (2025年)安全法律法规真题及答案解析
- 2026辽宁省债务管理办公室面向机关事业单位选调5人备考题库附参考答案详解【突破训练】
- 2026新疆第四师总医院春季招聘88人备考题库及答案详解(典优)
- 养老院医嘱查对制度
- 2026广西钦州市钦北区长田街道社区卫生服务中心招聘1人备考题库带答案详解(满分必刷)
- 2026云南昆明巫家坝建设发展有限责任公司校园招聘15人备考题库附答案详解(研优卷)
- 2026广东广州花都城投住宅建设有限公司第二次招聘项目用工人员4人备考题库附参考答案详解【典型题】
- 2026年OpenClaw安全部署与实践指南
- 雨课堂学堂在线学堂云《机器学习数学基础(国防科技)》单元测试考核答案
- 第一单元第3课《多元表达》课件人教版初中美术八年级下册
- 2025-2026学年苏科版(新教材)小学信息科技四年级下册教学计划及进度表
- 2026年广东省深圳市高三一模英语试题(含答案)
- 第10课 古代的村落、集镇和城市(教学设计)-2025-2026学年统编版高二历史选择性必修2 经济与社会生活
- 2025年吉安职业技术学院单招综合素质考试试题及答案解析
- 2025年安徽财贸职业学院单招职业适应性测试试题及答案解析
- 2026年南京城市职业学院单招综合素质考试题库含答案解析
- 2025年安徽财贸职业学院单招职业技能考试试题及答案解析
- 2026年江西应用技术职业学院高职单招职业适应性测试模拟试题及答案详细解析
评论
0/150
提交评论