简体   繁体   中英

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();" 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(); AND repaint();

Buttons should appear

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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