简体   繁体   English

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

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

i have this problem and yes i saw that other people had the problem to but i not realy able to compare there code to mine and see the problem that way so i hope u can help me. 我遇到了这个问题,是的,我看到其他人也遇到了问题,但是我不能真正比较那里的代码并以这种方式看到问题,所以希望您能为我提供帮助。

i use intellij to write my code and use there gui desinger to make gui's but when i added a button i didnt get it to display untill i hover it with a mouse and the possitions are wrong and i cant realy get it to work. 我用intellij编写我的代码,并在那里使用gui desinger制作gui,但是当我添加一个按钮时,直到鼠标悬停它并显示位置错误,我才真正能够使它工作。 here are the classes // this is the jpanel class public class paintMenu extends JPanel{ 这是类//这是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);

}

I don't know what the Kingdom class is, but i can assume that vissible is a typo and may be causing a compile-time error. 我不知道Kingdom类是什么,但是我可以假定vissible是一个错字,并且可能会导致编译时错误。 You didn't clearly describe your problem. 您没有清楚地描述您的问题。

Try setting the JFrame to visible after you add your JPanel to it. 将JPanel添加到JFrame后,尝试将其设置为可见。 Also you may want to call this.pack() after you add your 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);

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

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