List of usage examples for javax.swing JFormattedTextField getValue
public Object getValue()
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); final JFormattedTextField textField1 = new JFormattedTextField(new Float(10.01)); textField1.setFormatterFactory(new AbstractFormatterFactory() { @Override/* w w w .j a v a 2 s.co m*/ public AbstractFormatter getFormatter(JFormattedTextField tf) { NumberFormat format = DecimalFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); format.setRoundingMode(RoundingMode.HALF_UP); InternationalFormatter formatter = new InternationalFormatter(format); formatter.setAllowsInvalid(false); formatter.setMinimum(0.0); formatter.setMaximum(1000.00); return formatter; } }); Map attributes = (new Font("Serif", Font.BOLD, 16)).getAttributes(); attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); final JFormattedTextField textField2 = new JFormattedTextField(new Float(10.01)); textField2.setFormatterFactory(new AbstractFormatterFactory() { @Override public AbstractFormatter getFormatter(JFormattedTextField tf) { NumberFormat format = DecimalFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); format.setRoundingMode(RoundingMode.HALF_UP); InternationalFormatter formatter = new InternationalFormatter(format); formatter.setAllowsInvalid(false); formatter.setMinimum(0.0); formatter.setMaximum(1000.00); return formatter; } }); textField2.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } @Override public void insertUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } @Override public void removeUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } private void printIt(DocumentEvent documentEvent) { DocumentEvent.EventType type = documentEvent.getType(); double t1a1 = (((Number) textField2.getValue()).doubleValue()); if (t1a1 > 100) { textField2.setFont(new Font(attributes)); textField2.setForeground(Color.red); } else { textField2.setFont(new Font("Serif", Font.BOLD, 16)); textField2.setForeground(Color.black); } } }); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(textField1, BorderLayout.NORTH); frame.add(textField2, BorderLayout.SOUTH); frame.setVisible(true); frame.pack(); }
From source file:com.streamhub.StreamHubLicenseGenerator.java
private static JPanel createMacAddressRow() { JPanel macAddressPanel = new JPanel(new FlowLayout()); Calendar yesterday = Calendar.getInstance(); yesterday.setTime(new Date()); yesterday.add(Calendar.DAY_OF_MONTH, -1); Calendar expiry = Calendar.getInstance(); expiry.setTime(yesterday.getTime()); expiry.add(Calendar.DAY_OF_MONTH, 60); JLabel macAddressLabel = new JLabel("MAC Address:"); JTextField macAddress = new JTextField(17); JLabel startDateLabel = new JLabel("Start Date"); final JFormattedTextField startDate = new JFormattedTextField(new SimpleDateFormat(DATE_FORMAT)); startDate.setValue(yesterday.getTime()); JLabel expiryDateLabel = new JLabel("Expiry Date"); final JFormattedTextField expiryDate = new JFormattedTextField(new SimpleDateFormat(DATE_FORMAT)); expiryDate.setValue(expiry.getTime()); startDate.addKeyListener(new KeyListener() { @Override/*www. j a va2 s . c o m*/ public void keyTyped(KeyEvent arg0) { // Get the new date and change expiry to suit Date date = (Date) startDate.getValue(); Calendar tempCal = Calendar.getInstance(); tempCal.setTime(date); tempCal.add(Calendar.DAY_OF_MONTH, 60); expiryDate.setValue(tempCal.getTime()); } @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { } }); JComboBox edition = new JComboBox(new String[] { "web", "enterprise" }); JLabel nameLabel = new JLabel("Name:"); JTextField name = new JTextField(15); JLabel numUsersLabel = new JLabel("Num. Users:"); JTextField numUsers = new JTextField(DEFAULT_NUM_USERS); macAddressPanel.add(macAddressLabel); macAddressPanel.add(macAddress); macAddressPanel.add(startDateLabel); macAddressPanel.add(startDate); macAddressPanel.add(expiryDateLabel); macAddressPanel.add(expiryDate); macAddressPanel.add(edition); macAddressPanel.add(nameLabel); macAddressPanel.add(name); macAddressPanel.add(numUsersLabel); macAddressPanel.add(numUsers); return macAddressPanel; }
From source file:components.IntegerEditor.java
public Object getCellEditorValue() { JFormattedTextField ftf = (JFormattedTextField) getComponent(); Object o = ftf.getValue(); if (o instanceof Integer) { return o; } else if (o instanceof Number) { return new Integer(((Number) o).intValue()); } else {/* w w w . j a v a 2s . com*/ if (DEBUG) { System.out.println("getCellEditorValue: o isn't a Number"); } try { return integerFormat.parseObject(o.toString()); } catch (ParseException exc) { System.err.println("getCellEditorValue: can't parse o: " + o); return null; } } }
From source file:FormatTest.java
/** * Adds a row to the main panel./*w w w . jav a 2 s .com*/ * @param labelText the label of the field * @param field the sample field */ public void addRow(String labelText, final JFormattedTextField field) { mainPanel.add(new JLabel(labelText)); mainPanel.add(field); final JLabel valueLabel = new JLabel(); mainPanel.add(valueLabel); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Object value = field.getValue(); Class<?> cl = value.getClass(); String text = null; if (cl.isArray()) { if (cl.getComponentType().isPrimitive()) { try { text = Arrays.class.getMethod("toString", cl).invoke(null, value).toString(); } catch (Exception ex) { // ignore reflection exceptions } } else text = Arrays.toString((Object[]) value); } else text = value.toString(); valueLabel.setText(text); } }); }
From source file:it.txt.access.capability.revocation.wizard.panel.PanelRevocationData.java
private boolean isMissingFormattedTextField(JFormattedTextField textBox, StringBuilder missingFieldMessage) { if (textBox.getValue() == null) { if (missingFieldMessage.length() > 0) missingFieldMessage.append(", " + textBox.getName()); else//w w w . ja va2 s . c o m missingFieldMessage.append(textBox.getName()); return true; } return false; }
From source file:fll.scheduler.SchedulerUI.java
/** * Prompt the user for which columns represent subjective categories. * /*from w ww.ja v a 2s .co m*/ * @param parentComponent the parent for the dialog * @param columnInfo the column information * @return the list of subjective information the user choose */ public static List<SubjectiveStation> gatherSubjectiveStationInformation(final Component parentComponent, final ColumnInformation columnInfo) { final List<String> unusedColumns = columnInfo.getUnusedColumns(); final List<JCheckBox> checkboxes = new LinkedList<JCheckBox>(); final List<JFormattedTextField> subjectiveDurations = new LinkedList<JFormattedTextField>(); final Box optionPanel = Box.createVerticalBox(); optionPanel.add(new JLabel("Specify which columns in the data file are for subjective judging")); final JPanel grid = new JPanel(new GridLayout(0, 2)); optionPanel.add(grid); grid.add(new JLabel("Data file column")); grid.add(new JLabel("Duration (minutes)")); for (final String column : unusedColumns) { if (null != column && column.length() > 0) { final JCheckBox checkbox = new JCheckBox(column); checkboxes.add(checkbox); final JFormattedTextField duration = new JFormattedTextField( Integer.valueOf(SchedParams.DEFAULT_SUBJECTIVE_MINUTES)); duration.setColumns(4); subjectiveDurations.add(duration); grid.add(checkbox); grid.add(duration); } } final List<SubjectiveStation> subjectiveHeaders; if (!checkboxes.isEmpty()) { JOptionPane.showMessageDialog(parentComponent, optionPanel, "Choose Subjective Columns", JOptionPane.QUESTION_MESSAGE); subjectiveHeaders = new LinkedList<SubjectiveStation>(); for (int i = 0; i < checkboxes.size(); ++i) { final JCheckBox box = checkboxes.get(i); final JFormattedTextField duration = subjectiveDurations.get(i); if (box.isSelected()) { subjectiveHeaders .add(new SubjectiveStation(box.getText(), ((Number) duration.getValue()).intValue())); } } } else { subjectiveHeaders = Collections.emptyList(); } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Subjective headers selected: " + subjectiveHeaders); } return subjectiveHeaders; }
From source file:it.txt.access.capability.revocation.wizard.panel.PanelRevocationData.java
private void checkFormattedTextBoxIsEmpty(final JFormattedTextField textBox) { textBox.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { changeBorderColor(e);/*from ww w .j a va 2 s . com*/ } public void removeUpdate(DocumentEvent e) { changeBorderColor(e); } public void changedUpdate(DocumentEvent e) { changeBorderColor(e); } private void changeBorderColor(DocumentEvent e) { if (textBox.getValue() != null) { textBox.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); } else { textBox.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0))); } } }); }
From source file:oct.analysis.application.OCTAnalysisUI.java
private void lrpSelectionWidthBeanPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_lrpSelectionWidthBeanPropertyChange if (LRPSelectionWidthBean.LRP_SELECTION_WIDTH_PROPERTY.equals(evt.getPropertyName())) { //update the selection width (will only affect those selections that are resizable (OCTLines are NOT resizable) selectionLRPManager.setSelectionWidth((int) evt.getNewValue()); //update display with new values octAnalysisPanel.repaint();/*from w w w .j ava2 s .c o m*/ //ensure the value in the input box is bounded to possible values for selection width JFormattedTextField widthInput = getLrpWidthTextField(); Object value = widthInput.getValue(); int lrpw; if (value instanceof Long) { lrpw = (int) ((long) value); } else if (value instanceof Integer) { lrpw = (int) value; } else { lrpw = 5; } if (lrpw != selectionLRPManager.getSelectionWidth()) { //update UI to reflect bounded input value widthInput.setValue(selectionLRPManager.getSelectionWidth()); } } }
From source file:at.becast.youploader.gui.FrmMain.java
/** * Creates the Upload and the Uploadframe * /* w w w. jav a2 s. com*/ * * @param File path to the file that should be uploaded * * @param Name The title of the upload * * @param acc_id The Account id of the Account that should upload the Video * * @return UploadItem The Upload Frame * */ public UploadItem createUpload(String File, String Name, int acc_id) { UploadItem f = new UploadItem(); EditPanel edit = (EditPanel) ss1.contentPane; f.getlblName().setText(Name); this.getQueuePanel().add(f, new CC().wrap()); this.getQueuePanel().revalidate(); Video v = new Video(); v.snippet.title = Name; Categories cat = (Categories) cmbCategory.getSelectedItem(); v.snippet.categoryId = cat.getID(); v.snippet.description = txtDescription.getText(); if (txtTags != null && !txtTags.getText().equals("")) { v.snippet.tags = TagUtil.trimTags(txtTags.getText()); } VideoMetadata metadata = createMetadata(); VisibilityType visibility = (VisibilityType) edit.getCmbVisibility().getSelectedItem(); if (visibility == VisibilityType.SCHEDULED) { if (edit.getDateTimePicker().getEditor().getValue() != null && !edit.getDateTimePicker().getEditor().getValue().equals("")) { v.status.privacyStatus = VisibilityType.SCHEDULED.getData(); Date date = edit.getDateTimePicker().getDate(); String pattern = "yyyy-MM-dd'T'HH:mm:ss.sssZ"; SimpleDateFormat formatter = new SimpleDateFormat(pattern); f.getlblRelease().setText(edit.getDateTimePicker().getEditor().getValue().toString()); v.status.publishAt = formatter.format(date); } else { v.status.privacyStatus = VisibilityType.PRIVATE.getData(); } } else { v.status.privacyStatus = visibility.getData(); if (visibility == VisibilityType.PUBLIC) { f.getlblRelease().setText(LANG.getString("Visibility.Public")); } } v.status.embeddable = edit.getChckbxAllowEmbedding().isSelected(); v.status.publicStatsViewable = edit.getChckbxMakeStatisticsPublic().isSelected(); LicenseType license = (LicenseType) edit.getCmbLicense().getSelectedItem(); v.status.license = license.getData(); File data = new File(File); metadata.setFrame(f); metadata.setAccount(acc_id); JFormattedTextField tf = edit.getDateTimePickerStart().getEditor(); System.out.println(tf.getValue()); if (tf.getValue() == null || tf.getValue().toString().equals("")) { UploadMgr.addUpload(data, v, metadata, null); } else { UploadMgr.addUpload(data, v, metadata, edit.getDateTimePickerStart().getDate()); } return f; }
From source file:grupob.TipoProceso.java
private void botonGuardarNacionalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGuardarNacionalActionPerformed JFormattedTextField fechai1 = fechai1Nacional.getEditor(); Date datei1 = (Date) fechai1.getValue(); JFormattedTextField fechai2 = fechai2Nacional.getEditor(); Date datei2 = (Date) fechai2.getValue(); JFormattedTextField fechaf1 = fechaf1Nacional.getEditor(); Date datef1 = (Date) fechaf1.getValue(); JFormattedTextField fechaf2 = fechaf2Nacional.getEditor(); Date datef2 = (Date) fechaf2.getValue(); if (datei1 == null || datei2 == null || datef1 == null || datef2 == null) { JOptionPane.showMessageDialog(null, "Error: Falta ingresar todos los campos"); return;/*from w ww . j a v a2 s. c om*/ } TipoProcesoVotacion proceso = new TipoProcesoVotacion(); proceso.setId(1); Calendar calA = Calendar.getInstance(); calA.setTime(datei1); proceso.setFechaInicio1(calA); Date d = proceso.getFechaInicio1().getTime(); Calendar calB = Calendar.getInstance(); calB.setTime(datei2); proceso.setFechaInicio2(calB); Date d2 = proceso.getFechaInicio2().getTime(); Calendar calC = Calendar.getInstance(); calC.setTime(datef1); proceso.setFechaFin1(calC); Date d3 = proceso.getFechaFin1().getTime(); Calendar calD = Calendar.getInstance(); calD.setTime(datef2); proceso.setFechaFin2(calD); Date d4 = proceso.getFechaFin2().getTime(); proceso.setId(1); proceso.setNombre("Nacional"); proceso.setPorcentajeMinimo((float) 0.10); SimpleDateFormat formatoDeFecha = new SimpleDateFormat("dd/MM/yyyy"); if (verificaFechas(datei1, datei2, datef1, datef2)) { Manager.updateProceso(proceso); jLabel57.setText("1era Revision - Fecha Inicio: " + formatoDeFecha.format(datei1) + " Fecha Fin: " + formatoDeFecha.format(datef1)); jLabel58.setText("2da Revision - Fecha Inicio: " + formatoDeFecha.format(datei2) + " Fecha Fin: " + formatoDeFecha.format(datef2)); JOptionPane.showMessageDialog(null, "Se atualizo los datos del proceso nacional"); } }