Using menu to update look and feel

Hi all,
I am trying to update the look and feel of my application.
In the main method I set the look and feel to metal.However, I have created a menu with an option to change the look and feel at runtime. I want the user to be able to just select the required look, e.g. Windows,on the drop down menu and then have the application updated.
I know that the following does not work:
void jMenuItem10_actionPerformed(ActionEvent exc) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
this.repaint();
catch(Exception excs) {
excs.printStackTrace();
Am I miles away from the correct solution or am I nearly there? All help gratefully received.
Regards.

After UIManager.setLookAndFeel() add this row:
SwingUtilities.updateComponentTreeUI(this);
I don't think you need this.repaint();
Hope this will help you!

Similar Messages

  • Use more than one look and feel in the Portal

    Hi,
    I'm searching for a solution to use more than one Theme in the portal. It's not based on user or a role. One and the same user should be able to enter the portal and depending on his adress he should be rooted to A or B theme.
    We are usein EP6 sps13.
    Kind regards
    Michiel Veenemans

    Hello,
    To my feeling you should be work with display rules.
    You probably have user who need one theme and other user you want to give another theme. By using display rules you can assign a theme to one user group and another theme or themes to another group.
    So depending on the group the user is assigned to you get another theme. This way everybody uses the same URL and a theme can be altered with the default user functions.
    Best regards,
    Frederik

  • Problem With ButtonUI in an Auxiliary Look and Feel

    This is my first post to one of these forums, so I hope everything works correctly.
    I have been trying to get an axiliary look and feel installed to do some minor tweaking to the default UI. In particular, I need it to work with Windows and/or Metal as the default UI. For the most part I let the installed default look and feel handle things with my code making some colors lighter, darker, etc. I also play with focus issues by adding FocusListeners to some components. I expect my code to work reasonably well no matter what the default look and feel is. It works well with Motif, Metal, and Windows, the only default look and feels I've tested with. What I'm going to post is a stripped down version of what I have been working on. This example makes gross changes to the JButton background and foreground colors in order to illustrate what I've encountered.
    I have three source code files. The first, Problem.java, creates a JFrame and adds five buttons to it. One button installs MyAuxLookAndFeel as an auxiliary look and feel using MyAuxButtonUI for the look and feel of JButtons. The next button removes that look and feel. The next button does nothing except print a line to System.out. The next button installs MyAuxLookAndFeel as an auxiliary look and feel using MyModButtonUI for the look and feel of JButtons. The last button removes that look and feel.
    The problem is, when I install the first auxiliary look and feel, buttons are no longer tabable. Also, they cannot be invoked by pressing the space button when they're in focus. When I remove the first auxiliary look and feel everything reverts to behaving normally. When I add the "Mod" version, button tabability is fine. The only difference is I've added the following code:
    if ( c.isFocusable() ) {
       c.setFocusable(true);
    }That strikes me as an odd piece of code to profoundly change the program behavior. Anyway, after adding and removing the "Mod" look and feel, the tababilty is forever fixed. That is, if I subsequently re-install the first look and feel, tababilty works just fine.
    The problem with using the space bar to select a focused button is more problematic. My class is not supposed to mess with the default look and feel which may or may not use the space bar to press the button with focus. When the commented code in MyModButtonUI is uncommented, things behave correctly. Even the statement
    button.getInputMap().remove( spaceKeyStroke );doesn't mess things up after the auxiliary look and feel is removed. So far I've tested this with JRE 1.4.2_06 under Windows 2000, JRE 1.4.2_10 under Windows XP, and JRE 1.5.0_06 under Windows XP and the behavior is the same.
    All of this leads me to two questions.
    1. Is my approach fundamentally flawed? I've extended TextUI and ScrollBarUI with no problems. This is the only problem I've encountered with ButtonUI. My real workaround for the space bar issue is better than the one I've supplied in the example, but it certainly is not guaranteed to work for any arbitrary default look and feel.
    2. Assuming I have no fundamental problems with my approach, it's possible I've found a real bug. I searched the bug database and couldn't find anything like this. Of course, this is the first time I've tried seasrching the database for a bug so my I'm doing it badly. Has this already been reported as a bug? Is there any reason I shouldn't report it?
    What follows is the source code for my example. It's in three files because the two ButtonUI classes must be public in order to work. Thanks for insight you can provide.
    Bill
    File Problem.java:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Problem extends JFrame {
       public boolean isAuxInstalled = false;
       public boolean isModInstalled = false;
       public LookAndFeel lookAndFeel = new MyAuxLookAndFeel();
       private static int ctr = 0;
       public static void main( String[] args ) {
          new Problem();
       public Problem() {
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize(250, 150);
          setTitle("Button Test");
          JButton install = new JButton("Install");
          JButton remove = new JButton("Remove");
          JButton doNothing = new JButton("Do Nothing");
          JButton installMod = new JButton("Install Mod");
          JButton removeMod = new JButton("Remove Mod");
          this.getContentPane().setLayout(new FlowLayout());
          this.getContentPane().add(install);
          this.getContentPane().add(remove);
          this.getContentPane().add(doNothing);
          this.getContentPane().add(installMod);
          this.getContentPane().add(removeMod);
          install.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( !isAuxInstalled ) {
                   isAuxInstalled = true;
                   UIManager.addAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          remove.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( isAuxInstalled ) {
                   isAuxInstalled = false;
                   UIManager.removeAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          doNothing.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                System.out.println( "Do nothing " + (++ctr) );
          installMod.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( !isModInstalled ) {
                   isModInstalled = true;
                   UIManager.addAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          removeMod.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( isModInstalled ) {
                   isModInstalled = false;
                   UIManager.removeAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          setVisible(true);
       class MyAuxLookAndFeel extends LookAndFeel {
          public String getName() {
             return "Button Test";
          public String getID() {
             return "Not well known";
          public String getDescription() {
             return "Button Test Look and Feel";
          public boolean isSupportedLookAndFeel() {
             return true;
          public boolean isNativeLookAndFeel() {
             return false;
          public UIDefaults getDefaults() {
             UIDefaults table = new MyDefaults();
             Object[] uiDefaults = {
                "ButtonUI", (isModInstalled ? "MyModButtonUI" : "MyAuxButtonUI"),
             table.putDefaults(uiDefaults);
             return table;
       class MyDefaults extends UIDefaults {
          protected void getUIError(String msg) {
    //         System.err.println("(Not) An annoying error message!");
    }File MyAuxButtonUI.java:
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.plaf.*;
    import javax.swing.plaf.multi.*;
    import javax.accessibility.*;
    public class MyAuxButtonUI extends ButtonUI {
       private Color background;
       private Color foreground;
       private ButtonUI ui = null;
       public static ComponentUI createUI( JComponent c ) {
          return new MyAuxButtonUI();
       public void installUI(JComponent c) {
          MultiButtonUI multiButtonUI = (MultiButtonUI) UIManager.getUI(c);
          this.ui = (ButtonUI) (multiButtonUI.getUIs()[0]);
          super.installUI( c );
          background = c.getBackground();
          foreground = c.getForeground();
          c.setBackground(Color.GREEN);
          c.setForeground(Color.RED);
       public void uninstallUI(JComponent c) {
          super.uninstallUI( c );
          c.setBackground(background);
          c.setForeground(foreground);
          this.ui = null;
       public void paint(Graphics g, JComponent c) {
          this.ui.paint( g, c );
       public void update(Graphics g, JComponent c) {
          this.ui.update( g, c );
       public Dimension getPreferredSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getPreferredSize( c );
          return this.ui.getPreferredSize( c );
       public Dimension getMinimumSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getMinimumSize( c );
          return this.ui.getMinimumSize( c );
       public Dimension getMaximumSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getMaximumSize( c );
          return this.ui.getMaximumSize( c );
       public boolean contains(JComponent c, int x, int y) {
          if ( this.ui == null ) {
             return super.contains( c, x, y );
          return this.ui.contains( c, x, y );
       public int getAccessibleChildrenCount(JComponent c) {
          if ( this.ui == null ) {
             return super.getAccessibleChildrenCount( c );
          return this.ui.getAccessibleChildrenCount( c );
       public Accessible getAccessibleChild(JComponent c, int ii) {
          if ( this.ui == null ) {
             return super.getAccessibleChild( c, ii );
          return this.ui.getAccessibleChild( c, ii );
    }File MyModButtonUI.java:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.plaf.*;
    public class MyModButtonUI extends MyAuxButtonUI
       static KeyStroke spaceKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0 );
       public static ComponentUI createUI( JComponent c ) {
          return new MyModButtonUI();
       public void installUI(JComponent c) {
          super.installUI(c);
          c.setBackground(Color.CYAN);
          if ( c.isFocusable() ) {
             c.setFocusable(true);
    //      final JButton button = (JButton) c;
    //      button.getInputMap().put( spaceKeyStroke, "buttonexample.pressed" );
    //      button.getActionMap().put( "buttonexample.pressed", new AbstractAction() {
    //         public void actionPerformed(ActionEvent e) {
    //            button.doClick();
    //   public void uninstallUI(JComponent c) {
    //      super.uninstallUI(c);
    //      JButton button = (JButton) c;
    //      button.getInputMap().remove( spaceKeyStroke );
    //      button.getActionMap().remove( "buttonexample.pressed" );
    }

    here is the code used to change the current look and feel :
    try {
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
             catch (InstantiationException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (ClassNotFoundException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (UnsupportedLookAndFeelException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (IllegalAccessException e)
                  System.out.println("Error occured in .. " + e.toString());
             Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
             Fenetre fen = new Fenetre();
             fen.setSize(dim.width, dim.height);
             fen.setResizable(false);
                 fen.setLocation(0, 0);
                  fen.setVisible(true);

  • Accessing File/Folder icons for current Look and Feel

    Hi,
    I'm looking to get the Icon for files and folders that the current UIManager uses for some work I'm doing. Please could you help.
    I'm getting strange results from the method I'm using, which is to create a temporary file and do: Icon i = FileSystemView.getFileSystemView().getSystemIcon(tempFile);
    I don't like the idea of having to create a temporary file to do this - isn't there another way to do it? - for instance asking "get default file icon"/"get default folder icon".
    I could download a jpg image of the file/folder icons, but this is static - and I want my method to get the icons used for the current look and feel I'm using.
    There must be a simple way to do this right? I mean, java uses a method to get the icons for the current look and feel.. Oh.. Please help!
    - Edd.

    Try these:
    UIManager.getIcon("FileView.directoryIcon");
    UIManager.getIcon("FileView.fileIcon");Leif Samuelsson
    Java Swing Team
    Sun Microsystems, Inc.

  • Stefankrause XP look and feel

    Hi
    I m posting this thread again. Can anyone show the way to get rid of SecretLoader class in Stefankrause look and feel. SerectLoader Code is not available on net , but this is used in Stefankrause XP look and feel.I have tried default icons but does not exactly serve the purpose.
    I've downloded code from
    http://www.stefan-krause.com/java/
    Or if u've info regarding where is icon file for Microsoft Windows XP on Computer that are used in Java, like icons for plus ,minus, or question mark etc.
    Thanx.

    Hi there, I've used this package and u can use DJ - the java decompiler or jad to decomile it. Or event u can use Gel(a Java IDE written in Java) to just double click the class file to view it's source. Gel can be found at http://www.gexperts.com/.
    note the code
    abyte0[l] ^= 0x2a;
    is what the author exactual encode the resource. u can alse use this method to get the original images, in fact, i've done this, hehe. Since abyte ^ 0x2a ^ 0x2a = abyte, this is just a bitwise operation equals.
    // SecretLoader.java
    // Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
    // Jad home page: http://kpdus.tripod.com/jad.html
    // Decompiler options: packimports(3)
    package com.stefankrause.xplookandfeel.skin;
    import java.awt.*;
    import java.io.ByteArrayOutputStream;
    import java.io.InputStream;
    import java.net.URL;
    import javax.swing.JPanel;
    public class SecretLoader
    public SecretLoader()
    static Image loadImage(String s)
    URL url;
    url = (com.stefankrause.xplookandfeel.skin.SecretLoader.class).getResource("/com/stefankrause/xplookandfeel/icons/" + s);
    Object obj = null;
    Image image;
    InputStream inputstream = url.openStream();
    ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
    byte abyte0[];
    if(s.endsWith(".res"))
    inputstream.read();
    inputstream.read();
    for(int i = inputstream.read(buffer); i != -1; i = inputstream.read(buffer))
    bytearrayoutputstream.write(buffer, 0, i);
    abyte0 = bytearrayoutputstream.toByteArray();
    for(int l = 0; l < abyte0.length; l++)
    abyte0[l] ^= 0x2a;
    } else
    for(int j = inputstream.read(buffer); j != -1; j = inputstream.read(buffer))
    bytearrayoutputstream.write(buffer, 0, j);
    abyte0 = bytearrayoutputstream.toByteArray();
    int k = inputstream.read(abyte0);
    image = Toolkit.getDefaultToolkit().createImage(abyte0, 0, abyte0.length);
    MediaTracker mediatracker = new MediaTracker(panel);
    mediatracker.addImage(image, 0);
    try
    mediatracker.waitForID(0);
    catch(InterruptedException interruptedexception) { }
    return image;
    Throwable throwable;
    throwable;
    throw new IllegalArgumentException("File " + s + " could not be loaded.");
    static JPanel panel = new JPanel();
    static byte buffer[] = new byte[4096];
    }

  • Switching Look and Feel

    menu = new JMenu ( "Look and Feel" );
    menu.setMnemonic ( KeyEvent.VK_L );
    menuBar.add ( menu );
    JMenuItem lookAndFeel[];
    final UIManager.LookAndFeelInfo laf[] = UIManager.getInstalledLookAndFeels();
    lookAndFeel = new JMenuItem[laf.length];
    for ( int i = 0; i < laf.length; i++ )
    lookAndFeel[i] = new JMenuItem ( laf.getName() );
                   lookAndFeel[i].addActionListener (
                        new ActionListener() {
                             public void actionPerformed ( ActionEvent e )
                                  UIManager.setLookAndFeel ( laf[i].getClassName() );
                                  SwingUtilities.updateComponentTreeUI ();
                   menu.add ( lookAndFeel[i] );

    i get these errors, can someone give me a hand at the solution?
    C:\app\Applicatie.java:198: local variable i is accessed from within inner class; needs to be declared final
                                  UIManager.setLookAndFeel ( laf.getClassName() );
    ^
    C:\app\Applicatie.java:199: updateComponentTreeUI(java.awt.Component) in javax.swing.SwingUtilities cannot be applied to ()
                                  SwingUtilities.updateComponentTreeUI ();
    Many thanks

  • Problem about look and feeling

    i want to make my jframe looking and feeling like jdeveloper.what should i do ?

    Hi,
    if I remember well then JDeveloper uses the JGoodies Plastic Look and Feel. Just go to http://www.jgoodies.com/ and get the look and feel.
    Frank

  • Aqua Look and Feel

    Hello everybody,
    can someone show me how to use the Mac Aqua Look and Feel on Windows platform.
    Thanks very much!!!!!

    You can't since it uses calls to native APIs that are available only under Mac OS.

  • How to change the look and feel for Heading of quick launch menu in project server 2010

    Hi
    can someone tell me how to change the look and feel of Header names in quick launch.
    I want the header to be displayed in Bold with Underline to it.
    could this be possible for just header in quick launch in project server 2010. 

    Hi Rohan
    It does not work this way. You have to use a content editor webpart.
    See references below that might help you starting with this customisation:
    Http://go4answers.webhost4life.com/Example/sharepoint-2010-quick-launch-look-feel-78379.aspx
    Http://m.sharepointpromag.com/sharepoint/four-ways-add-or-remove-quick-launch-menu-control
    Hope this helps.
    Guillaume Rouyre - MBA, MCP, MCTS

  • SSHR reskin AKA 'How to Use Adobe Flash to Transform the Look and Feel...

    There was a presentation at the OHUG 2011 Conference titled 'How to Use Adobe Flash to Transform the Look and Feel of Oracle HR Self Service'. It presented a method of 're-skinning' SSHR to present a different UI to the user.
    Looking for anyone out there that has attempted to apply this to their Oracle HRSS pages. I know this company has developed (is developing?) a product based on this approach. I want to see if anyone has done it on their own and would be willing to share some details.
    Follow-up question. Has anyone availed themselves of the bespoke UI Development based on this approach from Applaud Solutions (as mentioned on their website), and care to comment on your experience?

    Any update on this please? Even we are looking for some pointers in this area.

  • I just updated iOS on my iPhone 5. What a shock!! Where is the premium look and feel I bought my iPhone for? If I wanted the lokale feel of iOS 7.0 I would have bought a much cheeper taiwanese smartphone. Please let me know how I can return to the origina

    I just updated iOS on my iPhone 5.
    What a shock!! Where is the premium look and feel I bought my iPhone for?
    If I wanted the lokale feel of iOS 7.0 I would have bought a much cheeper taiwanese smartphone.
    Please let me know how I can return to the original look and feel of the iPhone surface I bought my phone for.

    You had plenty of time to look at screenshots on the internet and read various blog posts about iOS 7.

  • Frame Moving Runtime using Look and Feel

    Hi All,
    I need creating Frame Moving runtime using Look and feel (Oracle forms 10 g with swing concept). If any bodies know give me a idea and demo files.
    Thanks and Regards
    M.Sathiya

    Dear Francois,
    Thanks all are working good and result also perfect but frame and DnD is not properly working compile time no problem only problem is run time it given error :java.lang.VerifyError:(class:oracle/forms/fd/frame$FrameBorder;methed <init> Signature:(Loracle/forms/fd/frame;)V) please tell me how can solve this problem.
    Regards,
    M.Sathiya

  • HT4623 I have just updated to ios7 on my iphone and don't like the look and feel of this update. Where are all the colors and texture of all the older isos, all those white background colors,yuk. Is a way to go back to the ios6

    I have just updated to ios7 on my iphone and don't like the look and feel of this update. Where are all the colors and texture of all the older isos, all those white background colors,yuk. Is a way to go back to the ios6

    "Unlike".  iOS 7 doesnt display well on my 4S. iOS 6.1.3 should still be supported for older hardware.  I think I shall me moving to Samsung Galaxy now.  Was really hoping hte new iphone would get a bit larger.

  • How to use a thirdparty look and feel

    how to use a thirdparty look and feel
    i download some from
    http://javootoo.l2fprod.com/
    but how to use?

    Include the downloaded jar file in your classpath.
    Then during startup of your application, call UIManager.setLookAndFeel(className) where className is the class name of your Look & Feel

  • Changing the fonts used by the look and feel?

    I want to be able to change the font settings for the program I'm writing. Is there any way to do this without writing my own theme and/or LookAndFeel? For example, is there a way to just use the Nimbus Look & Feel, but override the fonts it uses somehow? I've been browsing around and it seems like most solutions are to write your own theme from scratch, which I'd like to avoid if possible (I don't want to change anything else, just the fonts!).
    Any help or guidance is very much appreciated. Please let me know if I was unclear.

    Thank you both for the links. I realize I didn't ask this initially, and you both answered the question I asked, but I'm actually curious if there's a way to do this consistently across different looks and feels. Just some sort of blanket command that, regardless of what the Look and Feel is, overrides font selections. Perhaps I'm looking for a way to override the mappings of logical fonts? I'm not exactly sure how one would accomplish it.
    I don't do this because I want to force the user into using a specific font, but actually I'm trying to add a feature that allows the user to override the Look & Feel's font choices with their own if they so choose.
    But I can't control what Look and Feel they're using (well, I can, but I have chosen not to).
    Does any of that make sense?
    Edited by: Caryy on Sep 21, 2010 11:22 AM

Maybe you are looking for

  • Lack supporting Sony RX100 II in Adobe Camera RAW

    Please, integrate full support Sony RX100 & RX100 II to Adobe Camera RAW. This is a very good and expensive cameras. I replace my Nikon D5100 with Sony RX100 II, and second gives better quality despite very small size. But support in Camera RAW limit

  • No Cover flow for Search History in Safari 6.1

    Just upgraded to Safari 6.1 and can't search my history using the visual (coverflow) method anymore? I use that all the time here at work. Please tell me there's a way to get it working again, because looking at a page full of URLs does NOT help!

  • Problem using getCurrent() and setCurrent()

    In the following code snippet: public class MyMidlet extends MIDlet {    public void startApp() {       Display.getDisplay(this).setCurrent(new Form("")));       System.out.println("" + Display.getDisplay(this).getCurrent())); }my application prints

  • Why only one public class in a source file?

    why we have to write only one public class in a source file?

  • How to add custom line for today's date

    Hi, I want to add one vertical line for today's date on my line chart. Is it possible to draw custom line dynamically in line chart. Thanks in advance Madhuri