// 1.设置按钮(也可对所有控件使用)的绝对位置及大小
JPanel p1=new JPanel();
JButton b1=new JButton("登录");
p1.setLayout(null);// 设置空布局,即绝对布局
l1.setBounds(50, 230, 50, 34);//绝对位置
p1.add(b1);
//2.对JButton大小的设置
button.setPreferredSize(new Dimension(50,35));
//3.对JButton透明的设置
//按钮设置为透明,这样就不会挡着后面的背景
button.setContentAreaFilled(false);
//4.对JButton去掉按钮的边框的设置
button.setBorderPainted(false);
//5.对JButton添加图标的设置
// 实例化一个图标对象
ImageIcon image = new ImageIcon(icons[i]);
// 实例化按钮对象,并且设置按钮上显示图片
JButton button = new JButton(image);
//或者
button.setIcon(new ImageIcon(getClass().getResource("bg.jpg")));
//6.让按钮随按钮上的图案变化
butten.setMargin(new Insets(0,0,0,0));
//7.设置凹凸及背景色
//设置凸起来的按钮,很多其他的swing也可用此方法
butten.setBorder(BorderFactory.createRaisedBevelBorder());
//设置凹起来的按钮,很多其他的swing也可用此方法
button.setBorder(BorderFactory.createLoweredBevelBorder());
//设置按钮的前景色和背景色
button .setFont(new java.awt.Font("华文行楷", 1, 15));
button.setBackground(Color.green);
//8.设置前景色/字体颜色
button.setForeground(Color.red);
//9.设置按钮字体大小
//设置按钮字体大小为加粗,16号字
Font Fonts = new Font("行书", Font.BOLD, 16);
b1.setFont(Fonts);