java初学者,在按钮里加图片,可是图片不能覆盖按钮,有空白区怎么处理呢?
packagecom.jianting;importjava.awt.*;importjavax.swing.*;importjava.awt.Event;publicc...
package com.jianting;
import java.awt.*;
import javax.swing.*;
import java.awt.Event;
public class act1 extends JFrame{
/**
* @param args
*/
//声明所需对象
JFrame jf;
JButton jb1,jb2;
JPanel jp,jp1;
public static void main(String[] args) {
// TODO Auto-generated method stub
act1 testx=new act1();
}
//ActionListener类的构造函数,初始化所需的对象
public act1()
{
jf=new JFrame();
jp=new JPanel();
jp1=new JPanel();
jb1=new JButton(new ImageIcon("image\\denglu.gif"));
jb2=new JButton(new javax.swing.ImageIcon("image/xiangdao.gif"));
//jb1.setBorder(null);
//jb2.setBorder(null);
this.add(jp);
jp.setLayout(new GridLayout(3,1));
jp.add(jp1);
jp1.add(jb1);//按钮看得怪怪的
jp1.add(jb2);
this.setSize(400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
} 展开
import java.awt.*;
import javax.swing.*;
import java.awt.Event;
public class act1 extends JFrame{
/**
* @param args
*/
//声明所需对象
JFrame jf;
JButton jb1,jb2;
JPanel jp,jp1;
public static void main(String[] args) {
// TODO Auto-generated method stub
act1 testx=new act1();
}
//ActionListener类的构造函数,初始化所需的对象
public act1()
{
jf=new JFrame();
jp=new JPanel();
jp1=new JPanel();
jb1=new JButton(new ImageIcon("image\\denglu.gif"));
jb2=new JButton(new javax.swing.ImageIcon("image/xiangdao.gif"));
//jb1.setBorder(null);
//jb2.setBorder(null);
this.add(jp);
jp.setLayout(new GridLayout(3,1));
jp.add(jp1);
jp1.add(jb1);//按钮看得怪怪的
jp1.add(jb2);
this.setSize(400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询