Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

changing L&F for popup

I have a popup menu that I show when the user presses a button on my UI.
The problem is when the L&F gets changed and I do

UIManager.setLookAndFeel(..);
SwingUtilities.updateComponentTreeUI(mainFrame);

all my components get updated to the new L&F except for the popup. Is there a way to fix this ?
0
hapciu
Asked:
hapciu
1 Solution
 
edwardiiiCommented:
Hi, hapciu.

If the pop-up is supposed to stay up after the user changes the LookAndFeel, would it be an option for you to close/re-open the popup so the new LookAndFeel can take effect (on the pop-up)?
0
 
hapciuAuthor Commented:
it's not supposed to stay open - so it isn't shown while the LF changes. but the next time I show it - it still has the old LF

thanks
0
 
edwardiiiCommented:
Please ignore my recommendation to reopen/reinvoke your popup.  On my JFrame with a "jPopupMenu1" item, this changed the format of everything including the visible pop-up menu:

    try
        {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this);
            SwingUtilities.updateComponentTreeUI(jPopupMenu1);
        }
       
        catch (Exception e)
        {
            //your code, if any;
        }



 SwingUtilities.updateComponentTreeUI(this);
     SwingUtilities.updateComponentTreeUI(jPopupMenu1);
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
edwardiiiCommented:
To be more clear, even if you use your code "SwingUtilities.updateComponentTreeUI(mainFrame);" instead of my version with "this", as long as you include the following line of code,
your jPopup will retain the changed LookAndFeel, no matter how many times you subsequently open/close it:

     SwingUtilities.updateComponentTreeUI(jPopupMenu1);

Just substitute "jPopupMenu1" with the name of your jPopupMenu:)
0
 
aozarovCommented:
BTW, the reason for that is:
SwingUtilities.updateComponentTreeUI(component) will call updateUI on this component and each one of its children.
JPopupMenu is not a child of your frame (you never add it to your frame nor to its children).
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You should probably change the L&F before showing the pop-up.
0
 
hapciuAuthor Commented:
sorry for the delay
thanks
0
 
edwardiiiCommented:
Thank you;)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now