JButton图片和文字同是显示,求各位帮忙看下
private JButton getLoginButton() {
if (loginButton == null) {
img= new ImageIcon(getClass().getResource("/image/18.png"));
loginButton = new JButton("登录",img);
loginButton.setBounds(new Rectangle(109, 114, 68, 25));
loginButton.setMargin(new Insets(2,2,2,2));
// 添加一个监听
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null, "登录成功。");
}
});
}
return loginButton;
}
只能显示图片,不能显示文字
------解决方案--------------------下面两行删了,就能显示。应该是边距大小的问题
loginButton.setBounds(new Rectangle(109, 114, 68, 25));
loginButton.setMargin(new Insets(2,2,2,2));