• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why a different look and feel on second instance?  RSS feed

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
     
    Michael Dunn
    Ranch Hand
    Posts: 4632
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 11343
    Java Mac Safari
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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 ]
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!