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;
}
只能显示图片,不能显示文字
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));
JButton jbt=getJButton("xxxx.png","aa");
private JButton getJButton(String img, String text) {
ImageIcon ico = new ImageIcon(img); // 图片
JButton button = new JButton(text, ico);
button.setIconTextGap(2);
button.setHorizontalTextPosition(JButton.CENTER);
button.setVerticalTextPosition(JButton.BOTTOM);
return button;
}虽然时间比较久了.不过看到还是回复下.这是图片在上面文字在下面的