Example usage for javax.swing JTextField setText

List of usage examples for javax.swing JTextField setText

Introduction

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

Prototype

@BeanProperty(bound = false, description = "the text of this component")
public void setText(String t) 

Source Link

Document

Sets the text of this TextComponent to the specified text.

Usage

From source file:pipeline.parameter_cell_views.FloatRangeSlider.java

/**
 * Updates a text field displaying a number
 * /* w w w  .ja  v a 2 s.  co  m*/
 * @param f
 *            JTextField displaying the number
 * @param v
 *            Number to format and display
 */
private void updateTextValue(JTextField f, float v) {
    f.setText("" + nf.format(v));
}

From source file:edu.ku.brc.specify.datamodel.busrules.AgentBusRules.java

@Override
public void afterFillForm(final Object dataObjArg) {
    Object dataObj = dataObjArg;/*from  ww  w .  j  a  v  a  2s .  c  o  m*/
    if (!(viewable instanceof FormViewObj) || !(dataObj instanceof Agent)) {
        if (dataObj == null) {
            Component agentVarSubView = formViewObj.getCompById("10");
            if (agentVarSubView != null) {
                agentVarSubView.setVisible(false);
            }

            Component groupPersonSubForm = formViewObj.getCompById("31");
            if (groupPersonSubForm != null) {
                groupPersonSubForm.setVisible(false);
            }

            Component addrSubView = formViewObj.getCompById("9");
            if (addrSubView != null) {
                addrSubView.setVisible(false);
            }
        }
        return;
    }

    Agent agent = (Agent) dataObj;
    Byte agentType = agent.getAgentType();

    fixUpFormForAgentType(agent, true);

    if (typeComp instanceof ValComboBox) {
        ValComboBox typeCBX = (ValComboBox) typeComp;
        if (typeCBX != null) {
            ignoreSet = true;
            typeCBX.getComboBox().setSelectedIndex(agentType == null ? Agent.PERSON : agentType);
            ignoreSet = false;
            fixUpTypeCBX(typeCBX.getComboBox());
        }

    } else {
        JTextField typeTxt = (JTextField) typeComp;
        if (typeTxt != null) {
            typeTxt.setText(typeTitles[agentType]);
        }
    }

    boolean shouldBeVisible = agentType == Agent.PERSON || agentType == Agent.ORG;
    final Component addrSubView = formViewObj.getCompById("9");
    if (addrSubView != null) {
        boolean isVisible = addrSubView.isVisible();
        if (!isVisible != shouldBeVisible) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    Component topComp = UIHelper.getWindow(addrSubView);
                    Component topMost = UIRegistry.getTopWindow();
                    if (topComp != topMost && topComp != null) {
                        ((Window) topComp).pack();
                    }
                }
            });
        }
        addrSubView.setVisible(shouldBeVisible);
    }
}

From source file:edu.ku.brc.specify.plugins.PartialDateUI.java

public void reset() {
    for (UIValidatable uiv : uivs) {
        uiv.reset();//from  w  ww. j a  v  a 2 s.co  m
    }
    isChanged = false;
    isDateChanged = false;
    dataObj = null;

    formatSelector.setSelectedIndex(0); // None is zero, Full is 1

    for (JTextField tf : textFields) {
        if (tf != null) {
            tf.setText("");
        }
    }

}

From source file:king.flow.action.DefaultMsgSendAction.java

