资源描述:
《java指定字体的标题边框》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、指定字体的标题边框关键技术:创建复杂的标题边框publicTitleBorder(Borderborder,Stringtitle,inttitleJusetifcation,inttitlePostion,FonttitleFont,ColortitleColor)border嵌套的其他边框title标题titleJusetifcation水平对齐方式titlePostion垂直对齐方式titleFont字体titleColor字体颜色packagecom.java2010.swing02;importjava.awt.BorderLayout;importja
2、va.awt.Color;importjava.awt.Font;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.ButtonGroup;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JRadioButton;importjavax.swing.UIManager;importjavax.swing.
3、border.EmptyBorder;importjavax.swing.border.TitledBorder;publicclassTest01extendsJFrame{//定义我们需要的组件//面板JPanelmyjp;//按钮组ButtonGroupbg;//单选按钮JRadioButtonjrb1,jrb2,jrb3,jrb4;//按钮JButtonjb1;//标题边框TitledBordertitleborder;//字体Fontfont=null;//面板JPaneljp1;//构造方法publicTest01(){try{UIManager.se
4、tLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");}catch(Exceptione){//TODO:handleexception}//实例化组件myjp=newJPanel();myjp.setBorder(newEmptyBorder(5,5,5,5));myjp.setLayout(newBorderLayout(0,0));bg=newButtonGroup();jrb1=newJRadioButton("黑体");//默认勾选中jrb1.setSelected(true);
5、jrb1.setActionCommand(jrb1.getText());jrb1.setBounds(10,30,100,30);jrb2=newJRadioButton("宋体");jrb2.setBounds(10,60,100,30);jrb2.setActionCommand(jrb2.getText());jrb3=newJRadioButton("隶书");jrb3.setBounds(10,90,100,30);jrb3.setActionCommand(jrb3.getText());jrb4=newJRadioButton("楷体");jrb
6、4.setBounds(10,120,100,30);jrb4.setActionCommand(jrb4.getText());//将我们的单选按钮加入到组bg.add(jrb1);bg.add(jrb2);bg.add(jrb3);bg.add(jrb4);jb1=newJButton("设置字体");jb1.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){button(e);}});jb1.setBounds(50,160,120,3
7、0);jp1=newJPanel();font=newFont("黑体",Font.BOLD,18);titleborder=newTitledBorder(null,"设置字体",TitledBorder.LEFT,TitledBorder.TOP,font,newColor(255,0,0));jp1.setBorder(titleborder);//this.setLayout(null);jp1.setLayout(null);jp1.add(jrb1);jp1.add(jrb2);jp1.add(jrb3);jp1.add(jrb4);jp1.add(j
8、b1);m