Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Some swing components use wrong look and feel

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    0
    Thanked 3 Times in 1 Post

    Default Some swing components use wrong look and feel

    Our application uses a custom Synth based look and feel. On a couple of demo laptops, when new components get created due to some incoming event, the new components use a different look and feel.

    Instead of using our Synth look and feel, the new components get created with the default ( Windows 7 ) look and feel. It is very strange. Other machines using the same java version, 1.7.0_25-b17, work correctly.

    Any ideas?


  2. #2
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    116
    My Mood
    Tired
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Re: Some swing components use wrong look and feel

    Please dont ask us to do your work for you.
    Post the program that isn't working.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Some swing components use wrong look and feel

    Quote Originally Posted by llowe29 View Post
    Please dont ask us to do your work for you.
    Post the program that isn't working.
    I don't believe the OP is asking anyone to do his/her work, and this doesn't sound like a homework problem. The OP presented the bare outline of a problem and is asking for suggestions on how to solve it. If you have some ideas what might be causing the OP's problem but believe more info would be helpful to understand the problem, e.g., the code that sets the look and feel or the code that is called when an "incoming event" occurs, then you could ask for more details.

  4. The Following User Says Thank You to GregBrannon For This Useful Post:

    copeg (August 1st, 2013)

  5. #4
    Junior Member
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    0
    Thanked 3 Times in 1 Post

    Default Re: Some swing components use wrong look and feel

    In fact, I am not asking anyone do to my work for me. We have a very strange problem that only occurs on a couple of machines, and thought I might be able to get some help/suggestions here.

    If it makes you feel better, llowe29, here is the code that sets the look and feel:

    public class ClientLookAndFeel extends SynthLookAndFeel
    {
    public ClientLookAndFeel() throws UnsupportedLookAndFeelException
    {
    super();
    try
    {
    load( ClientLookAndFeel.class.getResourceAsStream( "Client.xml" ), ClientLookAndFeel.class );
    UIManager.setLookAndFeel( this );
    }
    catch ( final ParseException e )
    {
    // todo - Log it
    }
    }
    }

    This is the ONLY place where the look and feel is set in the application. The rest of the application is proprietary and way to large to post. When the program starts, the components all look correct. At some point new components are created, and they use the Windows look and feel. Right in the middle of a panel that is using our look and feel.

  6. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Some swing components use wrong look and feel

    Please post your code in code tags.

    I don't have much experience with changing the look and feel from whatever the host OS prefers to use, but if I were you, I'd wonder why the look and feel changes made by my application aren't persistent. Or, said a different way, if the look and feel is going to change (for whatever reason), how can one ensure that it always returns to what it needs to be when the desired application has focus? Since the look and feel is often set at the OS level, I can see how the look and feel behavior might vary from computer to computer depending on the applications sharing the OS, so think about the problem in a bigger space, not just within the boundaries of your application.

    I suggest that your application reset the look and feel to the desired look and feel each time it takes the focus and each time it processes an incoming event before new components are created, whether it has the focus or not (if that's possible).

    Hope this helps and good luck!

  7. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Some swing components use wrong look and feel

    Just a hunch: does the call to set the look and feel - or any calls which create your GUI - occur on a thread other than the EDT?

  8. #7
    Junior Member
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    0
    Thanked 3 Times in 1 Post

    Default Re: Some swing components use wrong look and feel

    Forgot the code tags, sorry.

    Getting focus is NOT causing the problem. I can be actively using the application when the problem occurs. Example. Select a new value in a combo box. That triggers a JNI call to a DLL which broadcasts an event. The swing part of the application listens for this event and then updates itself by deleting a series of buttons and creating a different series based on the data in the event. These new buttons use the Windows look and feel, even though the look and feel of the application has NOT been changed since the application was started. And, again, this only happens on a couple of machines.

    I have been working with swing for 13 years and have never seen anything like this.

    Thanks for trying to help.

    --- Update ---

    The look and feel is set in a call from the main() routine of the class used to launch the program.

  9. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Some swing components use wrong look and feel

    I've always been told that removing components and adding new ones to an existing interface can be risky, so I've always avoided the practice. I don't know what 'risky' means, but perhaps the behavior you're experiencing is one of the risks.

    Good luck. Sorry I can't be more helpful, but someone much smarter than me will probably happen along and have some ideas.

  10. #9
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Some swing components use wrong look and feel

    Quote Originally Posted by rstrout View Post
    [/COLOR]The look and feel is set in a call from the main() routine of the class used to launch the program.
    Never seen this before myself. Don't mean to hammer the threading issue too hard, but is this call wrapped inside SwingUtillities.invokeLater or something comparable to dispatch to the EDT? And based upon the above post, you create the GUI inside the EDT?

  11. #10
    Junior Member
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    0
    Thanked 3 Times in 1 Post

    Default Re: Some swing components use wrong look and feel

    Thanks anyway.

    --- Update ---

    It wasn't wrapped in SwingUtillities.invokeLater(), but based on your suggestion, I just wrapped in in SwingUtillities.invokeAndWait() and am preparing a build now. Setting the look and feel is ususally the first thing I do in an application. I used invokeAndWait() because I need this to happen first or else out login dialog will not look right. If there is a problem with invokeAndWait(), I'll try invokeLater(). I'll just have to refactor the code so that the stuff to launch the login dialog is called from within the invokeLater() instead of the way it is now.

    I honestly don't think this is the problem because the application look fine when it starts. I am giving it a shot though.

    Thanks

  12. #11
    Junior Member
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    0
    Thanked 3 Times in 1 Post

    Default Re: Some swing components use wrong look and feel

    After further digging, it appears that we are running into an know bug in java 7 update 25.

    Bug ID: JDK-8017776 Swing Event Thread does not use JNLP class loader

    More info can be seen in these threads:

    https://forums.oracle.com/thread/2552214
    https://forums.oracle.com/thread/2552941
    https://forums.oracle.com/message/11090709#11090709
    https://forums.oracle.com/thread/2556898

    Only a few of the machines have been updated to java 7 update 25, that is why not everyone would see it.
    Most of us are still on java 7 update 21. Also, the problem ONLY occurs when the application is launched via JNLP.
    When the app is launched view command line or IDE, everything works fine.
    In a nutshell, update 25 broke how the AppContext is maintained. Instead of there being only 1, there are now several.
    We have tried the workarounds listed in the bug and threads ( launch console with app, set the class loader in the
    EventQueue, etc ... ) but none of them worked for us. We are going to uninstall update 25 and reload update 21 on
    the problem machines.

    Good luck to anyone else that sees this. Hopefully Oracle will fix this soon.

  13. The Following 3 Users Say Thank You to rstrout For This Useful Post:

    copeg (August 6th, 2013), GregBrannon (August 6th, 2013), jps (August 6th, 2013)

  14. #12
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Some swing components use wrong look and feel

    Thanks for the update.

Similar Threads

  1. Replies: 0
    Last Post: March 11th, 2012, 08:36 AM
  2. HTML in Swing Components in Cached Applet
    By KevinWorkman in forum Java Applets
    Replies: 6
    Last Post: August 1st, 2011, 07:46 AM
  3. Java tip Sep 22, 2010 - "Screenshots" of swing components
    By helloworld922 in forum Java Code Snippets and Tutorials
    Replies: 3
    Last Post: June 6th, 2011, 01:25 AM
  4. Swing Components Invisible as Startup
    By SpiceProgrammer in forum AWT / Java Swing
    Replies: 5
    Last Post: January 23rd, 2011, 02:26 PM
  5. Painting swing components to an arbitrary position?
    By ScummyChimp in forum AWT / Java Swing
    Replies: 1
    Last Post: September 1st, 2009, 11:06 PM