當前位置: 首頁>>代碼示例>>Java>>正文


Java JPasswordField類代碼示例

本文整理匯總了Java中javax.swing.JPasswordField的典型用法代碼示例。如果您正苦於以下問題:Java JPasswordField類的具體用法?Java JPasswordField怎麽用?Java JPasswordField使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JPasswordField類屬於javax.swing包,在下文中一共展示了JPasswordField類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCellEditor

import javax.swing.JPasswordField; //導入依賴的package包/類
@Override
public TableCellEditor getCellEditor(int row, int column) {
    if(showParamTypes) {
        String paramName = (String) tableModel.getValueAt(row, 0);
        Class type = (column == 2) ? (Class) tableModel.getValueAt(row, 1) : Boolean.class;

        if (Enum.class.isAssignableFrom(type)) {
            JComboBox combo = new JComboBox(type.getEnumConstants());
            return new DefaultCellEditor(combo);
        } else if (type == Boolean.class || type == Boolean.TYPE) {
            JCheckBox cb = new JCheckBox();
            cb.setHorizontalAlignment(JLabel.CENTER);
            cb.setBorderPainted(true);
            return new DefaultCellEditor(cb);
        } else if (paramName.toLowerCase().contains(Constants.PASSWORD)) {
            return new DefaultCellEditor(new JPasswordField());
        }
    }

    return super.getCellEditor(row, column);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:CodeSetupPanel.java

示例2: getTableCellRendererComponent

import javax.swing.JPasswordField; //導入依賴的package包/類
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, 
        boolean hasFocus, int row, int column) {
    Component ret = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    String paramName = (String) tableModel.getValueAt(row, 0);

    if (value == null) {
        return new JLabel(NbBundle.getMessage(CodeSetupPanel.class, "LBL_NotSet"));
    } else if (value instanceof Class) {
        return new JLabel(((Class) value).getName());
    } else if (value instanceof Boolean) {
        JCheckBox cb = new JCheckBox();
        cb.setHorizontalAlignment(JLabel.CENTER);
        cb.setBorderPainted(true);
        cb.setSelected((Boolean) value);
        return cb;
    } else if (paramName.contains(Constants.PASSWORD)) {
        return new JPasswordField((String) value);
    } 
    return ret;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:CodeSetupPanel.java

示例3: showMasterPasswordEntry

import javax.swing.JPasswordField; //導入依賴的package包/類
/**
 * Show master password dialog if enabled
 */
private void showMasterPasswordEntry() {
	ConfigIO cfg = ConfigIO.getInstance();
	if (cfg.isMasterPwdEnabled()) {
		JPanel panel = new JPanel(new BorderLayout());
		JPasswordField pf = new JPasswordField();
		panel.setBorder(new EmptyBorder(0, 10, 0, 10));
		panel.add(pf, BorderLayout.NORTH);
		JFrame frame = new JFrame();
		frame.setAlwaysOnTop(true);

		int option = JOptionPane.showConfirmDialog(frame, panel, I18n.get("main.start.requestmasterpwd"),
				JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
		frame.dispose();
		if (option == JOptionPane.OK_OPTION) {
			cfg.setMasterPassword(new String(pf.getPassword()));
		} else {
			// TODO show config dialog
		}
	}
}
 
開發者ID:michaelnetter,項目名稱:dracoon-dropzone,代碼行數:24,代碼來源:Dropzone.java

示例4: showPasswordDialog

import javax.swing.JPasswordField; //導入依賴的package包/類
/**
 * Show password dialog if enabled
 */
private String showPasswordDialog() {
	JPanel panel = new JPanel(new BorderLayout());
	JPasswordField pf = new JPasswordField();
	panel.setBorder(new EmptyBorder(0, 10, 0, 10));
	panel.add(pf, BorderLayout.NORTH);
	JFrame frame = new JFrame();
	frame.setAlwaysOnTop(true);
	pf.requestFocus();

	int option = JOptionPane.showConfirmDialog(frame, panel, I18n.get("main.start.sharelinkpwd"),
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
	frame.dispose();
	if (option == JOptionPane.OK_OPTION) {
		return new String(pf.getPassword());
	} else {
		return null;
	}
}
 
開發者ID:michaelnetter,項目名稱:dracoon-dropzone,代碼行數:22,代碼來源:Dropzone.java

示例5: UserCredentialsPanel

import javax.swing.JPasswordField; //導入依賴的package包/類
public UserCredentialsPanel(){
	setSize(new Dimension(900, 300));
	setPreferredSize(new Dimension(900, 300));
	setMinimumSize(new Dimension(450, 300));
	setLayout(null);
	
	JLabel lblUsername = new JLabel("Username");
	lblUsername.setBounds(12, 12, 86, 15);
	add(lblUsername);
	
	JLabel lblPassword = new JLabel("Password");
	lblPassword.setBounds(12, 49, 70, 15);
	add(lblPassword);
	
	usernameField = new JTextField();
	usernameField.setBounds(116, 10, 114, 19);
	add(usernameField);
	usernameField.setColumns(10);
	
	passwordField = new JPasswordField();
	passwordField.setBounds(116, 47, 114, 19);
	add(passwordField);
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:24,代碼來源:UserCredentialsPanel.java

示例6: initGUI

import javax.swing.JPasswordField; //導入依賴的package包/類
@Override
public void initGUI()
{
	userField = new JTextField();
	passField = new JPasswordField();

	liveOnly = new JCheckBox();
	harvestLearningObjects = new JCheckBox();
	harvestResources = new JCheckBox();

	panel.addComponent(new JLabel(getString(getPluginsFieldString())));
	panel.addNameAndComponent(getString("detailstab.user"), userField);
	panel.addNameAndComponent(getString("detailstab.pass"), passField);

	panel.addNameAndComponent(getString("loraxplugin.live"), liveOnly);
	panel.addNameAndComponent(getString("loraxplugin.harvestlo"),
		harvestLearningObjects);
	panel.addNameAndComponent(getString("loraxplugin.harvestre"),
		harvestResources);

}
 
開發者ID:equella,項目名稱:Equella,代碼行數:22,代碼來源:AbstractTLFPlugin.java

示例7: PasswordEncryptionDialog

import javax.swing.JPasswordField; //導入依賴的package包/類
public PasswordEncryptionDialog(JFrame parent)
{
	super(parent);

	this.upperLabel.setText(
		"<html>The wallet.dat file will be encrypted with a password. If the operation is successful, " +
           "zend will automatically stop and will need to be restarted. The GUI wallet will also be stopped " +
           "and will need to be restarted. Please enter the password:</html>");
	
	JLabel confLabel = new JLabel("Confirmation: ");
	this.freeSlotPanel.add(confLabel);
	this.freeSlotPanel.add(passwordConfirmationField = new JPasswordField(30));
	this.passwordLabel.setPreferredSize(confLabel.getPreferredSize());
	
	JLabel dividerLabel = new JLabel("   ");
	dividerLabel.setFont(new Font("Helvetica", Font.PLAIN, 8));
	this.freeSlotPanel2.add(dividerLabel);
	
	this.setSize(460, 270);
	this.validate();
	this.repaint();
}
 
開發者ID:ZencashOfficial,項目名稱:zencash-swing-wallet-ui,代碼行數:23,代碼來源:PasswordEncryptionDialog.java

示例8: PasswordEncryptionDialog

import javax.swing.JPasswordField; //導入依賴的package包/類
public PasswordEncryptionDialog(JFrame parent)
{
	super(parent);

	this.upperLabel.setText(
		"<html>The wallet.dat file will be encrypted with a password. If the operation is successful, " +
           "zcashd will automatically stop and will need to be restarted. The GUI wallet will also be stopped " +
           "and will need to be restarted. Please enter the password:</html>");
	
	JLabel confLabel = new JLabel("Confirmation: ");
	this.freeSlotPanel.add(confLabel);
	this.freeSlotPanel.add(passwordConfirmationField = new JPasswordField(30));
	this.passwordLabel.setPreferredSize(confLabel.getPreferredSize());
	
	JLabel dividerLabel = new JLabel("   ");
	dividerLabel.setFont(new Font("Helvetica", Font.PLAIN, 8));
	this.freeSlotPanel2.add(dividerLabel);
	
	this.setSize(460, 270);
	this.validate();
	this.repaint();
}
 
開發者ID:ca333,項目名稱:komodoGUI,代碼行數:23,代碼來源:PasswordEncryptionDialog.java

示例9: CredentialsPanel

import javax.swing.JPasswordField; //導入依賴的package包/類
private CredentialsPanel(String username, String url) {
    this.url = url;
    this.usernamePassword = new JRadioButton("Username and password");
    this.usernamePassword.addActionListener(new RadioButtonListener());
    this.anonymous = new JRadioButton("Anonymous access");
    this.anonymous.addActionListener(new RadioButtonListener());
    this.buttonGroup = new ButtonGroup();
    this.buttonGroup.add(usernamePassword);
    this.buttonGroup.add(anonymous);
    this.usernameLabel = new JLabel("Username:");
    this.username = new JTextField(Objects.toString(username, ""), 20);
    this.passwordLabel = new JLabel("Password:");
    this.password = new JPasswordField(20);
    if (username == null || username.isEmpty()) {
        this.anonymous.setSelected(true);
    } else {
        this.usernamePassword.setSelected(true);
        this.password.addAncestorListener(new RequestFocusListener());
    }
    radioButtonToggled();
    layoutComponents();
}
 
開發者ID:pascalgn,項目名稱:jiracli,代碼行數:23,代碼來源:CredentialsPanel.java

示例10: drawUnselectedText

import javax.swing.JPasswordField; //導入依賴的package包/類
/**
 * Renders the given range in the model as normal unselected
 * text.  This sets the foreground color and echos the characters
 * using the value returned by getEchoChar().
 *
 * @param g the graphics context
 * @param x the starting X coordinate &gt;= 0
 * @param y the starting Y coordinate &gt;= 0
 * @param p0 the starting offset in the model &gt;= 0
 * @param p1 the ending offset in the model &gt;= p0
 * @return the X location of the end of the range &gt;= 0
 * @exception BadLocationException if p0 or p1 are out of range
 */
protected int drawUnselectedText(Graphics g, int x, int y,
                                 int p0, int p1) throws BadLocationException {

    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.drawUnselectedText(g, x, y, p0, p1);
        }
        if (f.isEnabled()) {
            g.setColor(f.getForeground());
        }
        else {
            g.setColor(f.getDisabledTextColor());
        }
        char echoChar = f.getEchoChar();
        int n = p1 - p0;
        for (int i = 0; i < n; i++) {
            x = drawEchoCharacter(g, x, y, echoChar);
        }
    }
    return x;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:37,代碼來源:PasswordView.java

示例11: drawSelectedText

import javax.swing.JPasswordField; //導入依賴的package包/類
/**
 * Renders the given range in the model as selected text.  This
 * is implemented to render the text in the color specified in
 * the hosting component.  It assumes the highlighter will render
 * the selected background.  Uses the result of getEchoChar() to
 * display the characters.
 *
 * @param g the graphics context
 * @param x the starting X coordinate &gt;= 0
 * @param y the starting Y coordinate &gt;= 0
 * @param p0 the starting offset in the model &gt;= 0
 * @param p1 the ending offset in the model &gt;= p0
 * @return the X location of the end of the range &gt;= 0
 * @exception BadLocationException if p0 or p1 are out of range
 */
protected int drawSelectedText(Graphics g, int x,
                               int y, int p0, int p1) throws BadLocationException {
    g.setColor(selected);
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.drawSelectedText(g, x, y, p0, p1);
        }
        char echoChar = f.getEchoChar();
        int n = p1 - p0;
        for (int i = 0; i < n; i++) {
            x = drawEchoCharacter(g, x, y, echoChar);
        }
    }
    return x;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:33,代碼來源:PasswordView.java

示例12: modelToView

import javax.swing.JPasswordField; //導入依賴的package包/類
/**
 * Provides a mapping from the document model coordinate space
 * to the coordinate space of the view mapped to it.
 *
 * @param pos the position to convert &gt;= 0
 * @param a the allocated region to render into
 * @return the bounding box of the given position
 * @exception BadLocationException  if the given position does not
 *   represent a valid location in the associated document
 * @see View#modelToView
 */
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.modelToView(pos, a, b);
        }
        char echoChar = f.getEchoChar();
        FontMetrics m = f.getFontMetrics(f.getFont());

        Rectangle alloc = adjustAllocation(a).getBounds();
        int dx = (pos - getStartOffset()) * m.charWidth(echoChar);
        alloc.x += dx;
        alloc.width = 1;
        return alloc;
    }
    return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:30,代碼來源:PasswordView.java

