资源描述:
《指定字体的标题边框java2012版》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、指定字体的标题边框关键技术:创建复杂的标题边框完整参数的标题边框构造方法可以指定标题文本、对齐方式、标题位置、还可以指定内嵌边框以及标题字体和颜色。publicTitleBorder(Borderborder,Stringtitle,inttitleJustification,inttitlePosition,FonttitleFont,ColortitleColor)border嵌套的其他边框title标题titleJustification标题的水平对齐方式titlePosition标题的垂直位置titleFont标题文字的字体对象titleFont标题文本的颜色对象pac
2、kagellt.swing09;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.EventQueue;importjava.awt.Font;importjavax.swing.ButtonGroup;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.border.EmptyBorder;importjavax.swing.border.TitledBorder;importjavax.swing.UIManage
3、r;importjava.awt.FlowLayout;importjavax.swing.JRadioButton;importjavax.swing.BoxLayout;importjava.awt.GridLayout;importjavax.swing.JButton;importjava.awt.event.ActionListener;importjava.awt.event.ActionEvent;publicclassShowTitleBorderextendsJFrame{privateJPanelcontentPane;privateButtonGroupb
4、g;privateFontfont=null;privateTitledBordertitledBorder;privateJPanelpanel;/***Launchtheapplication.*/publicstaticvoidmain(String[]args){try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");}catch(Throwablee){e.printStackTrace();}EventQueue.invokeLater(newRunnable(
5、){publicvoidrun(){try{ShowTitleBorderframe=newShowTitleBorder();frame.setVisible(true);}catch(Exceptione){e.printStackTrace();}}});}/***Createtheframe.*/publicShowTitleBorder(){setTitle("指定字体的标题边框");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100,100,322,221);contentPane=newJPan
6、el();contentPane.setBorder(newEmptyBorder(5,5,5,5));contentPane.setLayout(newBorderLayout(0,0));setContentPane(contentPane);panel=newJPanel();//创建面板font=newFont("黑体",Font.BOLD,18);//初始化字体对象titledBorder=newTitledBorder(null,"自定义字体标题",TitledBorder.LEADING,TitledBorder.TOP,font,newColor(255,0,0
7、));//创建标题边框对象panel.setBorder(titledBorder);//设置面板的边框contentPane.add(panel);panel.setLayout(null);JRadioButtonradioButton=newJRadioButton("黑体");//创建黑体单选按钮radioButton.setActionCommand(radioButton.getText());radioButton.setSelected(true);//默认为选择状态radi