Java 直到我用鼠标悬停在按钮上,我的按钮才会出现
我有这个问题,是的,我看到其他人也有这个问题,但我真的无法将这些代码与我的代码进行比较,并以这种方式看到问题,所以我希望你能帮助我 我使用intellij编写代码,并使用那里的gui设计工具来制作gui,但当我添加一个按钮时,我没有让它显示出来,直到我用鼠标悬停它,位置错误,我无法真正让它工作。这些是课程 //这是jpanel类 公共类paintMenu扩展了JPanel{Java 直到我用鼠标悬停在按钮上,我的按钮才会出现,java,jframe,jpanel,Java,Jframe,Jpanel,我有这个问题,是的,我看到其他人也有这个问题,但我真的无法将这些代码与我的代码进行比较,并以这种方式看到问题,所以我希望你能帮助我 我使用intellij编写代码,并使用那里的gui设计工具来制作gui,但当我添加一个按钮时,我没有让它显示出来,直到我用鼠标悬停它,位置错误,我无法真正让它工作。这些是课程 //这是jpanel类 公共类paintMenu扩展了JPanel{ public JPanel menuPanel; public JButton newGameButt; public J
public JPanel menuPanel;
public JButton newGameButt;
public JButton loadGameButt;
public JButton helpbutt;
public JButton optionsButt;
public JButton info;
public JButton quitButt;
public paintMenu(){
add(newGameButt);
add(loadGameButt);
add(helpbutt);
add(info);
add(optionsButt);
add(quitButt);
setVisible(true);
}
//this is de jframe class
public class jframepainter extends JFrame {
paintMenu menupaint = new paintMenu();
public jframepainter(){
//main frame settings
setTitle("Kingdom V " + Reference.version);
setSize(Reference.width, Reference.height);
setResizable(false);
setLocationRelativeTo(null);
setVisible(Kingdom.vissible);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//draw jpnael
getContentPane().add(menupaint);
}
我不知道Kingdom类是什么,但我可以假设vissible是一个输入错误,可能会导致编译时错误。您没有清楚地描述您的问题。尝试将JFrame设置为在添加JPanel后可见。此外,您可能希望在添加JPanel后调用this.pack
//main frame settings
setTitle("Kingdom V " + Reference.version);
setSize(Reference.width, Reference.height);
setResizable(false);
setLocationRelativeTo(null);
//draw jpnael
getContentPane().add(menupaint); //Moved this before setting Visible
this.pack(); // call pack before setting visible
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(Kingdom.vissible);
Kingdom是主类,Kingdom.vissible在该类中设置为true