List of usage examples for javax.swing JTextField setForeground
@BeanProperty(preferred = true, visualUpdate = true, description = "The foreground color of the component.") public void setForeground(Color fg)
From source file:Main.java
public static void addPlaceHolder(final JTextField field, final String placeHolderText) { field.addFocusListener(new FocusListener() { private Color fontColor = field.getForeground(); // private String previousText=field.getText(); public void focusGained(FocusEvent arg0) { if (field.getText().equals(placeHolderText)) { field.setText(""); }// w w w . j a v a 2 s . c om field.setForeground(fontColor); } public void focusLost(FocusEvent arg0) { if (field.getText().trim().equals("")) { fontColor = field.getForeground(); field.setForeground(Color.GRAY); field.setText(placeHolderText); } } }); if (field.getText().trim().equals("")) { field.setText(placeHolderText); field.setForeground(Color.GRAY); } }
From source file:edu.ku.brc.specify.plugins.ipadexporter.ManageDataSetsDlg.java
/** * //w w w.j a v a 2 s .com */ 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(); } }
From source file:es.emergya.ui.gis.ControlPanel.java
public ControlPanel(final CustomMapView view) { super(new FlowLayout(FlowLayout.LEADING, 12, 0)); this.view = view; // Posicion: panel con un label de icono y un textfield JPanel posPanel = new JPanel(); posPanel.setOpaque(true);/*from w ww .jav a2s. co m*/ posPanel.setVisible(true); JLabel mouseLocIcon = new JLabel(LogicConstants.getIcon("map_icon_coordenadas")); posPanel.add(mouseLocIcon); final JTextField posField = new JTextField(15); posField.setEditable(false); posField.setBorder(null); posField.setForeground(UIManager.getColor("Label.foreground")); posField.setFont(UIManager.getFont("Label.font")); posPanel.add(posField); view.addMouseMotionListener(new MouseMotionListener() { @Override public void mouseMoved(MouseEvent e) { LatLon ll = ((ICustomMapView) e.getSource()).getLatLon(e.getX(), e.getY()); String position = ""; String format = LogicConstants.get("FORMATO_COORDENADAS_MAPA", "UTM"); if (format.equals(LogicConstants.COORD_UTM)) { UTM u = new UTM(LogicConstants.getInt("ZONA_UTM")); EastNorth en = u.latlon2eastNorth(ll); position = String.format("x: %.1f y: %.1f", en.getX(), en.getY()); } else { position = String.format("Lat: %.4f Lon: %.4f", ll.lat(), ll.lon()); } posField.setText(position); validate(); } @Override public void mouseDragged(MouseEvent e) { } }); posPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); add(posPanel); // Panel de centrado: label, desplegable y parte cambiante JPanel centerPanel = new JPanel(); centerPanel.add(new JLabel(i18n.getString("map.centerIn"))); centerOptions = new JComboBox(new String[] { i18n.getString("map.street"), i18n.getString("map.resource"), i18n.getString("map.incidence"), i18n.getString("map.location") }); centerPanel.add(centerOptions); centerData = new JPanel(new CardLayout()); centerPanel.add(centerData); JPanel centerStreet = new JPanel(); street = new JTextField(30); street.setName(i18n.getString("map.street")); autocompleteKeyListener = new AutocompleteKeyListener(street); street.addKeyListener(autocompleteKeyListener); street.addActionListener(this); centerStreet.add(street); centerData.add(centerStreet, i18n.getString("map.street")); JPanel centerResource = new JPanel(); resources = new JComboBox(avaliableResources); resources.setName(i18n.getString("map.resource")); resources.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); resources.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { isComboResourcesShowing = true; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { isComboResourcesShowing = false; } @Override public void popupMenuCanceled(PopupMenuEvent e) { // view.repaint(); } }); centerResource.add(resources); centerData.add(centerResource, i18n.getString("map.resource")); centerResource = new JPanel(); incidences = new JComboBox(avaliableIncidences); incidences.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); incidences.setName(i18n.getString("map.incidence")); incidences.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { isComboIncidencesShowing = true; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { isComboIncidencesShowing = false; } @Override public void popupMenuCanceled(PopupMenuEvent e) { } }); centerResource.add(incidences); centerData.add(centerResource, i18n.getString("map.incidence")); JPanel centerLocation = new JPanel(); cx = new JTextField(10); cx.setName("x"); cx.addActionListener(this); centerLocation.add(cx); cy = new JTextField(10); cy.setName("y"); cy.addActionListener(this); centerLocation.add(cy); centerData.add(centerLocation, i18n.getString("map.location")); centerOptions.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { ((CardLayout) centerData.getLayout()).show(centerData, (String) e.getItem()); } }); JButton centerButton = new JButton(i18n.getString("map.center")); centerButton.addActionListener(this); centerPanel.add(centerButton); add(centerPanel); }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.AddParallelLineDialog.java
/** * Verify that the y-value is correct./* w w w .j av a2 s. c om*/ * * @param input * @return true if the value is valid; false otherwise */ private boolean verifyYInput(JComponent input) { JTextField textField = (JTextField) input; String inputString = textField.getText(); try { Double.parseDouble(inputString); } catch (NumberFormatException e) { textField.setForeground(Color.RED); return false; } textField.setForeground(Color.BLACK); return true; }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.AddParallelLineDialog.java
/** * Verify that the x-value is correct.//from w w w . ja v a 2 s . c om * * @param input * @return true if the value is valid; false otherwise */ private boolean verifyXInput(JComponent input) { JTextField textField = (JTextField) input; String inputString = textField.getText(); try { Double.parseDouble(inputString); } catch (NumberFormatException e) { textField.setForeground(Color.RED); return false; } textField.setForeground(Color.BLACK); return true; }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java
/** * Verify that the color value is correct. * /* www . j a va2s . c o m*/ * @param input * @return true if the value is valid; false otherwise */ private boolean verifyColorInput(JComponent input) { JTextField textField = (JTextField) input; String inputString = textField.getText(); try { double color; if (inputString.startsWith("-")) { color = Double.parseDouble(inputString.substring(1)); color = -color; } else { color = Double.parseDouble(inputString); } // TODO: fix check for actual ranges } catch (NumberFormatException e) { textField.setForeground(Color.RED); return false; } textField.setForeground(Color.BLACK); return true; }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java
/** * Verify that the width value is correct. * /*from w w w . jav a 2s.co m*/ * @param input * @return true if the value is valid; false otherwise */ private boolean verifyValueRangeLowerBoundInput(JComponent input) { JTextField textField = (JTextField) input; String inputString = textField.getText(); try { double valueLowerBound; if (inputString.startsWith("-")) { valueLowerBound = Double.parseDouble(inputString.substring(1)); valueLowerBound = -valueLowerBound; } else { valueLowerBound = Double.parseDouble(inputString); } // TODO: fix check for actual ranges } catch (NumberFormatException e) { textField.setForeground(Color.RED); return false; } textField.setForeground(Color.BLACK); return true; }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java
/** * Verify that the height value is correct. * /*from w w w . j a v a 2 s . co m*/ * @param input * @return true if the value is valid; false otherwise */ private boolean verifyValueRangeUpperBoundInput(JComponent input) { JTextField textField = (JTextField) input; String inputString = textField.getText(); try { double valueUpperBound; if (inputString.startsWith("-")) { valueUpperBound = Double.parseDouble(inputString.substring(1)); valueUpperBound = -valueUpperBound; } else { valueUpperBound = Double.parseDouble(inputString); } // TODO: fix check for actual ranges } catch (NumberFormatException e) { textField.setForeground(Color.RED); return false; } textField.setForeground(Color.BLACK); return true; }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java
/** * Verify that the x-value is correct./*from ww w . j a v a2s . co m*/ * * @param input * @return true if the value is valid; false otherwise */ private boolean verifyDomainRangeUpperBoundInput(JComponent input) { JTextField textField = (JTextField) input; String inputString = textField.getText(); try { double domainUpperBound; if (inputString.startsWith("-")) { domainUpperBound = Double.parseDouble(inputString.substring(1)); domainUpperBound = -domainUpperBound; } else { domainUpperBound = Double.parseDouble(inputString); } // TODO: fix check for actual ranges } catch (NumberFormatException e) { textField.setForeground(Color.RED); return false; } textField.setForeground(Color.BLACK); return true; }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java
/** * Verify that the y-value is correct.//w w w. jav a2 s . co m * * @param input * @return true if the value is valid; false otherwise */ private boolean verifyDomainRangeLowerBoundInput(JComponent input) { JTextField textField = (JTextField) input; String inputString = textField.getText(); try { double domainLowerBound; if (inputString.startsWith("-")) { domainLowerBound = Double.parseDouble(inputString.substring(1)); domainLowerBound = -domainLowerBound; } else { domainLowerBound = Double.parseDouble(inputString); } // TODO: fix check for actual ranges } catch (NumberFormatException e) { textField.setForeground(Color.RED); return false; } textField.setForeground(Color.BLACK); return true; }