Java Code Examples for javax.swing.UIManager#addPropertyChangeListener()

The following examples show how to use javax.swing.UIManager#addPropertyChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HtmlBrowser.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Dialog(RootPaneContainer parent, String title, boolean modal) {
  super(parent instanceof Frame ? (Frame) parent : null, title, modal);

  // L&F may change
  UIManager.addPropertyChangeListener(new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent e) {
      if (e.getPropertyName().equals("lookAndFeel"))
        SwingUtilities.updateComponentTreeUI(HtmlBrowser.Dialog.this);
    }
  });

  // add a dismiss button
  JButton dismissButton = new JButton("Dismiss");
  topButtons.add(dismissButton, null);

  dismissButton.addActionListener(e -> setVisible(false));

  // add it to contentPane
  Container cp = getContentPane();
  cp.setLayout(new BorderLayout());
  cp.add(HtmlBrowser.this, BorderLayout.CENTER);
  pack();
}
 
Example 2
Source File: SwingSet3.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
@Override 
protected void startup() {
    UIManager.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getPropertyName().equals("lookAndFeel")) {
                configureDefaults();
            }
        }
    });
    
    configureDefaults();
    
    View view = getMainView();
    view.setComponent(createMainPanel());
    view.setMenuBar(createMenuBar());
    
    applyDefaults();
    
    // application framework should handle this
    getMainFrame().setIconImage(resourceMap.getImageIcon("Application.icon").getImage());
    
    show(view);     
}
 
Example 3
Source File: MetalworksFrame.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public MetalworksFrame() {
    super("Metalworks");
    final int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset
            * 2);
    buildContent();
    buildMenus();
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            quit();
        }
    });
    UIManager.addPropertyChangeListener(new UISwitchListener(
            (JComponent) getRootPane()));
}
 
Example 4
Source File: LookAndFeelAddons.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If true, everytime the Swing look and feel is changed, the addon which
 * best matches the current look and feel will be automatically selected.
 * 
 * @param tracking
 *          true to automatically update the addon, false to not automatically
 *          track the addon. Defaults to false.
 * @see #getBestMatchAddonClassName()
 */
public static synchronized void setTrackingLookAndFeelChanges(boolean tracking) {
  if (trackingChanges != tracking) {
    if (tracking) {
      if (changeListener == null) {
        changeListener = new UpdateAddon();
      }
      UIManager.addPropertyChangeListener(changeListener);
    } else {
      if (changeListener != null) {
        UIManager.removePropertyChangeListener(changeListener);
      }
      changeListener = null;
    }
    trackingChanges = tracking;
  }
}
 
Example 5
Source File: MetalworksFrame.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public MetalworksFrame() {
    super("Metalworks");
    final int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset
            * 2);
    buildContent();
    buildMenus();
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            quit();
        }
    });
    UIManager.addPropertyChangeListener(new UISwitchListener(
            (JComponent) getRootPane()));
}
 
Example 6
Source File: MetalworksFrame.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public MetalworksFrame() {
    super("Metalworks");
    final int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset
            * 2);
    buildContent();
    buildMenus();
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            quit();
        }
    });
    UIManager.addPropertyChangeListener(new UISwitchListener(
            (JComponent) getRootPane()));
}
 
Example 7
Source File: MetalworksFrame.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public MetalworksFrame() {
    super("Metalworks");
    final int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset
            * 2);
    buildContent();
    buildMenus();
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            quit();
        }
    });
    UIManager.addPropertyChangeListener(new UISwitchListener(
            (JComponent) getRootPane()));
}
 
Example 8
Source File: MetalworksFrame.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public MetalworksFrame() {
    super("Metalworks");
    final int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset
            * 2);
    buildContent();
    buildMenus();
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            quit();
        }
    });
    UIManager.addPropertyChangeListener(new UISwitchListener(
            (JComponent) getRootPane()));
}
 
Example 9
Source File: MetalworksFrame.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public MetalworksFrame() {
    super("Metalworks");
    final int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset
            * 2);
    buildContent();
    buildMenus();
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            quit();
        }
    });
    UIManager.addPropertyChangeListener(new UISwitchListener(
            (JComponent) getRootPane()));
}
 
Example 10
Source File: TitledBorder.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private void installPropertyChangeListeners() {
    final WeakReference<TitledBorder> weakReference = new WeakReference<TitledBorder>(this);
    final PropertyChangeListener listener = evt -> {
        TitledBorder tb = weakReference.get();
        String prop = evt.getPropertyName();
        if (tb != null && ("lookAndFeel".equals(prop) || "LabelUI".equals(prop))) {
            tb.label.updateUI();
        }
    };

    UIManager.addPropertyChangeListener(listener);
    UIManager.getDefaults().addPropertyChangeListener(listener);
    CleanerFactory.cleaner().register(this, () -> {
        UIManager.removePropertyChangeListener(listener);
        UIManager.getDefaults().removePropertyChangeListener(listener);
    });
}
 
Example 11
Source File: SwingSet3.java    From littleluck with Apache License 2.0 6 votes vote down vote up
@Override 
protected void startup() {
    UIManager.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getPropertyName().equals("lookAndFeel")) {
                configureDefaults();
            }
        }
    });
    
    configureDefaults();
    
    View view = getMainView();
    view.setComponent(createMainPanel());
    view.setMenuBar(createMenuBar());
    
    applyDefaults();
    
    // application framework should handle this
    getMainFrame().setIconImage(resourceMap.getImageIcon("Application.icon").getImage());
    
    show(view);     
}
 
