资源描述:
《java实现带标题边框的面板容器》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实现带标题边框的面板容器关键技术:简单的标题边框publicTitleBorder(Stringtitle)title边框应该显示的标题publicTitleBorder(Borderborder,Stringtitle,inttitleJustification,inttitlePosition)border:嵌套的其他边框title边框应显示的标题titleJustification标题的水平对齐方式titlePosition标题的垂直位置//边框普通边框Borderborder=BorderFactory.createEtch
2、edBorder(Color.BLACK,Color.BLUE);以上是创建边框createEtchedBorder创建凹凸边框Color.BLACK,Color.BLUE阴影颜色//边框标题Bordertitle=BorderFactory.createTitledBorder(border,"力天教育",TitledBorder.RIGHT,TitledBorder.TOP,newFont("黑体",Font.ITALIC,16),Color.RED);BorderFactory.createTitledBorde给边框加入标题
3、border指定好边框类型"力天教育"标题内容TitledBorder.RIGHT标题放到边框的右边TitledBorder.TOP字体在边框的上方newFont("黑体",Font.ITALIC,16)设置标题字体的Color.RED标题字体的颜色JPaneljp1=newJPanel();JPaneljp2=newJPanel();jp2.setBorder(border);jp1.setBorder(title);给面板设置边框packagellt.swing08;importjava.awt.BorderLayout;imp
4、ortjava.awt.EventQueue;importjava.awt.Font;importjavax.swing.ImageIcon;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.border.EmptyBorder;importjava.awt.GridLayout;importjavax.swing.border.TitledBorder;importjava.awt.Color;importjavax.swing.border.B
5、evelBorder;importjavax.swing.border.EtchedBorder;importjavax.swing.border.LineBorder;importjavax.swing.border.MatteBorder;importjavax.swing.UIManager;publicclassTitledBorderPanelextendsJFrame{privateJPanelcontentPane;privateTitledBordertitledBorder;/***Launchtheapplica
6、tion.*/publicstaticvoidmain(String[]args){try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");}catch(Throwablee){e.printStackTrace();}EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{TitledBorderPanelframe=newTitledBorderPanel();fra
7、me.setVisible(true);}catch(Exceptione){e.printStackTrace();}}});}/***Createtheframe.*/publicTitledBorderPanel(){setTitle("实现带标题边框的面板容器");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100,100,448,389);contentPane=newJPanel();contentPane.setBorder(newEmptyBord
8、er(5,5,5,5));setContentPane(contentPane);contentPane.setLayout(newGridLayout(0,3,0,0));JPanelpanel_1=newJPanel();//创建