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!

Answers


You need to revalidate(); AND repaint();

Buttons should appear


Need Your Help

javascript recurrent countdown

php javascript countdown

i have a question regarding a countdown timer.

ICU4J LocaleData.MeasurementSystem

java internationalization

I wish to use ICU4J library for i18n.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.