我使用此代码将图片设置为 jframe 。但是,现在我的 Jtable 不显示了,为什么?
public class samplepage extends JFrame{
private AllUser userModel;
private JTable uTable;
JButton addUser;
JButton deleteUser;
JButton mainButton;
JTextField tf1;
JButton searchButton;
JLabel resultLbl;
public samplepage(){
userModel=new AllUser();
uTable=new JTable(userModel);
add(new JScrollPane(uTable), BorderLayout.CENTER);
add(buttonPanels() , BorderLayout.PAGE_START);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(800,600);
this.setLocation(300, 60);
this.setResizable(false);
}
public final JPanel buttonPanels(){
JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
setPic(this);
addUser=new JButton("Add New User");
deleteUser=new JButton("delete User");
mainButton= new JButton("Main Page");
tf1 = new JTextField(" ");
searchButton=new JButton("Search");
resultLbl=new JLabel();
buttonsPanel.add(addUser);
buttonsPanel.add(deleteUser);
buttonsPanel.add(mainButton);
buttonsPanel.add(tf1);
buttonsPanel.add(searchButton);
buttonsPanel.add(resultLbl);
return buttonsPanel;
}
public void setPic(JFrame jframe){
try{
File f=new File("pics\\user_group.png");
BufferedImage img=ImageIO.read(f);
jframe.setContentPane(new SetMyImage(img));
}
catch(IOException ioe){
}
}
public static void main(String[] args){
new samplepage().setVisible(true);
}
}
第二类:
public class SetMyImage extends JPanel{
private Image img;
public SetMyImage(Image img){
this.img=img;
}
@Override
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.drawImage(img, 00, 00, null);
}
}
我的错误在哪里?