List of usage examples for javax.swing JPasswordField addActionListener
public synchronized void addActionListener(ActionListener l)
From source file:Main.java
public static JPasswordField createPasswordField(String text, int columns, ActionListener... listeners) { JPasswordField result = new JPasswordField(text, columns); for (ActionListener listener : listeners) { result.addActionListener(listener); }// w ww . ja va 2 s . c o m return result; }
From source file:components.TextSamplerDemo.java
public TextSamplerDemo() { setLayout(new BorderLayout()); //Create a regular text field. JTextField textField = new JTextField(10); textField.setActionCommand(textFieldString); textField.addActionListener(this); //Create a password field. JPasswordField passwordField = new JPasswordField(10); passwordField.setActionCommand(passwordFieldString); passwordField.addActionListener(this); //Create a formatted text field. JFormattedTextField ftf = new JFormattedTextField(java.util.Calendar.getInstance().getTime()); ftf.setActionCommand(textFieldString); ftf.addActionListener(this); //Create some labels for the fields. JLabel textFieldLabel = new JLabel(textFieldString + ": "); textFieldLabel.setLabelFor(textField); JLabel passwordFieldLabel = new JLabel(passwordFieldString + ": "); passwordFieldLabel.setLabelFor(passwordField); JLabel ftfLabel = new JLabel(ftfString + ": "); ftfLabel.setLabelFor(ftf);/*from www. j a v a2 s .c o m*/ //Create a label to put messages during an action event. actionLabel = new JLabel("Type text in a field and press Enter."); actionLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); //Lay out the text controls and the labels. JPanel textControlsPane = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); textControlsPane.setLayout(gridbag); JLabel[] labels = { textFieldLabel, passwordFieldLabel, ftfLabel }; JTextField[] textFields = { textField, passwordField, ftf }; addLabelTextRows(labels, textFields, gridbag, textControlsPane); c.gridwidth = GridBagConstraints.REMAINDER; //last c.anchor = GridBagConstraints.WEST; c.weightx = 1.0; textControlsPane.add(actionLabel, c); textControlsPane.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Text Fields"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); //Create a text area. JTextArea textArea = new JTextArea("This is an editable JTextArea. " + "A text area is a \"plain\" text component, " + "which means that although it can display text " + "in any font, all of the text is in the same font."); textArea.setFont(new Font("Serif", Font.ITALIC, 16)); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); JScrollPane areaScrollPane = new JScrollPane(textArea); areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); areaScrollPane.setPreferredSize(new Dimension(250, 250)); areaScrollPane.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Plain Text"), BorderFactory.createEmptyBorder(5, 5, 5, 5)), areaScrollPane.getBorder())); //Create an editor pane. JEditorPane editorPane = createEditorPane(); JScrollPane editorScrollPane = new JScrollPane(editorPane); editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setPreferredSize(new Dimension(250, 145)); editorScrollPane.setMinimumSize(new Dimension(10, 10)); //Create a text pane. JTextPane textPane = createTextPane(); JScrollPane paneScrollPane = new JScrollPane(textPane); paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); paneScrollPane.setPreferredSize(new Dimension(250, 155)); paneScrollPane.setMinimumSize(new Dimension(10, 10)); //Put the editor pane and the text pane in a split pane. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, editorScrollPane, paneScrollPane); splitPane.setOneTouchExpandable(true); splitPane.setResizeWeight(0.5); JPanel rightPane = new JPanel(new GridLayout(1, 0)); rightPane.add(splitPane); rightPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Styled Text"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); //Put everything together. JPanel leftPane = new JPanel(new BorderLayout()); leftPane.add(textControlsPane, BorderLayout.PAGE_START); leftPane.add(areaScrollPane, BorderLayout.CENTER); add(leftPane, BorderLayout.LINE_START); add(rightPane, BorderLayout.LINE_END); }
From source file:TextSamplerDemo.java
public TextSamplerDemo() { setLayout(new BorderLayout()); //Create a regular text field. JTextField textField = new JTextField(10); textField.setActionCommand(textFieldString); textField.addActionListener(this); //Create a password field. JPasswordField passwordField = new JPasswordField(10); passwordField.setActionCommand(passwordFieldString); passwordField.addActionListener(this); //Create a formatted text field. JFormattedTextField ftf = new JFormattedTextField(java.util.Calendar.getInstance().getTime()); ftf.setActionCommand(textFieldString); ftf.addActionListener(this); //Create some labels for the fields. JLabel textFieldLabel = new JLabel(textFieldString + ": "); textFieldLabel.setLabelFor(textField); JLabel passwordFieldLabel = new JLabel(passwordFieldString + ": "); passwordFieldLabel.setLabelFor(passwordField); JLabel ftfLabel = new JLabel(ftfString + ": "); ftfLabel.setLabelFor(ftf);//from ww w . j av a 2 s .c o m //Create a label to put messages during an action event. actionLabel = new JLabel("Type text and then Enter in a field."); actionLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); //Lay out the text controls and the labels. JPanel textControlsPane = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); textControlsPane.setLayout(gridbag); JLabel[] labels = { textFieldLabel, passwordFieldLabel, ftfLabel }; JTextField[] textFields = { textField, passwordField, ftf }; addLabelTextRows(labels, textFields, gridbag, textControlsPane); c.gridwidth = GridBagConstraints.REMAINDER; //last c.anchor = GridBagConstraints.WEST; c.weightx = 1.0; textControlsPane.add(actionLabel, c); textControlsPane.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Text Fields"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); //Create a text area. JTextArea textArea = new JTextArea("This is an editable JTextArea. " + "A text area is a \"plain\" text component, " + "which means that although it can display text " + "in any font, all of the text is in the same font."); textArea.setFont(new Font("Serif", Font.ITALIC, 16)); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); JScrollPane areaScrollPane = new JScrollPane(textArea); areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); areaScrollPane.setPreferredSize(new Dimension(250, 250)); areaScrollPane.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Plain Text"), BorderFactory.createEmptyBorder(5, 5, 5, 5)), areaScrollPane.getBorder())); //Create an editor pane. JEditorPane editorPane = createEditorPane(); JScrollPane editorScrollPane = new JScrollPane(editorPane); editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setPreferredSize(new Dimension(250, 145)); editorScrollPane.setMinimumSize(new Dimension(10, 10)); //Create a text pane. JTextPane textPane = createTextPane(); JScrollPane paneScrollPane = new JScrollPane(textPane); paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); paneScrollPane.setPreferredSize(new Dimension(250, 155)); paneScrollPane.setMinimumSize(new Dimension(10, 10)); //Put the editor pane and the text pane in a split pane. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, editorScrollPane, paneScrollPane); splitPane.setOneTouchExpandable(true); splitPane.setResizeWeight(0.5); JPanel rightPane = new JPanel(new GridLayout(1, 0)); rightPane.add(splitPane); rightPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Styled Text"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); //Put everything together. JPanel leftPane = new JPanel(new BorderLayout()); leftPane.add(textControlsPane, BorderLayout.PAGE_START); leftPane.add(areaScrollPane, BorderLayout.CENTER); add(leftPane, BorderLayout.LINE_START); add(rightPane, BorderLayout.LINE_END); }
From source file:com.hp.alm.ali.idea.content.settings.SettingsPanel.java
public SettingsPanel(final Project prj, Color bgColor) { this.prj = prj; this.projectConf = prj.getComponent(AliProjectConfiguration.class); previewAndConnection = new JPanel(new GridBagLayout()); previewAndConnection.setOpaque(false); GridBagConstraints c2 = new GridBagConstraints(); c2.gridx = 0;/*from w ww . j a v a 2 s .c o m*/ c2.gridy = 1; c2.gridwidth = 2; c2.weighty = 1; c2.fill = GridBagConstraints.VERTICAL; JPanel filler = new JPanel(); filler.setOpaque(false); previewAndConnection.add(filler, c2); passwordPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); passwordPanel.setBackground(bgColor); JLabel label = new JLabel("Password"); label.setFont(label.getFont().deriveFont(Font.BOLD)); passwordPanel.add(label); final JPasswordField password = new JPasswordField(24); passwordPanel.add(password); JButton connect = new JButton("Login"); passwordPanel.add(connect); final JLabel message = new JLabel(); passwordPanel.add(message); ActionListener connectionAction = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { try { checkConnection(projectConf.getLocation(), projectConf.getDomain(), projectConf.getProject(), projectConf.getUsername(), password.getText()); } catch (AuthenticationFailed e) { message.setText(e.getMessage()); return; } projectConf.ALM_PASSWORD = password.getText(); projectConf.fireChanged(); } }; password.addActionListener(connectionAction); connect.addActionListener(connectionAction); restService = prj.getComponent(RestService.class); restService.addServerTypeListener(this); location = createTextPane(bgColor); domain = createTextPane(bgColor); project = createTextPane(bgColor); username = createTextPane(bgColor); final JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(bgColor); panel.setBorder(new EmptyBorder(10, 10, 10, 10)); final JTextPane textPane = new JTextPane(); textPane.setEditorKit(new HTMLEditorKit()); textPane.setText( "<html><body>HP ALM integration can be configured on <a href=\"ide\">IDE</a> and overridden on <a href=\"project\">project</a> level.</body></html>"); textPane.setEditable(false); textPane.addHyperlinkListener(this); textPane.setBackground(bgColor); textPane.setCaret(new NonAdjustingCaret()); panel.add(textPane, BorderLayout.CENTER); JPanel content = new JPanel(new BorderLayout()); content.setBackground(bgColor); content.add(panel, BorderLayout.NORTH); content.add(previewAndConnection, BorderLayout.WEST); preview = new JPanel(new GridBagLayout()) { public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); // make enough room for the connection status message dim.width = Math.max(dim.width, 300); return dim; } public Dimension getMinimumSize() { return getPreferredSize(); } }; connectedTo(restService.getServerTypeIfAvailable()); preview.setBackground(bgColor); final GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; preview.add(location, c); c.gridwidth = 1; c.gridy++; preview.add(domain, c); c.gridy++; preview.add(project, c); c.gridy++; preview.add(username, c); c.gridx++; c.gridy--; c.gridheight = 2; c.weightx = 0; c.anchor = GridBagConstraints.SOUTHEAST; final LinkLabel reload = new LinkLabel("Reload", IconLoader.getIcon("/actions/sync.png")); reload.setListener(new LinkListener() { public void linkSelected(LinkLabel linkLabel, Object o) { projectConf.fireChanged(); } }, null); preview.add(reload, c); JPanel previewNorth = new JPanel(new BorderLayout()); previewNorth.setBackground(bgColor); previewNorth.add(preview, BorderLayout.NORTH); addToGridBagPanel(0, 0, previewAndConnection, previewNorth); setBackground(bgColor); setLayout(new BorderLayout()); add(content, BorderLayout.CENTER); onChanged(); ApplicationManager.getApplication().getComponent(AliConfiguration.class).addListener(this); projectConf.addListener(this); }