Example usage for javax.swing JTextField setVisible

List of usage examples for javax.swing JTextField setVisible

Introduction

In this page you can find the example usage for javax.swing JTextField setVisible.

Prototype

@BeanProperty(hidden = true, visualUpdate = true)
public void setVisible(boolean aFlag) 

Source Link

Document

Makes the component visible or invisible.

Usage

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

protected void changeMaxFileSize() {
    final JPanel panel = new JPanel();
    boolean keineLimitierung = iliasProperties.getMaxFileSize() == Long.MAX_VALUE;

    panel.setLayout(new GridLayout(1, 0));

    panel.add(new JLabel("Maximale Dateigre in MB"));

    final JCheckBox cb = new JCheckBox("Keine Limitierung");
    cb.setSelected(keineLimitierung);//from  www.  ja  v a2  s .  c o  m
    panel.add(cb);

    final JTextField fieldFileSize = new JTextField(
            String.valueOf(iliasProperties.getMaxFileSize() / (1024 * 1024)));
    panel.add(fieldFileSize);

    fieldFileSize.setVisible(!cb.isSelected());

    cb.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            fieldFileSize.setVisible(!cb.isSelected());

        }
    });

    if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(mainFrame, panel,
            "Maximale Dateigre ndern", JOptionPane.OK_CANCEL_OPTION)) {

        if (cb.isSelected()) {
            iliasProperties.setMaxFileSize(Long.MAX_VALUE);
        } else {
            iliasProperties.setMaxFileSize(Long.parseLong(fieldFileSize.getText()) * 1024 * 1024);
        }
        saveProperties(iliasProperties);
    }

}

From source file:edu.ku.brc.specify.plugins.ipadexporter.ManageDataSetsDlg.java

/**
 * //from  w  w  w . j a  va2  s.  c  o  m
 */
private void addUserToDS() {
    final Vector<String> wsList = new Vector<String>();
    final Vector<String> instItems = new Vector<String>();

    String addStr = getResourceString("ADD");
    instItems.add(addStr);
    wsList.add(addStr);
    for (String fullName : cloudHelper.getInstList()) {
        String[] toks = StringUtils.split(fullName, '\t');
        instItems.add(toks[0]);
        wsList.add(toks[1]);
    }

    final JTextField userNameTF = createTextField(20);
    final JTextField passwordTF = createTextField(20);
    final JLabel pwdLbl = createI18NFormLabel("Password");
    final JLabel statusLbl = createLabel("");
    final JCheckBox isNewUser = UIHelper.createCheckBox("Is New User");
    final JLabel instLbl = createI18NFormLabel("Insitution");
    final JComboBox instCmbx = UIHelper.createComboBox(instItems.toArray());

    if (instItems.size() == 2) {
        instCmbx.setSelectedIndex(1);
    }

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,4px,p,4px,p,4px,p,4px,p,8px,p"));

    pb.add(createI18NLabel("Add New or Existing User to DataSet"), cc.xyw(1, 1, 3));
    pb.add(createI18NFormLabel("Username"), cc.xy(1, 3));
    pb.add(userNameTF, cc.xy(3, 3));
    pb.add(pwdLbl, cc.xy(1, 5));
    pb.add(passwordTF, cc.xy(3, 5));
    pb.add(instLbl, cc.xy(1, 7));
    pb.add(instCmbx, cc.xy(3, 7));

    pb.add(isNewUser, cc.xy(3, 9));

    pb.add(statusLbl, cc.xyw(1, 11, 3));
    pb.setDefaultDialogBorder();

    pwdLbl.setVisible(false);
    passwordTF.setVisible(false);
    instLbl.setVisible(false);
    instCmbx.setVisible(false);

    final CustomDialog dlg = new CustomDialog(this, "Add User", true, OKCANCEL, pb.getPanel()) {
        @Override
        protected void okButtonPressed() {
            String usrName = userNameTF.getText();
            if (cloudHelper.isUserNameOK(usrName)) {
                String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex());
                if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) {
                    super.okButtonPressed();
                } else {
                    iPadDBExporterPlugin.setErrorMsg(statusLbl,
                            String.format("Unable to add usr: %s to the DataSet guid: %s", usrName, collGuid));
                }
            } else if (isNewUser.isSelected()) {
                String pwdStr = passwordTF.getText();
                String guid = null;
                if (instCmbx.getSelectedIndex() == 0) {
                    //                        InstDlg instDlg = new InstDlg(cloudHelper);
                    //                        if (!instDlg.isInstOK())
                    //                        {
                    //                            instDlg.createUI();
                    //                            instDlg.pack();
                    //                            centerAndShow(instDlg, 600, null);
                    //                            if (instDlg.isCancelled())
                    //                            {
                    //                                return;
                    //                            }
                    //                            //guid = instDlg.getGuid()();
                    //                        }
                } else {
                    //webSite = wsList.get(instCmbx.getSelectedIndex());

                }

                if (guid != null) {
                    String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex());
                    if (cloudHelper.addNewUser(usrName, pwdStr, guid)) {
                        if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) {
                            ManageDataSetsDlg.this.loadUsersForDataSetsIntoJList();
                            super.okButtonPressed();
                        } else {
                            iPadDBExporterPlugin.setErrorMsg(statusLbl,
                                    String.format("Unable to add%s to the DataSet %s", usrName, collGuid));
                        }
                    } else {
                        iPadDBExporterPlugin.setErrorMsg(statusLbl,
                                String.format("Unable to add%s to the DataSet %s", usrName, collGuid));
                    }
                } else {
                    // error
                }
            } else {
                iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("'%s' doesn't exist.", usrName));
            }
        }
    };

    KeyAdapter ka = new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            statusLbl.setText("");
            String usrNmStr = userNameTF.getText();
            boolean hasData = StringUtils.isNotEmpty(usrNmStr)
                    && (!isNewUser.isSelected() || StringUtils.isNotEmpty(passwordTF.getText()))
                    && UIHelper.isValidEmailAddress(usrNmStr);
            dlg.getOkBtn().setEnabled(hasData);
        }

    };
    userNameTF.addKeyListener(ka);
    passwordTF.addKeyListener(ka);

    final Color textColor = userNameTF.getForeground();

    FocusAdapter fa = new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            JTextField tf = (JTextField) e.getSource();
            if (!tf.getForeground().equals(textColor)) {
                tf.setText("");
                tf.setForeground(textColor);
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
            JTextField tf = (JTextField) e.getSource();
            if (tf.getText().length() == 0) {
                tf.setText("Enter email address");
                tf.setForeground(Color.LIGHT_GRAY);
            }
        }
    };
    userNameTF.addFocusListener(fa);

    userNameTF.setText("Enter email address");
    userNameTF.setForeground(Color.LIGHT_GRAY);

    isNewUser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean isSel = isNewUser.isSelected();
            pwdLbl.setVisible(isSel);
            passwordTF.setVisible(isSel);
            instLbl.setVisible(isSel);
            instCmbx.setVisible(isSel);

            Dimension s = dlg.getSize();
            int hgt = isNewUser.getSize().height + 4 + instCmbx.getSize().height;
            s.height += isSel ? hgt : -hgt;
            dlg.setSize(s);
        }
    });

    dlg.createUI();
    dlg.getOkBtn().setEnabled(false);

    centerAndShow(dlg);
    if (!dlg.isCancelled()) {
        loadUsersForDataSetsIntoJList();
    }
}