コード例 #1
0
  /**
   * This method gets called when a bound property is changed on the associated JTextComponent. This
   * is a hook which UI implementations may change to reflect how the UI displays bound properties
   * of JTextComponent subclasses. If the font, foreground or document has changed, the the
   * appropriate property is set in the default style of the document.
   *
   * @param evt the property change event
   */
  @Override
  protected void propertyChange(PropertyChangeEvent evt) {
    super.propertyChange(evt);

    String name = evt.getPropertyName();

    if (name.equals("foreground")) {
      updateForeground((Color) evt.getNewValue());
    } else if (name.equals("font")) {
      updateFont((Font) evt.getNewValue());
    } else if (name.equals("document")) {
      JComponent comp = getComponent();
      updateForeground(comp.getForeground());
      updateFont(comp.getFont());
    }
  }
コード例 #2
0
 /**
  * Installs the UI for a component. This does the following things.
  *
  * <ol>
  *   <li>Sets opaqueness of the associated component according to its style, if the opaque
  *       property has not already been set by the client program.
  *   <li>Installs the default caret and highlighter into the associated component. These
  *       properties are only set if their current value is either {@code null} or an instance of
  *       {@link UIResource}.
  *   <li>Attaches to the editor and model. If there is no model, a default one is created.
  *   <li>Creates the view factory and the view hierarchy used to represent the model.
  * </ol>
  *
  * @param c the editor component
  * @see javax.swing.plaf.basic.BasicTextUI#installUI
  * @see ComponentUI#installUI
  */
 @Override
 public void installUI(JComponent c) {
   super.installUI(c);
   updateForeground(c.getForeground());
   updateFont(c.getFont());
 }