aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Why a different look and feel on second instance? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Why a different look and feel on second instance?" Watch "Why a different look and feel on second instance?" New topic
Author

Why a different look and feel on second instance?

marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

If I create 2 frames -- even if they're both instances of the same class -- why do they each have a different look and feel?

For example, the code below creates 2 frames from the same class. The only difference is the title ("First" and "Second") and the vertical placement on the screen. The first looks native (in this case, Windows), but the second looks Metal.



NOTES:
  • The above code is just a simple demo of what I've been observing in more complex code. In my other code, the frames use different classes. I've switched the order around, and it's always the first instance that looks native and the second that looks Metal.
  • I realize that the above behavior can be avoided by using a UIManager to set the look and feel as desired. I'm just wondering why this is happening.
  • This is on a Windows 2000 machine running Java 5.0.

  • [ October 25, 2005: Message edited by: marc weber ]

    "We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
    sscce.org
    Michael Dunn
    Ranch Hand

    Joined: Jun 09, 2003
    Posts: 4632
    it seems you have to set the lookandfeel of the JFrame class, prior to instantiating

    toggle the indicated lines of this to see the difference

    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    Thanks, Michael! That explains it.

    The default appears to be a native look and feel (at least for the window decorations). When both of these lines are commented, both frame instances look native. In my original code, the first instance used this default, but then I changed the default decorated setting, so Metal (if that's still what it's called) was used for subsequent frames.

    What's interesting is that I was using getSystemLookAndFeelClassName() to make this native. But given its placement in my code, this probably wasn't really doing anything to my first instance. It just looked like it was because the native was already being used as a default.

    So my original question was just a curiosity, but I think you saved me some real headaches in the future!
    [ October 25, 2005: Message edited by: marc weber ]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Why a different look and feel on second instance?
     
    Similar Threads
    GUI problems with extending JFrame
    close and open a frame
    a qn from RHE..
    Swing Look and Feel not working
    Designing GUIs with cross-platform look and feel