这是有问题的 JPanel 类:
public class EntryDialog extends JPanel{
private static final long serialVersionUID = 1L;
MainWindow mainWindow;
Image background;
JButton continueresume;
JButton newresume;
JButton settings;
JButton exit;
public EntryDialog(MainWindow mainWindow){
continueresume = new JButton("Continue resume");
newresume = new JButton("New resume");
settings = new JButton("Settings");
exit = new JButton("Exit");
this.mainWindow = mainWindow;
this.background = Utilities.getImage("images\\entryDialogBackground.jpg", true);
this.setLayout(null);
//continueresume button
continueresume.setBounds(Utilities.getScaledWidth(1150),
Utilities.getScaledHeight(150),
Utilities.getScaledWidth(500),
Utilities.getScaledHeight(50));
//newresume button
newresume.setBounds(Utilities.getScaledWidth(1150),
Utilities.getScaledHeight(220),
Utilities.getScaledWidth(500),
Utilities.getScaledHeight(50));
//settings button
settings.setBounds(Utilities.getScaledWidth(1150),
Utilities.getScaledHeight(290),
Utilities.getScaledWidth(500),
Utilities.getScaledHeight(50));
//exit button
exit.setBounds(Utilities.getScaledWidth(1150),
Utilities.getScaledHeight(360),
Utilities.getScaledWidth(500),
Utilities.getScaledHeight(50));
this.add(continueresume);
this.add(newresume);
this.add(settings);
this.add(exit);
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
if(background != null){
g2d.drawImage(background, 0, 0, this);
}
g2d.dispose();
}
此 JPanel 正在绘制到另一个类的主框架上。正在发生的事情是“背景”被画得很好,但按钮却没有。一旦我用鼠标悬停在按钮上,按钮就会出现,但在那之前它们是不可见的。我已经搜索了几个小时并没有找到解决方案,因此我们将不胜感激。谢谢!