Example 12
Source File: MetalworksFrame.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public MetalworksFrame() {
    super("Metalworks");
    final int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset
            * 2);
    buildContent();
    buildMenus();
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            quit();
        }
    });
    UIManager.addPropertyChangeListener(new UISwitchListener(
            (JComponent) getRootPane()));
}
 
Example 13
Source File: MetalworksFrame.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public MetalworksFrame() {
    super("Metalworks");
    final int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset
            * 2);
    buildContent();
    buildMenus();
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            quit();
        }
    });
    UIManager.addPropertyChangeListener(new UISwitchListener(
            (JComponent) getRootPane()));
}
 
Example 14
Source File: FileSystemView.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a FileSystemView.
 */
public FileSystemView() {
    final WeakReference<FileSystemView> weakReference = new WeakReference<>(this);
    final PropertyChangeListener pcl = evt -> {
        final FileSystemView fsv = weakReference.get();
        if (fsv != null && evt.getPropertyName().equals("lookAndFeel")) {
            fsv.useSystemExtensionHiding =
                    UIManager.getDefaults().getBoolean(
                            "FileChooser.useSystemExtensionHiding");
        }
    };

    UIManager.addPropertyChangeListener(pcl);
    CleanerFactory.cleaner().register(this, () -> {
        UIManager.removePropertyChangeListener(pcl);
    });
}
 
Example 15
Source File: IndependentWindow.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * constructor
 * 
 * @param title Window title
 * @param iconImage image to show when iconified
 */
public IndependentWindow(String title, Image iconImage) {
  super(title);

  // L&F may change
  UIManager.addPropertyChangeListener(new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent e) {
      if (e.getPropertyName().equals("lookAndFeel"))
        SwingUtilities.updateComponentTreeUI(IndependentWindow.this);
    }
  });

  if (null != iconImage)
    setIconImage(iconImage);
}
 
Example 16
Source File: UIScale.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
private static void initialize() {
	if( initialized )
		return;
	initialized = true;

	if( !isUserScalingEnabled() )
		return;

	// listener to update scale factor if LaF changed, "defaultFont" or "Label.font" changed
	PropertyChangeListener listener = new PropertyChangeListener() {
		@Override
		public void propertyChange( PropertyChangeEvent e ) {
			switch( e.getPropertyName() ) {
				case "lookAndFeel":
					// it is not necessary (and possible) to remove listener of old LaF defaults
					if( e.getNewValue() instanceof LookAndFeel )
						UIManager.getLookAndFeelDefaults().addPropertyChangeListener( this );
					updateScaleFactor();
					break;

				case "defaultFont":
				case "Label.font":
					updateScaleFactor();
					break;
			}
		}
	};
	UIManager.addPropertyChangeListener( listener );
	UIManager.getDefaults().addPropertyChangeListener( listener );
	UIManager.getLookAndFeelDefaults().addPropertyChangeListener( listener );

	updateScaleFactor();
}
 
Example 17
Source File: LookAndFeelsComboBox.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
@Override
public void addNotify() {
	super.addNotify();

	selectedCurrentLookAndFeel();
	UIManager.addPropertyChangeListener( lafListener );
}
 
Example 18
Source File: AnimationAutoCompletion.java    From 3Dscript with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Installs this auto-completion on a text component. If this
 * {@link AnimationAutoCompletion} is already installed on another text component,
 * it is uninstalled first.
 *
 * @param c The text component.
 * @see #uninstall()
 */
@Override
public void install(JTextComponent c) {

	if (textComponent != null) {
		uninstall();
	}

	this.textComponent = c;
	installTriggerKey(getTriggerKey());

	// Install the function completion key, if there is one.
	// NOTE: We cannot do this if the start char is ' ' (e.g. just a space
	// between the function name and parameters) because it overrides
	// RSTA's special space action. It seems KeyStorke.getKeyStroke(' ')
	// hoses ctrl+space, shift+space, etc., even though I think it
	// shouldn't...
	char start = provider.getParameterListStart();
	if (start != 0 && start != ' ') {
		InputMap im = c.getInputMap();
		ActionMap am = c.getActionMap();
		KeyStroke ks = KeyStroke.getKeyStroke(start);
		oldParenKey = im.get(ks);
		im.put(ks, PARAM_COMPLETE_KEY);
		oldParenAction = am.get(PARAM_COMPLETE_KEY);
		am.put(PARAM_COMPLETE_KEY, new ParameterizedCompletionStartAction(
				start));
	}

	textComponentListener.addTo(this.textComponent);
	// In case textComponent is already in a window...
	textComponentListener.hierarchyChanged(null);

	if (isAutoActivationEnabled()) {
		autoActivationListener.addTo(this.textComponent);
	}

	UIManager.addPropertyChangeListener(lafListener);
	updateUI(); // In case there have been changes since we uninstalled

}
 
Example 19
Source File: NimbusDefaults.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/** Called by UIManager when this look and feel is installed. */
void initialize() {
    // add listener for derived colors
    UIManager.addPropertyChangeListener(defaultsListener);
    UIManager.getDefaults().addPropertyChangeListener(colorTree);
}
 
Example 20
Source File: Microba.java    From microba with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Initializes the library: installs L&F properties, sets up a L&F change
 * listener.
 * <p>
 * No need to call this method explicitly for desktop applications. You
 * should only call it in {@link Applet#init()}. This will handle browser
 * refresh button correctly.
 * 
 */
public static synchronized void init() {
	setLookAndFeelProperties(UIManager.getLookAndFeel());

	UIManager.removePropertyChangeListener(changeListener);
	UIManager.addPropertyChangeListener(changeListener);
}