taoujouti / macwidgets

Automatically exported from code.google.com/p/macwidgets
0 stars 0 forks source link

JPasswordField #132

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice, when the createHudTextField can also produce
JPasswordField's.

Original issue reported on code.google.com by goo...@x2on.de on 12 Oct 2009 at 8:40

GoogleCodeExporter commented 9 years ago
HudWidgetFactory:

    public static JPasswordField createHudPasswordField(String text) {
        JPasswordField passwordField = new JPasswordField(text);
        passwordField.setUI(new HudPasswordFieldUI());
        return passwordField;
    }

HudPasswordFieldUI:

package com.explodingpixels.macwidgets.plaf;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicPasswordFieldUI;
import javax.swing.text.JTextComponent;
import java.awt.Color;

/**
 * Creates a Heads Up Display (HUD) style password field, similar to that seen in
various iApps (e.g.
 * iPhoto).
 * <br>
 * <img src="../../../../../graphics/HUDTextFieldUI.png">
 */
public class HudPasswordFieldUI extends BasicPasswordFieldUI {

    @Override
    public void installUI(JComponent c) {
        super.installUI(c);

        JTextComponent textComponent = (JTextComponent) c;

        textComponent.setOpaque(false);
        textComponent.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(HudPaintingUtils.BORDER_COLOR),
                BorderFactory.createEmptyBorder(1, 2, 1, 2)));
        textComponent.setBackground(new Color(0, 0, 0, 0));
        textComponent.setForeground(HudPaintingUtils.FONT_COLOR);
        textComponent.setFont(HudPaintingUtils.getHudFont());
        textComponent.setSelectedTextColor(Color.BLACK);
        textComponent.setSelectionColor(HudPaintingUtils.FONT_COLOR);
        textComponent.setCaretColor(HudPaintingUtils.FONT_COLOR);
    }
}

Then you can use a JPasswordField:
JPasswordField password = HudWidgetFactory.createHudPasswordField("password");

Original comment by goo...@x2on.de on 12 Oct 2009 at 9:05

GoogleCodeExporter commented 9 years ago

Original comment by kenneth....@gmail.com on 13 Oct 2009 at 5:28

GoogleCodeExporter commented 9 years ago
I added the suggested solution.

Original comment by dlemmermann@gmail.com on 16 Mar 2010 at 5:06