Search code examples
javaswinglook-and-feeljdialogjoptionpane

java- how can you set the Look&Feel to JOptionPanes and classes that extend JDialog?


I'm currently using Look&Feel for my application. I have a few problems:

1. When I start my program, the first thing that pops up is a JDialog for login. This is normal, but the problem is that it's the default Look&Feel. Now, after you get pass the login, the main program launches with the Look&Feel I chose. One thing to note is that the JDialog is constructed like this:

    public class FooLogin extends JDialog{
        // variables...

    public FooLogin(JFrame parent){
        // code...

2. My JOptionPanes are all default as well.

So how do I explicitly apply Look&Feel to a JDialog in this form? And how can I match the JOptionPanes to the Look&Feel of the main program?


Solution

  • You forgot to mentioned for which from Look and Feels, but by default you have to read Changing the Look and Feel After Startup, then you have to call code line before visible of a new Container

    SwingUtilities.updateComponentTreeUI(frame);
    

    be sure that you have to create a new Container wrapped into invokeLater, more in Initial Threads