84669 人学习
152542 人学习
20005 人学习
5487 人学习
7821 人学习
359900 人学习
3350 人学习
180660 人学习
48569 人学习
18603 人学习
40936 人学习
1549 人学习
1183 人学习
32909 人学习
闭关修行中......
继承JButton,重写其中的绘制方法。方法名我不记得了,去翻一下JDK吧。
别用swing了。。
自己回答了,这是我的代码,希望给遇到相同问题的人以帮助。
package youcanyoubb; import javax.swing.*; import java.awt.*; /** * Created by mcxinyu on 2015/12/8. */ //主页功能按钮 class HomeFunctionBtn extends JButton { JTextArea textJTA; JPanel btnArea; JButton button; //参数:图片路径,按钮名称,说明文本,坐标x,坐标y。 public HomeFunctionBtn(String image,String btnName,String text,int x,int y){ //设置按钮里面图片与标签的位置垂直居中. button = new JButton(btnName,new ImageIcon(image)); button.setBackground(new Color(230,230,230)); button.setSize(198,153); button.setFocusPainted(false); button.setFont(new Font("微软雅黑",Font.BOLD,18)); button.setVerticalAlignment(SwingConstants.BOTTOM); button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setHorizontalAlignment(SwingConstants.CENTER); button.setHorizontalTextPosition(SwingConstants.CENTER); //设置说明文本的内容及显示. textJTA= new JTextArea(text); textJTA.setFont(new Font("微软雅黑",Font.PLAIN,13)); textJTA.setBounds(0,153,200,47); textJTA.setLineWrap(true); textJTA.setEditable(false); textJTA.setBackground(new Color(230,230,230)); //添加组件 btnArea = new JPanel(null);//new FlowLayout()?? btnArea.add(button); btnArea.add(textJTA); this.setBorder(null); this.setLocation(x,y); this.add(btnArea); this.setSize(200,200); } }
继承JButton,重写其中的绘制方法。方法名我不记得了,去翻一下JDK吧。
别用swing了。。
自己回答了,这是我的代码,希望给遇到相同问题的人以帮助。