示例13: viewToModel

import javax.swing.JPasswordField; //導入依賴的package包/類
/**
 * Provides a mapping from the view coordinate space to the logical
 * coordinate space of the model.
 *
 * @param fx the X coordinate &gt;= 0.0f
 * @param fy the Y coordinate &gt;= 0.0f
 * @param a the allocated region to render into
 * @return the location within the model that best represents the
 *  given point in the view
 * @see View#viewToModel
 */
public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {
    bias[0] = Position.Bias.Forward;
    int n = 0;
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.viewToModel(fx, fy, a, bias);
        }
        char echoChar = f.getEchoChar();
        int charWidth = f.getFontMetrics(f.getFont()).charWidth(echoChar);
        a = adjustAllocation(a);
        Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
                          a.getBounds();
        n = (charWidth > 0 ?
             ((int)fx - alloc.x) / charWidth : Integer.MAX_VALUE);
        if (n < 0) {
            n = 0;
        }
        else if (n > (getStartOffset() + getDocument().getLength())) {
            n = getDocument().getLength() - getStartOffset();
        }
    }
    return getStartOffset() + n;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:37,代碼來源:PasswordView.java

示例14: run

import javax.swing.JPasswordField; //導入依賴的package包/類
public static String run() {	// SOURCE: https://goo.gl/5pFXao
	JPanel panel = new JPanel();
	JLabel label = new JLabel("This server is protected with a password.");
	JPasswordField pass = new JPasswordField(10);
	panel.add(label);
	panel.add(pass);
	String[] options = new String[]{"OK", "Cancel"};
	int option = JOptionPane.showOptionDialog(null, panel, "Enter password",
			JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
			null, options, options[0]);
	if(option == 0) { // OK button
		char[] password = pass.getPassword();
		return new String(password);
	} else {
		return null;
	}
}
 
開發者ID:jlxip,項目名稱:LANClipboard,代碼行數:18,代碼來源:EnterPassword.java

示例15: getPreferredSpan

import javax.swing.JPasswordField; //導入依賴的package包/類
/**
 * Determines the preferred span for this view along an
 * axis.
 *
 * @param axis may be either View.X_AXIS or View.Y_AXIS
 * @return   the span the view would like to be rendered into &gt;= 0.
 *           Typically the view is told to render into the span
 *           that is returned, although there is no guarantee.
 *           The parent may choose to resize or break the view.
 */
public float getPreferredSpan(int axis) {
    switch (axis) {
    case View.X_AXIS:
        Container c = getContainer();
        if (c instanceof JPasswordField) {
            JPasswordField f = (JPasswordField) c;
            if (f.echoCharIsSet()) {
                char echoChar = f.getEchoChar();
                FontMetrics m = f.getFontMetrics(f.getFont());
                Document doc = getDocument();
                return m.charWidth(echoChar) * getDocument().getLength();
            }
        }
    }
    return super.getPreferredSpan(axis);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:27,代碼來源:PasswordView.java


注:本文中的javax.swing.JPasswordField類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。