private void showOnComponent(Object metaNode, TLSResult result) {
    Component meta = (Component) metaNode;
    getLogger(CommunicationWorker.class.getName()).log(Level.INFO, "Display component[{0}] type : {1}",
            new Object[] { String.valueOf(meta.getId()), meta.getType().value() });
    JsonParser jsonParser;//from w w  w .  j  ava 2 s .c o m
    JsonArray arrays;
    switch (meta.getType()) {
    case TABLE:
        try {
            jsonParser = new JsonParser();
            arrays = jsonParser.parse(result.getOkMsg()).asArray();
            JTable table = getBlock(meta.getId(), JTable.class);
            DefaultTableModel model = (DefaultTableModel) table.getModel();
            model.setRowCount(0);
            for (Iterator it = arrays.iterator(); it.hasNext();) {
                JsonArray row = (JsonArray) it.next();
                Vector<String> rowData = new Vector<>();
                for (Object v : row) {
                    rowData.add(v.toString());
                }
                model.addRow(rowData);
            }
        } catch (Exception e) {
            getLogger(CommunicationWorker.class.getName()).log(Level.WARNING,
                    "Invalid array data [ {0} ] for TABLE component[{1}], \n exception is {2}",
                    new Object[] { result.getOkMsg(), String.valueOf(meta.getId()), e });
        }
        break;
    case ADVANCED_TABLE:
        try {
            jsonParser = new JsonParser();
            JsonObject jsonObj = jsonParser.parse(result.getOkMsg()).asObject();
            Integer total = jsonObj.getInt(ADVANCED_TABLE_TOTAL_PAGES);
            Integer page = jsonObj.getInt(ADVANCED_TABLE_CURRENT_PAGE);
            arrays = jsonObj.getArray(ADVANCED_TABLE_VALUE);
            getLogger(CommunicationWorker.class.getName()).log(Level.INFO,
                    "Dump JSON DATA for ADVANCED_TABLE: \n{0} \ntotal: {1} \npage: {2}",
                    new Object[] { jsonObj.toString(), total, page });
            JXMsgPanel advanceTable = getBlock(meta.getId(), JXMsgPanel.class);
            advanceTable.refreshTotalPages(total);
            advanceTable.refreshCurrentPage(page);
            advanceTable.refreshTable(arrays);
        } catch (Exception e) {
            getLogger(CommunicationWorker.class.getName()).log(Level.WARNING,
                    "Invalid complex data [ {0} ] for ADVANCED_TABLE component[{1}] \n exception is {2}",
                    new Object[] { result.getOkMsg(), String.valueOf(meta.getId()), e });
        }
        break;
    case LABEL:
        JLabel label = getBlock(meta.getId(), JLabel.class);
        if (result.getRetCode() == 0) {
            label.setText(StringEscapeUtils.unescapeHtml(result.getOkMsg()));
        } else {
            label.setText(StringEscapeUtils.unescapeHtml(result.getErrMsg()));
        }
        break;
    case TEXT_FIELD:
        JTextField textField = getBlock(meta.getId(), JTextField.class);
        if (result.getRetCode() == 0) {
            textField.setText(result.getOkMsg());
        } else {
            CommonUtil.showErrorMsg(textField.getTopLevelAncestor(), result.getErrMsg());
        }
        break;
    default:
        getLogger(CommunicationWorker.class.getName()).log(Level.WARNING,
                "Unsupported displayed component type : {0}", meta.getType());
    }
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.EditorPropPanel.java

/**
 * @param data/* w  w  w .  jav  a 2  s .  c  o m*/
 */
public void setData(final Object data) {
    currentFC = null;
    this.data = data;

    if (multiView != null) {
        multiView.setData(data);

        if (data != null) {
            if (data instanceof ViewDefIFace) {
                JTextField typeLabel = (JTextField) formViewObj.getControlByName("type"); //$NON-NLS-1$
                typeLabel.setText(UIHelper.makeNamePretty(data.getClass().getSimpleName()));

            } else if (data instanceof AltView) {
                setDataIntoUI((AltView) data);
            }
        }
    }
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.EditorPropPanel.java

/**
 * @param fc//from  ww  w .j  a  v a 2  s  .c o  m
 * @param rows
 * @param rowInx
 * @param cols
 * @param colInx
 */
public void setDataIntoUI(final FormViewDef fvd, final FormCell fc, final int rows, final int rowDefs,
        final int rowInx, final int cols, final int colDefs, final int colInx) {
    if (formViewObj == null) {
        return;
    }

    formViewDef = fvd;

    currentFC = fc;
    data = fc;

    setDataIntoBase(fc, rows, rowDefs, rowInx, cols, colDefs, colInx, false);

    JTextField typeLabel = (JTextField) formViewObj.getControlByName("type"); //$NON-NLS-1$
    typeLabel.setText(fc.getType().toString());

    if (fc instanceof FormCellLabel) {
        FormCellLabel fcl = (FormCellLabel) fc;

        getIdCombobox(fcl.getLabelFor());

        processImageNameCBX(fcl.getIconName());

        ValCheckBox chkbx = (ValCheckBox) formViewObj.getControlByName("isRecordObj"); //$NON-NLS-1$
        chkbx.setSelected(fcl.isRecordObj());

        ((ValTextField) formViewObj.getControlByName("label")).setText(((FormCellLabel) fc).getLabel()); //$NON-NLS-1$
    }

    multiView.validateAll();

}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.EditorPropPanelOld.java

/**
 * @param fc/*from   www . j a  va 2 s . c o m*/
 * @param rows
 * @param rowInx
 * @param cols
 * @param colInx
 */
public void setDataIntoUI(final FormCell fc, final int rows, final int rowDefs, final int rowInx,
        final int cols, final int colDefs, final int colInx) {
    if (formViewObj == null) {
        return;
    }
    currentData = fc;

    //viewPanel.getMultiView().setData(fc);

    setDataIntoBase(fc, rows, rowDefs, rowInx, cols, colDefs, colInx, false);

    JTextField typeLabel = (JTextField) formViewObj.getControlByName("type"); //$NON-NLS-1$
    typeLabel.setText(fc.getType().toString());

    /*
    ValComboBox typeCBX = (ValComboBox)formViewObj.getControlByName("typecbx");
    DefaultComboBoxModel model = (DefaultComboBoxModel)typeCBX.getModel();
    int inx = -1;
    int cnt = 0;
    for (String type : controlHash.keySet())
    {
    model.addElement(type);
    if (type.equals(fc.getType().toString()))
    {
        inx = cnt;
    }
    cnt++;
    }
    typeCBX.getComboBox().setSelectedIndex(inx);
            
    */

    if (fc instanceof FormCellLabel) {
        FormCellLabel fcl = (FormCellLabel) fc;

        getIdCombobox(fcl.getLabelFor());

        processImageNameCBX(fcl.getIconName());

        ValCheckBox chkbx = (ValCheckBox) formViewObj.getControlByName("isRecordObj"); //$NON-NLS-1$
        chkbx.setSelected(fcl.isRecordObj());

        ((ValTextField) formViewObj.getControlByName("label")).setText(((FormCellLabel) fc).getLabel()); //$NON-NLS-1$
    }

    //if (doValidate)
    //{
    viewDefMultiView.validateAll();
    //}

}

From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java

public File fileChooser(JTextField jtf, String ext, String openOrSave) {
    jfcFiles = new JFileChooser(jtf.getText());
    if (!ext.equals(""))
        jfcFiles.addChoosableFileFilter(new MyFileFilter(ext));
    jfcFiles.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    int state;/*from  www.ja  va  2  s  .  c  o  m*/
    if (openOrSave.equals("open"))
        state = jfcFiles.showOpenDialog(null);
    else
        state = jfcFiles.showSaveDialog(null);

    if (state == JFileChooser.APPROVE_OPTION) {
        File file = checkFileExtension(ext);
        jtf.setText(file.getPath());
        log.info("Opening: " + file.getName() + ".");
        return file;
    } else {
        log.info("Open command cancelled by user.");
        return null;
    }
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.EditorPropPanelOld.java

/**
 * @param fcf//from   w w  w.ja  v a2 s .  c  o  m
 * @param rows
 * @param rowInx
 * @param cols
 * @param colInx
 */
public void setDataIntoUI(final FormCellField fcf, final int rows, final int rowDefs, final int rowInx,
        final int cols, final int colDefs, final int colInx) {
    if (formViewObj == null) {
        return;
    }
    currentData = fcf;

    //viewPanel.getMultiView().setData(fcf);
    int inx;
    int cnt;

    setDataIntoBase(fcf, rows, rowDefs, rowInx, cols, colDefs, colInx, true);
    setDataIntoBase(fcf);

    JTextField typeLabel = (JTextField) formViewObj.getControlByName("type"); //$NON-NLS-1$
    typeLabel.setText(fcf.getUiType().toString());

    /*
    ValComboBox typeCBX = (ValComboBox)formViewObj.getControlByName("typecbx");
    DefaultComboBoxModel model = (DefaultComboBoxModel)typeCBX.getModel();
    inx = -1;
    cnt = 0;
    for (String type : subcontrolHash.keySet())
    {
    model.addElement(type);
    if (type.equals(fcf.getUiType().toString()))
    {
        inx = cnt;
    }
    cnt++;
    }
    typeCBX.getComboBox().setSelectedIndex(inx);*/

    if (fcf.getUiType() == FormCellFieldIFace.FieldType.combobox) {
        DataProviderSessionIFace session = DataProviderFactory.getInstance().createSession();
        List<?> pickLists = session.getDataList(PickList.class);
        ValComboBox pickListCBX = (ValComboBox) formViewObj.getControlByName("picklistcbx"); //$NON-NLS-1$
        DefaultComboBoxModel model = (DefaultComboBoxModel) pickListCBX.getModel();
        inx = 0;
        cnt = 1;

        String dataPickListName = fcf.getPickListName();

        pickList.clear();
        model.addElement(getResourceString("EditorPropPanelOld.NONE"));//$NON-NLS-1$
        for (Iterator<?> iter = pickLists.iterator(); iter.hasNext();) {
            PickList pl = (PickList) iter.next();
            String name = pl.getName();
            pickList.put(pl.getName(), pl.getIdentityTitle());
            model.addElement(name);
            if (StringUtils.isNotEmpty(dataPickListName) && dataPickListName.equals(name)) {
                inx = cnt;
            }
            cnt++;
        }
        session.close();
        pickListCBX.getComboBox().setSelectedIndex(inx);

        ValTextArea textArea = (ValTextArea) formViewObj.getControlByName("list"); //$NON-NLS-1$
        String list = fcf.getProperty("list"); //$NON-NLS-1$
        if (list != null) {
            textArea.setText(list);
        }
    }

    viewDefMultiView.validateAll();
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.EditorPropPanel.java

/**
 * @param fcf/*from  w w w.  j ava 2s  .  co m*/
 * @param rows
 * @param rowInx
 * @param cols
 * @param colInx
 */
public void setDataIntoUI(final FormViewDef fvd, final FormCellField fcf, final int rows, final int rowDefs,
        final int rowInx, final int cols, final int colDefs, final int colInx) {
    if (formViewObj == null) {
        return;
    }

    formViewDef = fvd;
    currentFC = fcf;
    data = fcf;

    //viewPanel.getMultiView().setData(fcf);
    int inx;
    int cnt;

    setDataIntoBase(fcf, rows, rowDefs, rowInx, cols, colDefs, colInx, true);
    setDataIntoBase(fcf);

    JTextField typeLabel = (JTextField) formViewObj.getControlByName("type"); //$NON-NLS-1$
    typeLabel.setText(fcf.getUiType().toString());

    /*
    ValComboBox typeCBX = (ValComboBox)formViewObj.getControlByName("typecbx");
    DefaultComboBoxModel model = (DefaultComboBoxModel)typeCBX.getModel();
    inx = -1;
    cnt = 0;
    for (String type : subcontrolHash.keySet())
    {
    model.addElement(type);
    if (type.equals(fcf.getUiType().toString()))
    {
        inx = cnt;
    }
    cnt++;
    }
    typeCBX.getComboBox().setSelectedIndex(inx);*/

    if (fcf.getUiType() == FormCellFieldIFace.FieldType.combobox) {
        DataProviderSessionIFace session = DataProviderFactory.getInstance().createSession();
        List<?> pickLists = session.getDataList(PickList.class);
        ValComboBox pickListCBX = (ValComboBox) formViewObj.getControlByName("picklistcbx"); //$NON-NLS-1$
        DefaultComboBoxModel model = (DefaultComboBoxModel) pickListCBX.getModel();
        inx = 0;
        cnt = 1;

        String dataPickListName = fcf.getPickListName();

        pickList.clear();
        model.addElement(getResourceString("EditorPropPanel.NONE")); //$NON-NLS-1$
        for (Iterator<?> iter = pickLists.iterator(); iter.hasNext();) {
            PickList pl = (PickList) iter.next();
            String name = pl.getName();
            pickList.put(pl.getName(), pl.getIdentityTitle());
            model.addElement(name);
            if (StringUtils.isNotEmpty(dataPickListName) && dataPickListName.equals(name)) {
                inx = cnt;
            }
            cnt++;
        }
        session.close();
        pickListCBX.getComboBox().setSelectedIndex(inx);

        ValTextArea textArea = (ValTextArea) formViewObj.getControlByName("list"); //$NON-NLS-1$
        String list = fcf.getProperty("list"); //$NON-NLS-1$
        if (list != null) {
            textArea.setText(list);
        }
    }

    multiView.validateAll();
}