我的About Frame类有问题。我通过action listener
中的JMenuItem
来调用它。它出现但它没有显示它居中,框架没有按我的要求显示图标图像。我有图标在大型机中工作,所以图像大小不是问题。这是否与private JPanel contentPane;
?
JmenuItem中的代码:
aboutMItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jAboutMN_actionPerformed(e);
关于框架代码:
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.BoxLayout;
public class AboutFrame extends JFrame {
private JPanel contentPane;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
AboutFrame frame = new AboutFrame();
frame.setIconImage(new ImageIcon("resources/Image.png").getImage());
frame.setVisible(true);
//frame.setLocationRelativeTo(null);
frame.setLocationRelativeTo(null);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public AboutFrame() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
//AboutFrame.setLocationRelativeTo(null);
setTitle("About MyAPP");
setBounds(100, 100, 370, 250);
//contentPane.setLocationRelativeTo(null);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lbVerNum = new JLabel("MYAPP, Beta 1.2");
lbVerNum.setBounds(57, 11, 233, 19);
lbVerNum.setVerticalAlignment(SwingConstants.TOP);
lbVerNum.setFont(new Font("Tahoma", Font.BOLD, 15));
lbVerNum.setHorizontalAlignment(SwingConstants.CENTER);
contentPane.add(lbVerNum);
JLabel lbCopyright = new JLabel("Copyright 2015 ");
lbCopyright.setBounds(86, 41, 170, 16);
lbCopyright.setIcon(null);
lbCopyright.setFont(new Font("Tahoma", Font.PLAIN, 13));
lbCopyright.setVerticalAlignment(SwingConstants.TOP);
lbCopyright.setHorizontalAlignment(SwingConstants.CENTER);
contentPane.add(lbCopyright);
}
}