Introduction to JFormattedTextFields

Hi there,
Can someone help me out with a link to a tutorial/introduction how to work with JFormattedTextFields?
I'd like to do a TextField to read in some int values but would like to guarantee that it is not possible to type in letters or more than 8 characters. Someone in this forum recommended me JFormattedTextFields (which I appreciate very much!!!). But it looked quite complicate - do I have to use a Formatter or a FormatterFactory?! Whatever if I would have some explanation I could read and find out about that.

Hi,
I am also facing a similar problem
if u could find it and have written some code for that, it will be very helpfull if u can send it to my mail id: [email protected]
thanx in advance,
Umesh

Similar Messages

  • How to see a null or empty value in JFormattedTextField

    Hello, I am having a problem. I'm trying to use a JFormattedTextField, and I keep getting errors.
    I know what is causing the error, but I don't know how to fix it.
    Here is my code:
    String cf = countFTX.getText();
    if(cf.equals(" ")) {
      i = Integer.valueOf(countJTX.getText());
    }else{ i = Integer.valueOf(countFTX.getText()); }what happens is I get an error when it goes to change it into an int. Because it see's it as being (" ") and not (" ") or even ("") so it doesn't fit into my if statement. And returns it being false, then tries to turn it into an int, and blows up there.
    Now how can I fix my if statement to be able to see if nothing was entered, and if so then use the countJTX and not the countFTX?
    countJTX is a regular JTextField, and countFTX is a JFormattedTextField.
    the JTX is filled automaticaly with an int, and if there needs to be a change, the user puts it into the FTX. (so you understand the logic behind it)
    any ideas? or should i just revert to not using the FTX?

    you need to know the differenct between NULL and "" (empty) of a string. Also both of these values cann't converted to in integer so you can not call Integer.valueOf(cf). I don't understand why you need to do that. Instead:
        String cf = countFTX.getText();
        if(cf == null || cf.length() == 0)) {
            i = ?; //something you want i to be when cf is null or empty but not call Integer.valueOf(countJTX.getText());
        }else{
            i = Integer.valueOf(cf);
        }Also, you may need to add try/catch exceptions.

  • Apple maps has received a poor performance rating just after introduction of the iPhone 5. I am running google maps app on the phone. Siri cannot seem to get me to a specific address. Where does the problem lie? Thanks.

    Apple maps has received a poor performance rating just after introduction of the iPhone 5. I am running Google Maps app on the phone. SIRI cannot seem to get me to a specific address. Where does the problem lie? Also can anyone tell me the hierarchy of use between the Apple Maps, SIRI, and Google maps when the app is on the phone? How do you choose one over the other as the default map usage? Or better still how do you suppress SIRI from using the Apple maps app when requesting a "go to"?
    I have placed an address location into the CONTACTS list and when I ask SIRI to "take me there" it found a TOTALLY different location in the metro area with the same street name. I have included the address, the quadrant, (NE) and the ZIP code into the CONTACTS list. As it turns out, no amount of canceling the trip or relocating the address in the CONTACTS list line would prevent SIRI from taking me to this bogus location. FINALLY I typed in Northeast for NE in the CONTACTS list (NE being the accepted method of defining the USPS location quadrant) , canceled the current map route and it finally found the correct address. This problem would normally not demand such a response from me to have it fixed but the address is one of a hospital in the center of town and this hospital HAS a branch location in a similar part of town (NOT the original address SIRI was trying to take me to). This screw up could be dangerous if not catastrophic to someone who was looking for a hospital location fast and did not know of these two similar locations. After all the whole POINT of directions is not just whimsical pasttime or convenience. In a pinch people need to rely on this function. OR, are my expectations set too high? 
    How does the iPhone select between one app or the other (Apple Maps or Gppgle Maps) as it relates to SIRI finding and showing a map route?  
    Why does SIRI return an address that is NOT the correct address nor is the returned location in the requested ZIP code?
    Is there a known bug in the CONTACTS list that demands the USPS quadrant ID be spelled out, as opposed to abreviated, to permit SIRI to do its routing?
    Thanks for any clarification on these matters.

    siri will only use apple maps, this cannot be changed. you could try google voice in the google app.

  • Formatting using JFormattedTextField

    Hi everyone , I'm trying to create a JFormattedTextField wich accepts only number and have a limited size and if the user didn't fill all field, I want this fields stillValid..
    JFormattedTextField fmtNumer = new JFormattedTextField(new MaskFormatter("###,###");
    Thanks.

    Set the format using a DecimalFormat. Set the document to be one that allows a limited size.
    public class DocumentSizeFilter extends DocumentFilter {
          * Allows unlimited text.
         public static final int UNLIMITED_TEXT = -1;
                   private int maxCharacters;
        private boolean DEBUG = false;
         * Default constructor. Does not limit size of document.
        public DocumentSizeFilter() {
           this(UNLIMITED_TEXT);
         * Constructor
         * @param maxChars the maximum number of characters to allow
        public DocumentSizeFilter(int maxChars) {
            maxCharacters = maxChars;
         //     ------------------------  Methods ---------------------------
         * Set the maximum number of characters allowed.
         * <B>UNLIMITED_TEXT<\B> specified unlimited text size.
         * @param maxChars the maximum number of characters to allow
        public void setMaxSize (int maxChars) {
            maxCharacters = maxChars;
        public void insertString(FilterBypass fb, int offs,
                                 String str, AttributeSet a)
            throws BadLocationException {
            if (DEBUG) {
                System.out.println("in DocumentSizeFilter's insertString method");
            //This rejects the entire insertion if it would make
            //the contents too long. Another option would be
            //to truncate the inserted string so the contents
            //would be exactly maxCharacters in length.
            if (maxCharacters == UNLIMITED_TEXT ||
                      (fb.getDocument().getLength() + str.length()) <= maxCharacters)
                super.insertString(fb, offs, str, a);
            else
                Toolkit.getDefaultToolkit().beep();
        public void replace(FilterBypass fb, int offs,
                            int length,
                            String str, AttributeSet a)
            throws BadLocationException {
            if (DEBUG) {
                System.out.println("in DocumentSizeFilter's replace method");
            //This rejects the entire replacement if it would make
            //the contents too long. Another option would be
            //to truncate the replacement string so the contents
            //would be exactly maxCharacters in length.
            if (maxCharacters == UNLIMITED_TEXT ||
                      (fb.getDocument().getLength() + str.length()
                 - length) <= maxCharacters)
                super.replace(fb, offs, length, str, a);
            else
                Toolkit.getDefaultToolkit().beep();
              textFilter = new DocumentSizeFilter(/*num characters to allow*/);
              AbstractDocument doc;
              Document doci = getDocument();
              if (doci instanceof AbstractDocument) {
                   doc = (AbstractDocument) doci;
                   doc.setDocumentFilter(textFilter);
              }

  • How to use multiple formats in one JFormattedTextField

    Hi,
    I am looking for a way to allow multiple formats in the same JFormattedTextField. Let's say I want to allow input like:
    a) 123-AB-123
    and
    b) AB-12345-CD
    Of course I could use an InputVerifier of my own combined with regular expressions to see if the input matches. But I like the way JFormattedTextField supports the UserInput by displaying a Placeholder String. So the User sees what the input might look like.
    I'd tried to write a FormatterFactory of my own, which will return either a MaskFormatter for a) or b) but the JFormattedTextField checks out the Formatter only when gaining or loosing focus. What should happen is that it checks out the formatter after each keystroke.
    Does anyone know a solution for this or how I could force the FormattedTextField to REget it's formatter?
    Thanks
    Thimo

    Check out the following; it provides code for a regular expression formatter:
    http://java.sun.com/products/jfc/tsc/articles/reftf/
    Unfortunately, this does not support the 'placeholder' notion like the MaskFormatter does, if that's what you were talking about. I'm not sure how you could cobble them together, since with the MaskFormatter you don't have to type the mask literal characters, but you would need to with the regular expression.
    : jay

  • Re-write numerical page numbers to roman numerals for an introduction?

    Hi there everybody,
    I've been attempting (for some considerable time!) to typeset and format a book. The book needs to have roman numerals running from the first title page (which is in reality left blank through using a secondary master page without page numbers). However, I didn't realise I would need to use roman numerals in the introduction, and instead started the page numbers from the first title page of the introduction. Therefore, my pages that are numbered by roman numerals (copyright page etc) stop at this point and in the introduction become numbers.
    I need to change it so it is roman numerals up until the first page of the actual book, all through the introduction,  but when I try to change it in the Numbers and Sections tab, it tells me that i've already used the numbers i've typed in.
    Basically I would like to know how to take off the first set of roman numeral page numbers and start again??
    I'm very confused!! Help would be MUCH appreciated.
    Lucy

    Is this any help?
    Working with Page Numbers and Sections | Managing Pages and Books with Adobe InDesign CS6 | Que

  • How do I copy the introduction of a project to other projects?

    I am trying to find out how to copy the introduction (video clip + title + audio clip) of my video series from one project to another.... so far, the only information I can find tells me to 'open both projects at once'.... I have searched everywhere and cannot figure out how to open multiple projects at once.... i can copy the video clip to a new project, but the title and audio track don't come with it... they won't drag and drop nor copy and paste into the new project. I plan to have many episodes of my video series, and want my standard introduction to be at the beginning of each new project, without having to do the title and audio from scratch each time, like i am doing now.
    thanks for any help.....

    Does this mean I would have to then delete all the other clips/audio, etc from the new, duplicated project? Surely there must be a way to just copy one section into a new project. I start making some of the new projects in advance, and want to drop the intro into the beginning... if I already have the next three or four 'episodes' (projects) already started, the duplication thing won't work.....

  • Selection problem with JFormattedTextField

    I encounter a problem to select the content of a JFormattedTextField.
    Here is a class for a dialog containing 2 JFormattedTextFields :
    * Created on 7 juin 2005
    * To change the template for this generated file go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    package cimpa.smartndtkit.dialog;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.text.DecimalFormat;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import cimpa.smartndtkit.utilities.Texts;
    import cimpa.smartndtkit.utilities.basic_classes.MyButton;
    import cimpa.smartndtkit.utilities.basic_classes.MyFormattedTextField;
    import cimpa.smartndtkit.utilities.basic_classes.MyLabel;
    import cimpa.smartndtkit.utilities.basic_classes.MyPanel;
    * @author st08051
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    public class ChangePaletteLimitsDialog extends MyDialog {
         private boolean isOK = false;
         private float minValue, maxValue;
         private MyButton bOK, bCancel;
         private MyFormattedTextField txtMin, txtMax;
         public ChangePaletteLimitsDialog(JFrame parent, float minValue, float maxValue){
              super(parent, "Modification des limites", true);
              setResizable(false);
              setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              getContentPane().setLayout(new GridBagLayout());
              /** Constantes */
              Insets leftComponentInsets = new Insets(15,30,0,5);
              Insets rightComponentInsets = new Insets(15,5,0,30);
              Insets buttonsInsets = new Insets(8,5,8,5);
              int txtWidth = 60;
              int txtHeight = 22;
              DecimalFormat format = Texts.formatFactory("###0.###");
              /** Cr�ation des composants */
              MyLabel labelMin = new MyLabel("Valeur minimale :");          
              txtMin = new MyFormattedTextField(format);
              txtMin.setHorizontalAlignment(JTextField.RIGHT);
              txtMin.setAlignmentX(JTextField.RIGHT_ALIGNMENT);
              txtMin.setSizes(txtWidth, txtHeight);
              txtMin.setText(""+minValue);
    //          txtMin.setValue(new Float(minValue));
              txtMin.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent ke) {
                        keyPressed_actionPerformed(ke);
              txtMin.addFocusListener(new FocusAdapter() {
                   public void focusGained(FocusEvent arg0) {
                        txtMin.selectAll();
    //               public void focusLost(FocusEvent arg0) {
    //          txtMin.addActionListener(new ActionListener() {
    //               public void actionPerformed(ActionEvent arg0) {
    //                    txtMin.selectAll();
              MyLabel labelMax = new MyLabel("Valeur maximale :");
              txtMax = new MyFormattedTextField(format);
              txtMax.setHorizontalAlignment(JTextField.RIGHT);
              txtMax.setAlignmentX(JTextField.RIGHT_ALIGNMENT);
              txtMax.setSizes(txtWidth, txtHeight);
              txtMax.setText(""+maxValue);
    //          txtMax.setValue(new Float(maxValue));
              txtMax.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent ke) {
                        keyPressed_actionPerformed(ke);
              txtMax.addFocusListener(new FocusAdapter() {
                   public void focusGained(FocusEvent arg0) {
                        txtMax.selectAll();
    //               public void focusLost(FocusEvent arg0) {
    //          txtMax.addActionListener(new ActionListener() {
    //               public void actionPerformed(ActionEvent arg0) {
    //                    txtMax.selectAll();
              MyPanel panel = new MyPanel();
              bOK = new MyButton("OK");
              bOK.setSizes(60,25);
              bOK.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent ae) {
                        bOK_actionPerformed();
              bCancel = new MyButton("Annuler");
              bCancel.setSizes(60,25);
              bCancel.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent ae) {
                        bCancel_actionPerformed();
              /** Contraintes */
              GridBagConstraints constraints = new GridBagConstraints();
              constraints.anchor = GridBagConstraints.CENTER;
              /** Agencement des composants */
              constraints.gridx = 1;
              constraints.gridy = 0;
              constraints.gridwidth = 2;
              constraints.insets = leftComponentInsets;
              getContentPane().add(labelMin, constraints);
              constraints.gridx = 3;
              constraints.insets = rightComponentInsets;
              getContentPane().add(txtMin, constraints);
              constraints.gridx = 1;
              constraints.gridy = 1;
              constraints.insets = leftComponentInsets;
              getContentPane().add(labelMax, constraints);
              constraints.gridx = 3;
              constraints.insets = rightComponentInsets;
              getContentPane().add(txtMax, constraints);
              constraints.gridx = 0;
              constraints.gridy = 0;
              constraints.gridwidth = 1;
              constraints.insets = buttonsInsets;
              panel.add(bOK, constraints);
              constraints.gridx = 1;
              panel.setLayout(new GridBagLayout());
              panel.add(bCancel, constraints);
              constraints.gridx = 0;
              constraints.gridy = 3;
              constraints.gridwidth = 6;
              constraints.anchor = GridBagConstraints.CENTER;
              getContentPane().add(panel, constraints);
              this.pack();
              setLocationRelativeTo(parent);
              txtMin.requestFocus();
    //          getRootPane().setDefaultButton(bOK);
              setVisible(true);
          * @return
         public boolean isOK() {
              return isOK;
         public void bOK_actionPerformed(){
              isOK=true;
              minValue = new Float(txtMin.getText()).floatValue();
              maxValue = new Float(txtMax.getText()).floatValue();
              dispose(); //st11870 : � faire en dehors ou l�?
         public void bCancel_actionPerformed(){
              escapeActionPerformed();
         private void keyPressed_actionPerformed(KeyEvent ke) {
              if (ke.getKeyChar() == KeyEvent.VK_ESCAPE) {
                   escapeActionPerformed();
              else if (ke.getKeyChar() == KeyEvent.VK_ENTER) {
                   bOK_actionPerformed();
         protected void escapeActionPerformed() {
              isOK=false;
              dispose();
         public float getMaxValue() {
              return maxValue;
         public float getMinValue() {
              return minValue;
    }The problem is that the first time I pass through a textfield, it selects its content. But once, it has been selected, it can't be selected anymore...
    And if I make a setValue() during the initialization, it cannot be selected at all!
    Does anyone know how to fix this?
    Thanks!

    Should work now...
    package cimpa.smartndtkit.dialog;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.text.DecimalFormat;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    public class ChangePaletteLimitsDialog extends JDialog {
         private boolean isOK = false;
         private float minValue, maxValue;
         private JButton bOK, bCancel;
         private JFormattedTextField txtMin, txtMax;
         public ChangePaletteLimitsDialog(JFrame parent, float minValue, float maxValue){
              super(parent, "Modification des limites", true);
              setResizable(false);
              setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              getContentPane().setLayout(new GridBagLayout());
              /** Constantes */
              Insets leftComponentInsets = new Insets(15,30,0,5);
              Insets rightComponentInsets = new Insets(15,5,0,30);
              Insets buttonsInsets = new Insets(8,5,8,5);
              int txtWidth = 60;
              int txtHeight = 22;
              DecimalFormat format = formatFactory("###0.###");
              /** Cr�ation des composants */
              JLabel labelMin = new JLabel("Valeur minimale :");          
              txtMin = new JFormattedTextField(format);
              txtMin.setHorizontalAlignment(JTextField.RIGHT);
              txtMin.setAlignmentX(JTextField.RIGHT_ALIGNMENT);
              txtMin.setSize(txtWidth, txtHeight);
              txtMin.setText(""+minValue);
    //          txtMin.setValue(new Float(minValue));
              txtMin.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent ke) {
                        keyPressed_actionPerformed(ke);
              txtMin.addFocusListener(new FocusAdapter() {
                   public void focusGained(FocusEvent arg0) {
                        txtMin.selectAll();
    //               public void focusLost(FocusEvent arg0) {
    //          txtMin.addActionListener(new ActionListener() {
    //               public void actionPerformed(ActionEvent arg0) {
    //                    txtMin.selectAll();
              JLabel labelMax = new JLabel("Valeur maximale :");
              txtMax = new JFormattedTextField(format);
              txtMax.setHorizontalAlignment(JTextField.RIGHT);
              txtMax.setAlignmentX(JTextField.RIGHT_ALIGNMENT);
              txtMax.setSize(txtWidth, txtHeight);
              txtMax.setText(""+maxValue);
    //          txtMax.setValue(new Float(maxValue));
              txtMax.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent ke) {
                        keyPressed_actionPerformed(ke);
              txtMax.addFocusListener(new FocusAdapter() {
                   public void focusGained(FocusEvent arg0) {
                        txtMax.selectAll();
    //               public void focusLost(FocusEvent arg0) {
    //          txtMax.addActionListener(new ActionListener() {
    //               public void actionPerformed(ActionEvent arg0) {
    //                    txtMax.selectAll();
              JPanel panel = new JPanel();
              bOK = new JButton("OK");
              bOK.setSize(60,25);
              bOK.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent ae) {
                        bOK_actionPerformed();
              bCancel = new JButton("Annuler");
              bCancel.setSize(60,25);
              bCancel.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent ae) {
                        bCancel_actionPerformed();
              /** Contraintes */
              GridBagConstraints constraints = new GridBagConstraints();
              constraints.anchor = GridBagConstraints.CENTER;
              /** Agencement des composants */
              constraints.gridx = 1;
              constraints.gridy = 0;
              constraints.gridwidth = 2;
              constraints.insets = leftComponentInsets;
              getContentPane().add(labelMin, constraints);
              constraints.gridx = 3;
              constraints.insets = rightComponentInsets;
              getContentPane().add(txtMin, constraints);
              constraints.gridx = 1;
              constraints.gridy = 1;
              constraints.insets = leftComponentInsets;
              getContentPane().add(labelMax, constraints);
              constraints.gridx = 3;
              constraints.insets = rightComponentInsets;
              getContentPane().add(txtMax, constraints);
              constraints.gridx = 0;
              constraints.gridy = 0;
              constraints.gridwidth = 1;
              constraints.insets = buttonsInsets;
              panel.add(bOK, constraints);
              constraints.gridx = 1;
              panel.setLayout(new GridBagLayout());
              panel.add(bCancel, constraints);
              constraints.gridx = 0;
              constraints.gridy = 3;
              constraints.gridwidth = 6;
              constraints.anchor = GridBagConstraints.CENTER;
              getContentPane().add(panel, constraints);
              this.pack();
              setLocationRelativeTo(parent);
              txtMin.requestFocus();
    //          getRootPane().setDefaultButton(bOK);
              setVisible(true);
          * @return
         public boolean isOK() {
              return isOK;
         public void bOK_actionPerformed(){
              isOK=true;
              minValue = new Float(txtMin.getText()).floatValue();
              maxValue = new Float(txtMax.getText()).floatValue();
              dispose();
         public void bCancel_actionPerformed(){
              escapeActionPerformed();
         private void keyPressed_actionPerformed(KeyEvent ke) {
              if (ke.getKeyChar() == KeyEvent.VK_ESCAPE) {
                   escapeActionPerformed();
              else if (ke.getKeyChar() == KeyEvent.VK_ENTER) {
                   bOK_actionPerformed();
         protected void escapeActionPerformed() {
              isOK=false;
              dispose();
         public float getMaxValue() {
              return maxValue;
         public float getMinValue() {
              return minValue;
         public static DecimalFormat formatFactory(String pattern){
              DecimalFormat format = new DecimalFormat(pattern);
              DecimalFormatSymbols dfs = new DecimalFormatSymbols();
              dfs.setDecimalSeparator('.');
              format.setDecimalFormatSymbols(dfs);
              return format;
    }

  • How can I set this text in a JformattedTextField ?

    Hi,
    I have a JFormattedTextField with this mask "#####-###"
    When I'm typing It works very fine, but when I call the setText( "12345") It doesn't work, it clears the field.
    If I call setText( "12345-123" ) It work very fine.
    when I don't have all the numbers in the setText() it clears the field.
    Is it a bug ?
    Can someone help me ?
    Thanks.
    wmiro.

    hi,
    the problem is that I'm using this mask "#####-###" to enter the Brazil postal code, we have some cities which every street has a postal code like this:
    A st, postal code 03986-150
    B st, postal code 03986-250
    but we have some other smaller cities which doesn't have a different postal code each street, like this:
    A neighborhood, postal code 05089
    B neighborhood, postal code 05090
    the the user will type only five numbers, the system will accept, but when the user needs to see the information he can't because the setText() fail.
    I've been thinking I must complete with zeros or change the mask to "00000-000".
    Is that the best way to solve this problem ?
    thanks
    wmiro.

  • Introduction to regular expressions ...

    I'm well aware that there are already some articles on that topic, some people asked me to share some of my knowledge on this topic. Please take a look at this first part and let me know if you find this useful. If yes, I'm going to continue on writing more parts using more and more complicated expressions - if you have questions or problems that you think could be solved through regular expression, please post them.
    Introduction
    Oracle has always provided some character/string functions in its PL/SQL command set, such as SUBSTR, REPLACE or TRANSLATE. With 10g, Oracle finally gave us, the users, the developers and of course the DBAs regular expressions. However, regular expressions, due to their sometimes cryptic rules, seem to be overlooked quite often, despite the existence of some very interesing use cases. Beeing one of the advocates of regular expression, I thought I'll give the interested audience an introduction to these new functions in several installments.
    Having fun with regular expressions - Part 1
    Oracle offers the use of regular expression through several functions: REGEXP_INSTR, REGEXP_SUBSTR, REGEXP_REPLACE and REGEXP_LIKE. The second part of each function already gives away its purpose: INSTR for finding a position inside a string, SUBSTR for extracting a part of a string, REPLACE for replacing parts of a string. REGEXP_LIKE is a special case since it could be compared to the LIKE operator and is therefore usually used in comparisons like IF statements or WHERE clauses.
    Regular expressions excel, in my opinion, in search and extraction of strings, using that for finding or replacing certain strings or check for certain formatting criterias. They're not very good at formatting strings itself, except for some special cases I'm going to demonstrate.
    If you're not familiar with regular expression, you should take a look at the definition in Oracle's user guide Using Regular Expressions With Oracle Database, and please note that there have been some changes and advancements in 10g2. I'll provide examples, that should work on both versions.
    Some of you probably already encountered this problem: checking a number inside a string, because, for whatever reason, a column was defined as VARCHAR2 and not as NUMBER as one would have expected.
    Let's check for all rows where column col1 does NOT include an unsigned integer. I'll use this SELECT for demonstrating different values and search patterns:
    WITH t AS (SELECT '456' col1
                 FROM dual
                UNION
               SELECT '123x'
                 FROM dual
                UNION  
               SELECT 'x123'
                 FROM dual
                UNION 
               SELECT 'y'
                 FROM dual
                UNION 
               SELECT '+789'
                 FROM dual
                UNION 
               SELECT '-789'
                 FROM dual
                UNION 
               SELECT '159-'
                 FROM dual
                UNION 
               SELECT '-1-'
                 FROM dual
    SELECT t.col1
      FROM t
    WHERE NOT REGEXP_LIKE(t.col1, '^[0-9]+$')
    ;Let's take a look at the 2nd argument of this REGEXP function: '^[0-9]+$'. Translated it would mean: start at the beginning of the string, check if there's one or more characters in the range between '0' and '9' (also called a matching character list) until the end of this string. "^", "[", "]", "+", "$" are all Metacharacters.
    To understand regular expressions, you have to "think" in regular expressions. Each regular expression tries to "fit" an available string into its pattern and returns a result beeing successful or not, depending on the function. The "art" of using regular expressions is to construct the right search pattern for a certain task. Using functions like TRANSLATE or REPLACE did already teach you using search patterns, regular expressions are just an extension to this paradigma. Another side note: most of the search patterns are placeholders for single characters, not strings.
    I'll take this example a bit further. What would happen if we would remove the "$" in our example? "$" means: (until the) end of a string. Without this, this expression would only search digits from the beginning until it encounters either another character or the end of the string. So this time, '123x' would be removed from the SELECTION since it does fit into the pattern.
    Another change: we will keep the "$" but remove the "^". This character has several meanings, but in this case it declares: (start from the) beginning of a string. Without it, the function will search for a part of a string that has only digits until the end of the searched string. 'x123' would now be removed from our selection.
    Now there's a question: what happens if I remove both, "^" and "$"? Well, just think about it. We now ask to find any string that contains at least one or more digits, so both '123x' and 'x123' will not show up in the result.
    So what if I want to look for signed integer, since "+" is also used for a search expression. Escaping is the name of the game. We'll just use '^\+[0-9]+$' Did you notice the "\" before the first "+"? This is now a search pattern for the plus sign.
    Should signed integers include negative numbers as well? Of course they should, and I'll once again use a matching character list. In this list, I don't need to do escaping, although it is possible. The result string would now look like this: '^[+-]?[0-9]+$'. Did you notice the "?"? This is another metacharacter that changes the placeholder for plus and minus to an optional placeholder, which means: if there's a "+" or "-", that's ok, if there's none, that's also ok. Only if there's a different character, then again the search pattern will fail.
    Addendum: From this on, I found a mistake in my examples. If you would have tested my old examples with test data that would have included multiple signs strings, like "--", "-+", "++", they would have been filtered by the SELECT statement. I mistakenly used the "*" instead of the "?" operator. The reason why this is a bad idea, can also be found in the user guide: the "*" meta character is defined as 0 to multiple occurrences.
    Looking at the values, one could ask the question: what about the integers with a trailing sign? Quite simple, right? Let's just add another '[+-] and the search pattern would look like this: '^[+-]?[0-9]+[+-]?$'.
    Wait a minute, what happened to the row with the column value "-1-"?
    You probably already guessed it: the new pattern qualifies this one also as a valid string. I could now split this pattern into several conditions combined through a logical OR, but there's something even better: a logical OR inside the regular expression. It's symbol is "|", the pipe sign.
    Changing the search pattern again to something like this '^[+-]?[0-9]+$|^[0-9]+[+-]?$' [1] would return now the "-1-" value. Do I have to duplicate the same elements like "^" and "$", what about more complicated, repeating elements in future examples? That's where subexpressions/grouping comes into play. If I want only certain parts of the search pattern using an OR operator, we can put those inside round brackets. '^([+-]?[0-9]+|[0-9]+[+-]?)$' serves the same purpose and allows for further checks without duplicating the whole pattern.
    Now looking for integers is nice, but what about decimal numbers? Those may be a bit more complicated, but all I have to do is again to think in (meta) characters. I'll just use an example where the decimal point is represented by ".", which again needs escaping, since it's also the place holder in regular expressions for "any character".
    Valid decimals in my example would be ".0", "0.0", "0.", "0" (integer of course) but not ".". If you want, you can test it with the TO_NUMBER function. Finding such an unsigned decimal number could then be formulated like this: from the beginning of a string we will either allow a decimal point plus any number of digits OR at least one digits plus an optional decimal point followed by optional any number of digits. Think about it for a minute, how would you formulate such a search pattern?
    Compare your solution to this one:
    '^(\.[0-9]+|[0-9]+(\.[0-9]*)?)$'
    Addendum: Here I have to use both "?" and "*" to make sure, that I can have 0 to many digits after the decimal point, but only 0 to 1 occurrence of this substrings. Otherwise, strings like "1.9.9.9" would be possible, if I would write it like this:
    '^(\.[0-9]+|[0-9]+(\.[0-9]*)*)$'Some of you now might say: Hey, what about signed decimal numbers? You could of course combine all the ideas so far and you will end up with a very long and almost unreadable search pattern, or you start combining several regular expression functions. Think about it: Why put all the search patterns into one function? Why not split those into several steps like "check for a valid decimal" and "check for sign".
    I'll just use another SELECT to show what I want to do:
    WITH t AS (SELECT '0' col1
                 FROM dual
                UNION
               SELECT '0.' 
                 FROM dual
                UNION
               SELECT '.0' 
                 FROM dual
                UNION
               SELECT '0.0' 
                 FROM dual
                UNION
               SELECT '-1.0' 
                 FROM dual
                UNION
               SELECT '.1-' 
                 FROM dual
                UNION
               SELECT '.' 
                 FROM dual
                UNION
               SELECT '-1.1-' 
                 FROM dual
    SELECT t.*
      FROM t
    ;From this select, the only rows I need to find are those with the column values "." and "-1.1-". I'll start this with a check for valid signs. Since I want to combine this with the check for valid decimals, I'll first try to extract a substring with valid signs through the REGEXP_SUBSTR function:
    NVL(REGEXP_SUBSTR(t.col1, '^([+-]?[^+-]+|[^+-]+[+-]?)$'), ' ')Remember the OR operator and the matching character collections? But several "^"? Some of the meta characters inside a search pattern can have different meanings, depending on their positions and combination with other meta characters. In this case, the pattern translates into: from the beginning of the string search for "+" or "-" followed by at least another character that is not "+" or "-". The second pattern after the "|" OR operator does the same for a sign at the end of the string.
    This only checks for a sign but not if there also only digits and a decimal point inside the string. If the search string fails, for example when we have more than one sign like in the "-1.1-", the function returns NULL. NULL and LIKE don't go together very well, so we'll just add NVL with a default value that tells the LIKE to ignore this string, in this case a space.
    All we have to do now is to combine the check for the sign and the check for a valid decimal number, but don't forget an option for the signs at the beginning or end of the string, otherwise your second check will fail on the signed decimals. Are you ready?
    Does your solution look a bit like this?
    WHERE NOT REGEXP_LIKE(NVL(REGEXP_SUBSTR(t.col1,
                               '^([+-]?[^+-]+|[^+-]+[+-]?)$'),
                           '^[+-]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)[+-]?$'
                          )Now the optional sign checks in the REGEXP_LIKE argument can be added to both ends, since the SUBSTR won't allow any string with signs on both ends. Thinking in regular expression again.
    Continued in Introduction to regular expressions ... continued.
    C.
    Fixed some embarrassing typos ... and mistakes.
    cd

    Excellent write up CD. Very nice indeed. Hopefully you'll be completing parts 2 and 3 some time soon. And with any luck, your article will encourage others to do the same....I know there's a few I'd like to see and a few I'd like to have a go at writing too :-)

  • How do I turn off percent symbol in JFormattedTextField

    I am using a custom JFormattedTextField field, that has methods to add masks which apply formatting and add suffix and prefixes.
    It allows the user to see the data in display mode (formatted) or raw (unedited mode)
    Just found a problem though with our display mode when I try and add a suffix of a % symbol after the text.
    It turns out that JFormattedTextField does magic when it sees a %.
    It assumes I want to multiply the data by 100, which I do not. (the data is already stored in terms of percent.)
    I found an ugly hack to solve my problem, which is:
      DecimalFormat displayFormat = new DecimalFormat();
      DecimalFormatSymbols dfs = displayFormat.getDecimalFormatSymbols();
      dfs.setPercent('~'); // set to a symbol we will never use 
      displayFormat.setDecimalFormatSymbols(dfs);
      this.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(displayFormat)));
      // then later we apply our mask
      // used to do this
      // displayFormat.applyPattern(myDisplayFormat);
      // now have to do this so it does not overwrite our percent symbol
      this.displayFormat.applyLocalizedPattern(myDisplayFormat);It seems like there should be an easier way to accomplish this.
    What I was really hoping I could do, is "turn off" the percent substitution functionality.
    i.e. something like displayFormat.disablePercentFormatting(true);
    but at the moment, messing with localised symbols seems like the only way to hack it.
    Anyone have any thoughts? I just want DecimalFormat not to treat a % as a special symbol.
    note:
    Changing the data itself (dividing it by 100) is not an option as the data is entered elsewhere and it would screw up the raw view of the data too.
    Changing the underlying framework (of how we use our display / edit fields and masks etc) is not an option
    as there are hundreds of screens and objects using this framework already with no problems (they dont have a % in their mask though)
    I look forward to bright ideas.
    Cheers,
    - ding

    This behavior is documented in the API of DecimalFormat. If you don't want the special character to be interpreted, you need to quote it:
    Many characters in a pattern are taken literally; they are matched during parsing and output unchanged during formatting. Special characters, on the other hand, stand for other characters, strings, or classes of characters. They must be quoted, unless noted otherwise, if they are to appear in the prefix or suffix as literals. and
    '      Prefix or suffix      No      Used to quote special characters in a prefix or suffix, for example, "'#'#" formats 123 to "#123". To create a single quote itself, use two in a row: "# o''clock". see also: http://download.oracle.com/javase/6/docs/api/java/text/DecimalFormat.html

  • Disappointed with product introduction

    I am new to FrameMaker.  Based on its popularity and others' comments, I'm sure it is a fascinating, feature-packed program that can do a lot for me in my technical writing.  However, I am disappointed with Adobe's lack of introduction to the product.  Any product should come with material that tells me what is special about it and who is meant to use it.  It should also have sample work to show what can be done with the product.  Instead, Adobe begins with a Getting Started with FrameMaker that introduces the user interface and screen basics, which are not yet of concern at this introductory stage.  Note also that there is a section called "What's new in FrameMaker 9", clearly oriented to past users, but totally ignoring the need of new users to learn about the essence of FrameMaker.
    I hope the folks at Adobe are listening and will provide some introductory material.  I would be most thankful for it.

    hmm63 wrote:
    I am new to FrameMaker.  Based on its popularity and others' comments, I'm sure it is a fascinating, feature-packed program that can do a lot for me in my technical writing.  However, I am disappointed with Adobe's lack of introduction to the product.  Any product should come with material that tells me what is special about it and who is meant to use it.  It should also have sample work to show what can be done with the product.  Instead, Adobe begins with a Getting Started with FrameMaker that introduces the user interface and screen basics, which are not yet of concern at this introductory stage.  Note also that there is a section called "What's new in FrameMaker 9", clearly oriented to past users, but totally ignoring the need of new users to learn about the essence of FrameMaker.
    I hope the folks at Adobe are listening and will provide some introductory material.  I would be most thankful for it.
    I agree that it's hard to find good getting started training materials in the FrameMaker package that you buy. Some versions of FrameMaker were shipped with a training disk, or with training materials on the main disk. I'm not sure if recent versions do.
    Recently some Adobe products have come with a 30-day free subscription to Lynda.com online training. Sometimes there's something in the package that tells you about these goodies, and other times you'll get email that tells you about them. You probably have to register your software at Adobe.com. You'll need to create an Adobe user account (free) if you don't have one. The adobe.com site isn't easy to find your way around. On the home page, type register in the search box at the top right, click Product Registration, and the registration log-in page appears. You can create an account if you need to.
    Search Google for terms like "adobe.tv framemaker tutorial," "free online video training framemaker," and "framemaker training resources" without quotes for some good links. These searches include content from the official adobe.com site as well as others.
    Forum participants are users who volunteer to help others in the community, as they've been helped - passing a torch. You're always welcome to post questions here. It's most helpful to would-be helpers if you state the subject of your question clearly, one question or problem per message thread. And, provide your exact version of FrameMaker; it's the version number (like 9.1) and the build number (pxxx) displayed with Help > About FrameMaker.
    And, you can help others who struggle to find good introductory material in the package by posting a formal request at https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform.
    HTH
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices

  • Reg: introduction of DTP and Transformation in BI 7.0

    Hi all,
    I've two questions here one is:
    1. what is the purpose of introduction of DTP with NW 7.0 BI 7.0
    i know the bcoz of these reasons:
    >Improved transparency of staging processes across data warehouselayers
    >Improved performance:Intrinsic parallelism
    >Separation of deltamechanism for differentdata targets: deltacapability is controlledby the DTP..
    >Enhanced filtering indataflow..
    >Repair modus based ontemporary buffers (bufferskeep complete set of data)
    but can any one explain me how this happens in detail.
    coming to my question 2.
    Why transformation replaced tranfer rules and update rules
    (excluing graphical UI)
    Regards
    Ganesh

    >Improved transparency of staging processes across data warehouselayers
    PSA to multiple datatargets allows you transparency and overcomes the spiderweb of export datamart
    >Improved performance:Intrinsic parallelism
    need not have to wait for one infoprovider to load(datamart) to load the consecutive dataprovider  - data can be parallely loaded to different providers at the same time once the data is in PSA
    >Separation of deltamechanism for differentdata targets: deltacapability is controlledby the DTP..
    delta in DTP's is governed by datamart status
    >Enhanced filtering indataflow..
    you can set ur filters independent of any other dataproviders like in datamarts .
    >Repair modus based ontemporary buffers (bufferskeep complete set of data)
    error stack allow you to resurrect the data and load it again
    Why transformation replaced tranfer rules and update rules
    transformations and DTP have 1:1 relationship - so if u pretty sure to use DTP (ur 1st question) - the pre req would be to have transformation - u can create a DTP only after you create a transformation(source and target mapping )

  • Nice introduction's link for this 10g new feature

    As starting point for future discussion in this forum i post a link with a small introduction of Oracle Expression Filter: http://www.oracle.com/technology/oramag/oracle/05-may/o35sql.html
    The official Oracle documentation:
    - Oracle® Database Application Developer's Guide - Expression Filter
    10g Release 1 (10.1):
    http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10821/toc.htm
    - Oracle® Database Application Developer's Guide - Rules Manager and Expression Filter
    10g Release 2 (10.2):
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14288/toc.htm
    I never used this feature before, but I can start now ;-)
    Cheers, Aron

    Thanks Aron. Please let us know how it goes, if you are so inclined.
    There is also a new page on OTN for Expression Filter and Rules Manager resources at
    http://www.oracle.com/technology/products/database/rules_manager/index.html
    Regards,
    Bill Beauregard
    Principal Product Manager
    Message was edited by:
    wbeaureg

  • Info on JFormattedTextField

    Which is the best way to transfer from JFormattedTextField to database. The conventional way of getting Text and inserting into database or Is there any other way where u can connect to database field directly like in VB or any other packages.
    Also based on events like LostFocus of InFocus of JFormattedTextField, I need to write different codes. Where do I get such examples.?

    Strange, until today I do not remember ever hearing about this view before today and now I see two requests for information about this view.
    All I know is that the 11g Reference manual entry for my downloaded version it is devoid of information and does not even show the column datatypes. I had no luck looking on the online docs either.
    Now I am curious.
    Just tagging along to see if anyone knows anything.
    Apparently this undocumented view is related to the AWR.
    -- Mark D Powell --

Maybe you are looking for

  • I have adobe design std. 6 i wanted to install photoshop and acrobat pro on my windows xp sp3

    i have adobe design std. 6 i wanted to install photoshop and acrobat pro on my windows xp sp3. i am not able to install acrobat it is showing folowing error. my email id is [email protected] Exit Code: 6 Please see specific errors and warnings below

  • Need opinions on how to get sketches in Illustrator to become vectors

    Have Illustrator CS6, Medium Baboo tablet. I can draw well but it seems almost impossible to get the quality of my sketch work to go to Illustrator in a way I am happy with. I do not like what I see from scanner to Imagetrace either. This is largely

  • CSS problems in IE

    I am working on a project for a web programming class. The page I created works perfectly in Firefox, Opera, and Safari, but not in IE :-( I explained this to my professor who thankfully said that it was ok if it didn't work in IE (The project involv

  • 9i jdbc driver change causes problems

    Hello all, I was wondering if anyone had any problems with jdbc when migrating to oracle 9i. We are using timestamps from java which were mapped to dates. In oracle there is a function which takes a date. Now this won't work anymore as the mapping ch

  • DVD+-R EUROPE not compatible???

    I have used Imation and Memorex DVD-R's (purchased in the U.S.) successfully on my 17" pbook and the g5 tower. However, the other day I purchased a Verbatim DVD+R (in Europe) and my computer ejects it automatically. I had also purchased previously a