Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Updating UI for all components

843804Jul 1 2005 — edited Jul 13 2005
HI all,
I've been fiddling with making my app more configurable, more pretty and started changing the UI.

That in itself, I don't have a problem with. The java demos illustrated that fine. The problem is that I don't have a reference to everything that needs to be updated, specifically a JFileChooser. Whilst searching I saw others use Frame.getFrames(), but JFileChooser doesn't extend Frame, so no good.
Here's a test rig:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class UpdateUITest extends JFrame implements ActionListener
{
    
    public UpdateUITest()
    {
        super("Update UI Test");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setSize(200,200);
        
        JButton button = new JButton("Change to windows LAF");
        button.addActionListener(this);
        
        getContentPane().setLayout(new GridLayout(2,1));
        getContentPane().add(button);
        getContentPane().add(new TestButtons());
    }
    
    public void actionPerformed(ActionEvent e)
    {
        try
        {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this);
        }
        catch(Exception ex)
        {}
    }
    
    public static void main(String[] args)
    {
        new UpdateUITest().setVisible(true);
    }
}

class TestButtons extends JPanel implements ActionListener
{
    private JFileChooser chooser;
    
    public TestButtons()
    {
        super();
        chooser = new JFileChooser();
        
        JButton button = new JButton("Open FIlechooser");
        button.addActionListener(this);
        add(button);
    }
    
    public void actionPerformed(ActionEvent e)
    {
        int returnVal = chooser.showDialog(this, "Select...");
    }
}
So although class TestButtons gets updated by UpdateUITest (it's a part of it's component tree I assume), my JFileChooser doesn't.

Do I need to override some method in TestButtons (perhaps override updateUI(), update the JFileChooser, then call super.updateUI())?
Or is there some other method I can use?
I could always create my own updateWithThisLAF() method, but doesn't seem the best way.

Regards,
Radish21
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 10 2005
Added on Jul 1 2005
11 comments
331 views