[英]Java applet buttons are not displayed until i hover the mouse over them
[英]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.