if (loginButton == null) {
img = new ImageIcon (getClass (). getResource ("/ image/18.png"));
loginButton = new JButton (" login ", img);
loginButton.setBounds (new Rectangle (109, 114, 68, 25));
loginButton.setMargin (new Insets (2,2,2,2));
/ / add a listener
loginButton.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent arg0) {
/ / TODO Auto-generated method stub
JOptionPane.showMessageDialog (null, " Login successful ." ) ;
}
});
}
return loginButton;
}
only show pictures , you can not display text
------ Solution ---------------------------- ----------------
delete the following two lines can be displayed . Margins should be the size of the problem
loginButton.setBounds (new Rectangle (109, 114, 68, 25));
loginButton.setMargin (new Insets (2,2,2,2));
------ For reference only ---------------- -----------------------
can show ah, just pictures and text arranged display
------ For reference only - -------------------------------------
arranged to give an example of how
------ For reference only --------------------------- ------------
I have the same problem
------ For reference only ------------------ ---------------------
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;
}
Although relatively long time , but still back down to see this is the picture in the above text below
没有评论:
发表评论