本文整理汇总了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);
}
示例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;
}
示例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
}
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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 >= 0
* @param y the starting Y coordinate >= 0
* @param p0 the starting offset in the model >= 0
* @param p1 the ending offset in the model >= p0
* @return the X location of the end of the range >= 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;
}
示例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 >= 0
* @param y the starting Y coordinate >= 0
* @param p0 the starting offset in the model >= 0
* @param p1 the ending offset in the model >= p0
* @return the X location of the end of the range >= 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;
}
示例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 >= 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;
}
示例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 >= 0.0f
* @param fy the Y coordinate >= 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;
}
示例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;
}
}
示例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 >= 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);
}