This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Why a different look and feel on second instance?

 
Sheriff
Posts: 11343
Mac Safari Java
  • 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 ]
     
    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
    Mac Safari Java
    • 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 ]
     
    Good heavens! What have you done! Here, try to fix it with this tiny ad:
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
      Bookmark Topic Watch Topic
    • New Topic