繁体   English   中英

直到我将鼠标悬停在其上时,我的按钮才会显示

[英]My buttons wont appear until i hover over it with my mouse

我遇到了这个问题,是的,我看到其他人也遇到了问题,但是我不能真正比较那里的代码并以这种方式看到问题,所以希望您能为我提供帮助。

我用intellij编写我的代码,并在那里使用gui desinger制作gui,但是当我添加一个按钮时,直到鼠标悬停它并显示位置错误,我才真正能够使它工作。 这是类//这是jpanel类公共类paintMenu扩展了JPanel {

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是一个错字,并且可能会导致编译时错误。 您没有清楚地描述您的问题。

将JPanel添加到JFrame后,尝试将其设置为可见。 另外,您可能需要在添加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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM