简体   繁体   English

鼠标接触前JApplet中未显示JButton

[英]JButtons not showing in JApplet before mouse contact

I have this problem with my Applet not showing Buttons, before I move the mouse over them. 在将鼠标移到按钮上之前,我的小程序没有显示按钮,我遇到了这个问题。 I googled it, and found out "validate();" 我用谷歌搜索,发现“ validate();” might help. 可能有帮助。 It did not. 它没。 Maybe I did it wrong, but couldn't find any other solution. 也许我做错了,但是找不到其他解决方案。 Here's my code: 这是我的代码:

    public void paintMainMenu(){
    Container conMain = getContentPane();
    play = new JButton("Play");
    credits = new JButton("Credits");
    controls = new JButton("Controls");
    FlowLayout lay1 = new FlowLayout();
    JPanel mainPanel = new JPanel();
    mainPanel.setSize(SW, SH);
    mainPanel.setLayout(lay1);
    mainPanel.add(play);
    mainPanel.add(credits);
    mainPanel.add(controls);
    play.addActionListener(this);
    credits.addActionListener(this);
    controls.addActionListener(this);
    conMain.add(mainPanel);
    conMain.validate(); // Validation...
    setContentPane(conMain);
}

I think the problem exists in here, but if you want full code just tell. 我认为这里存在问题,但是如果您想要完整的代码,请告诉。

Thanks! 谢谢!

You need to revalidate(); 您需要revalidate(); AND repaint(); AND repaint();

Buttons should appear 按钮应该出现

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

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