Validation of JTextField to accept negative and positive values

Hi,
I have a question. I have a jTable populated with the fieldname
in the first column and datatype in the second column.
I would like to place a JTextField component in the frame
depending on the data type. So, if a row is selected in the table, the
datatype of that fieldname is retrieved and depending on that data type
I want a JTextField to be displayed.
Now, if the data type is of Integer type, I want the JTextfield to
accepts Integers only(positive). I have created a class that extends JTextfield.
But, I want the text field to accept negative integers also. Can anyone please guide me ?

Hi,
I wrote an extension of JTable that provides better rendering and editing support for:
Color
Font
Locale
Integer
int
Long
long
Short
short
Byte
byte
BigInteger
Double
double
Float
float
BigDecimal
and some more
To allow only positive values for the type integer you could use:
JXTable myTable = new JXTable(...);
myTable.setDefaultEditor(Integer.class, new IntegerCellEditor(0, Integer.MAX_VALUE, <some locale>));The number editors are based on JFormattedTextField.
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JXTable.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/IntegerCellEditor.html
Homepage:
http://www.softsmithy.org
Download:
http://sourceforge.net/project/showfiles.php?group_id=64833
Source:
http://sourceforge.net/cvs/?group_id=64833
For more information about the number fields have a look at he following thread:
http://forum.java.sun.com/thread.jspa?threadID=718662
-Puce

Similar Messages

  • BEx Analyzer - Aggregation of Negative and Positive Values

    Hello Gurus,
    I have a key figure 0Subtotal1. This KF contains both negative and positive figures.
    For eg; +10, -20, -30.
    In Query Analyzer, I need the column total as 60 and not
    -40.
    Can I use a formula and use the ABS function...
    Any clue....
    thanks in advance.

    hi BW,
    u can make -ve sign as positive in the query.
    Go to query properties in the query designer, then click on display tab->there u will find in the number format block settings for the display of -ve numbers....u can change them to positive there...
    reward if it helps,
    ajay

  • StackedBarChart stacked bar corrupted when add negative and positive value.

    When StackedBarChart series have (positive & negative) data stacked bar corrupted and loss data.
    I have a chart with data stacked on (-,+)Y-Axis.
    - With JfreeChart all this go rigth and data appear perfectly on each bar without loss.
    - But when using javafx StackedBar Chart , when bar series have (positive & negative) data stacked bar corrupted and loss data.
    Stackoverflow link : http://stackoverflow.com/questions/15410153/javafx-stackedbar-chart-issue .

    As stated in your StackOverflow post, you should file this as a bug on Jira.
    But I'd also point out that stacked bar charts with negative values are not a good idea. In a stacked bar chart, the highest point of the stack should represent the total of the individual bars. You lose this property if there are negative values, and the chart becomes misleading. (I'd bet that the cause of the bug is that the code assumes this property at some point.)

  • Negative  values in red and Positive values in black CONDITIONAL FORMATTING

    Hi ... Everyone
    I have to show Negative values in red and Positive values in black in one of my report.
    i tried these conditions
    1. <?if:GAIN<0.00?><?attribute@inlines:color;'red'?><?end if?>
    but it shows negative values only in red ,positive values in black are missing
    2. <?if:GAIN<0.00?><?attribute@incontext:color;'red'?><?end if?><?if:GAIN>0.00?><?attribute@incontext:color;'black'?><?end if?>
    This gives the exact result what i wanted ...but the problem is i have five tables in my report ... so the above condition only allow changes in ONE TABLE ONLY. :(
    Plzzzz anyone who can help me to sort out my problem or else SUGGEST ANOTHER WORKING CONDITION
    Regards
    Subham Mittal

    Subham,
    This should not be difficult and moreover the BI Publisher Desktop installation comes with a set of examples:
    Start -> Programs -> BI Publisher Desktop -> Samples -> RTF Templates -> Advanced -> Conditional
    There you can find two templates with the exact same situation like yours, highlighting either the foreground color or background color.
    regards
    Jorge

  • Wat should be data type for  negative and decimal values (eg: -1.2222)

    What should be data type for  negative and decimal values (eg: -1.2222)

    Hi
    U can use the data type DEC while creating the DOMAIN and in the domain u  have sign check box at the left corner of the screen, click that check box , u can assign negative values for the field which refers this domain.
    REWARD IF HELPFULL
    Anees.

  • JTextField:  How to selectAll() AND Position Cursor at Beginning of Text

    Hi All,
    I have a problem with when a JTextField is selected, I cannot simultaneously selectAll() and position the cursor at the beginning of the text. (selectAll() positions the cusror at the end of the selected text, not the beginning, which is what I require).
    Does anyone have a solution for this as I haven't found an answer as of yet.
    Many thanks.

    Thanks uncle_alice, but as far as I have determined, the setCaret() and selectAll() methods are mutally exclusive. Why do people ask for help and then disagree with the answer given?
    Thanks uncle_alice, I tried the code and it works.It amazes me that it took half an hour to "try" the code. Why not try the code first, ask a followup question later if it doesn't work? Why do we have to waste time resonding to a question twice, just to get you to try the code?

  • Validating a JTextField having a float or double value.

    Hello,
    I need help in validating a JTextfield which will accept a float or double value because it the deposit field and it shouldn't be of length more than 7 before the decimal and 2 after the decimal.That is it should be of length 10.I have written the following code for the validation.
    txtDeposit.addKeyListener(new KeyAdapter(){
    //Accept only integer value
              public void keyTyped(KeyEvent e){
              char c = e.getKeyChar();
    if((txtDeposit.getText()).length() == 10)
              if (!(Character.isDigit(c)))
              if(!Character.isISOControl(c))
              getToolkit().beep();
              e.consume();
              });//end of txtDeposit*/
    Please help.

    use javax.swing.InputVerifier
    import java.awt.BorderLayout;
    import java.awt.Toolkit;
    import javax.swing.InputVerifier;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    public class VerifyInput extends JFrame {
        public VerifyInput(){
            super("Input Verifier");
            this.setSize(200, 200);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JTextField txt = new JTextField();
            txt.setInputVerifier(new CheckInput());
            this.getContentPane().add(txt, BorderLayout.NORTH);
            JButton btnMoveFocus = new JButton("CLick");
            this.getContentPane().add(btnMoveFocus, BorderLayout.SOUTH);
        public static void main(String[] args) {
            VerifyInput f = new VerifyInput();
            f.setVisible(true);
        class CheckInput extends InputVerifier{
            private int lengthBeforeDot = 7;
            private int lengthAfterDot = 2;
            public CheckInput(){
            public CheckInput(int lengthBeforeDot, int lengthAfterDot){
                this.lengthAfterDot = lengthAfterDot;
                this.lengthBeforeDot = lengthBeforeDot;
            public boolean verify(JComponent input) {
                boolean correct = true;
                try {
                    JTextField tField = (JTextField) input;
                    String text = tField.getText();
                    if(text.length() == 0){
                        return true;
                    if ((correct = isDoubleOrFloat(text))) {
                        correct = isFormatCorrect(text);
                } finally {               
                    if(!correct){
                        Toolkit.getDefaultToolkit().beep();
                        System.out.println("Not Correct");
                    }else{
                        System.out.println("Correct");
                return correct;
            private boolean isDoubleOrFloat(String text){
                try{
                    Double.parseDouble(text);
                }catch(NumberFormatException nfe){
                    return false;
                return true;
            private boolean isFormatCorrect(String text){
                int dotIndex = text.indexOf('.');
                if(dotIndex < 0){
                    return text.length() <= lengthBeforeDot;
                String beforeDecimal = text.substring(0, dotIndex - 1);
                if(beforeDecimal.length() >= lengthBeforeDot){
                    return false;
                String afterDecimal = text.substring(dotIndex + 1);
                if(afterDecimal.length() > lengthAfterDot){
                    return false;
                return true;
    }

  • Object Size and Position values not being retained

    Hi,
           I'm trying to set the size and position of a picture object in a report. This logo, should appear on the top right corner of the report.
    The margins of the report are Left - .79 in, Right - 0.79 in, Top - 0.79 in and Bottom - 0.39 in.
    The size of the picture object should be 1.574 x 0.79 inches.
    I have ensured that File -> Page Setup -> dimensions are in INCHES.
    I right click the logo and select 'Size and Position'.
    I set 'Y' (distance between top of object and top margin) = 0. This is to perfectly align the object with the top margin.
    Now, i set the height of the object = 0.79 inches. Ok the dialog and close.
    The strange thing happening is, when i re-open the size and position dialog, i see that the values i set are not being retained.
    0.79 becomes 0.810
    and
    0 become -0.010.
    What am i doing wrong here? How can i make sure the values i specify in the size and position dialog are  retained.
    Thanks.

    Ensure File | Options | Layout tab has the following UNMARKED!!!!
    Design View
      Guidelines
      Grid
    Preview
      Guidelines
      Grid
    Ensure that "Snap to Grid" is turned off.
    Make your grid size larger (.5 inches for example)
    What is occurring (I suspect) is that your objects are snapping to the grid - thus changing the position and possibly size due to the Snap to Grid being turned on.

  • Why Illustrator change entered size and position values?

    Hy All!
    Illustrator 5.5 always change my entered size or position values.
    (For example: I type 10mm, hit enter, and 10 changed to 10,231mm.)
    I checked again and again, but I have no any enabled snap function.
    I have Illustrator CS6 too, what works fine (but much slower).
    Checked all my setting about 5 times, still didn't find the solution...
    Thank you for your tips!
    (MBP 17", C2D 2,5GHz, 4Gb RAM, Mac OS X 10.6.8.)

    The measurement you type in defines the frame of your shape. The new measurement you see includes the width of the stroke.
    Under your Illustrator preferences, if you uncheck "use preview bounds", it will leave your measurements as you typed them, but it will not include the width of any stroke that is aligned to center or outside of your box.

  • Grid Y negative and positive chaged in CS5

    I know there is another thread with discussion on why different programs have the y axis inverted, which is fine.  The problem is that all previous versions of Illustrator have your zero point as it would be on a normal mathmatical grid.  Why now after 7 years of using Illustrator must I "rethink" how I am moving objects.  We create dielines and now if I am placing my measurement text and callouts on the top and bottom, we have to do the opposite of what we did for all of these years.  Not to mention artwork placement.  Why is there not an option?  This is pathetic on Adobe's part.  Someone please tell me there is an option to invert the now inverted Y axis.

    What Monika said.
    Here it is:
    To change the ruler origin in CS5 to be the same as in CS4 and earlier, you may:
    1)  Find and open the AIPrefs (Win speak) or Adobe Illustrator Prefs (Mac  speak) file; it is a hidden file in the hidden folder Adobe Illustrator  CS5 Settings
    2): Find and change the following two bits of code:
    /isRulerOriginTopLeft 1 >>> /isRulerOriginTopLeft 0 (change 1 to 0)
    /isRulerIn4thQuad 1 >>> /isRulerIn4thQuad 0 (change 1 to 0)
    Note: This is a global change.

  • GeoRaster querying returns negative and invalid cell coordinates

    Hi!
    I'm using Oracle 10.2.0.1 and loading raster data into GeoRaster - loading all works but when querying cell coordinates I get negative and unexpected values. Here is my process:
    -- Create GeoRaster table
    DROP TABLE tm;
    CREATE TABLE tm (id NUMBER, description VARCHAR2(50), image SDO_GEORASTER);
    -- Create trigger to keep metadata up to date
    EXECUTE sdo_geor_utl.createDMLTrigger('TM', 'IMAGE');
    -- Create raster data table
    DROP TABLE tm_rdt;
    CREATE TABLE tm_rdt OF SDO_RASTER
    (PRIMARY KEY (rasterID, pyramidLevel, bandBlockNumber, rowBlockNumber, columnBlockNumber))
    TABLESPACE tbsp
    NOLOGGING LOB(rasterBlock)
    STORE AS lobseg (TABLESPACE tbsp CHUNK 8192 CACHE READS NOLOGGING PCTVERSION 0 );
    -- Grant privs on file locations
    exec dbms_java.grant_permission( 'PUBLIC', 'SYS:java.io.FilePermission', 'D:\Users\tm.tif','read,write' );
    exec dbms_java.grant_permission( 'TEST', 'SYS:java.io.FilePermission', 'D:\Users\tm.tif','read,write' );
    exec dbms_java.grant_permission( 'MDSYS', 'SYS:java.io.FilePermission', 'D:\Users\tm.tif','read,write' );
    exec dbms_java.grant_permission( 'PUBLIC', 'SYS:java.io.FilePermission', 'D:\Users\tm.tfw','read,write' );
    exec dbms_java.grant_permission( 'TEST', 'SYS:java.io.FilePermission', 'D:\Users\tm.tfw','read,write' );
    exec dbms_java.grant_permission( 'MDSYS', 'SYS:java.io.FilePermission', 'D:\Users\tm.tfw','read,write' );
    -- Initialise GeoRaster object and import image
    DECLARE
    l_gr SDO_GEORASTER;
    BEGIN      
    -- Initialise GeoRaster objects
    INSERT INTO tm (id, description, image)
    VALUES (1, 'TM', sdo_geor.init('TM_RDT'));
    -- Import the images
    SELECT image INTO l_gr FROM tm WHERE id = 1 FOR UPDATE;
    SDO_GEOR.IMPORTFROM(l_gr, 'spatialExtent=true', 'TIFF', 'file', 'D:\Users\tm.tif', 'WORLDFILE', 'file', 'D:\Users\tm.tfw,3035');
    UPDATE tm SET image = l_gr WHERE id = 1;
    COMMIT;
    END;
    DECLARE
    gr sdo_georaster;
    BEGIN
    SELECT image INTO gr FROM tm WHERE id = 1 FOR UPDATE;
    sdo_geor.setModelSRID(gr, 3035);
    gr.spatialExtent := sdo_geor.generateSpatialExtent(gr);
    UPDATE tm SET image = gr WHERE id = 1;
    COMMIT;
    END;
    The raster file was originally a .MAP file which I converted to a .TIF file via ArcCatalog 9.2.
    I created a World File whose contents are:
    5000
    0
    0
    -5000
    -1697500
    2697500
    The .MAP file and .TIF file have the following Spatial Reference (Oracle SID 3035):
    PROJCS["PCS_Lambert_Azimuthal_Equal_Area",GEOGCS["GCS_User_Defined",DATUM["D_User_Defined",SPHEROID["User_Defined_Spheroid",6378388.0,0.0]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Azimuthal_Equal_Area"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Latitude_Of_Origin",48.0],UNIT["Meter",1.0]
    In the Raster file:
    Columns, Rows = 680, 810
    Number of Bands = 1
    Cellsize = 5000,5000
    Extent Top = 2700000
    Extent Left = -1700000
    Extent Right = 1700000
    Extent Bottom = -1350000
    Origin Location = Upper Left
    So, loaded the raster into Oracle all ok; but when I try and find the cell coord for a real-world coord in WGS84 (location of a point in Iceland), it returns invalid cell coords:
    SELECT     sdo_geor.getCellCoordinate(t.image, 0, SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(-19.4833, 64.6833, 0), NULL, NULL))
    FROM      tm t;
    Returns: SDO_NUMBER_ARRAY(-443, 930) which isn't a true cell coord in my raster??
    Also, if I test out to get the corners of the raster:
    SELECT sdo_geor.getCellCoordinate(image, 0, sdo_geometry(2001, 3035, sdo_point_type(1700000,2700000,null), null,null)) FROM tm WHERE id=1;
    Should return the top right corner at (680,0), it actually returns: SDO_NUMBER_ARRAY(0, 680) - the other way round?!?!
    I'm slowing going mad on this, so any ideas/thoughts would be greatly appreciated!!!

    Hi,
    I just did some test. The results you got actually was right. The point (-19.4833, 64.6833, 0) you give is in 8307. After it is transformed into coordinate system 3035, the system your georaster in. We get the model coordinates (2954416.89, 4914665.16, 0). The model coordinate of your up-left corner cell of your georaster is (-1697500, 2697500), so the cell coordinates of the give point is col = int((2954416.89 - (-1697500))/5000) = int(930.38) = 930, and row = int((4914665.16 - 2697500)/(-5000)) = int(-443.43) = -430. That is what you got. The point you give is outside of your georaster on the top.
    SQL> select sdo_cs.transform(
    sdo_geometry(2001, 8307, SDO_POINT_TYPE(-19.4833, 64.6833, 0), null,null),
    3035) from dual; 2 3
    SDO_CS.TRANSFORM(SDO_GEOMETRY(2001,8307,SDO_POINT_TYPE(-19.4833,64.6833,0),NULL,
    SDO_GEOMETRY(2001, 3035, SDO_POINT_TYPE(2954416.89, 4914665.16, 0), NULL, NULL)
    For point (1700000,2700000,null), it is at the top-right corner. Its cell coordinates should be (0,680). Be noticed, the cell coordinates has order of ROW, COLUMN.
    Please let me know if you have further question.

  • How can I put validation for JTextField when gotfocus and lostfocus

    Hi,
    How can I put validation for JTextField when gotfocus and lostfocus ?
    Thanks
    Wilson

    You add a focusListener to the control you wish to monitor. In the focusLost() handler you do whatever, in the focusGained() handler you do whatever.

  • What is False negative and False positive

    Hi Gurus,
    What is False negative and False positive?
    what situations they will arises and what is the impact on database/cube?
    Give me some examples.

    yes, one of my friend has across this question in an interview.
    the interviewer has explained like this:
    Occasionally, some times clean blocks are marked as dirty,this is called false negative
    and dirty blocks are marked as clean status is called as false positive.
    I would like to know when this situation arises and what is the impact on the database/cube.

  • Numbers do not accept negative values after upgrading to Snow Leopard

    I have iWork 9 installed in Leopard, and after upgrading to Snow Leopard, Numbers don't accept negative values, e.g. -141. They are defined as text and are aligned left in the cell, even if the cell is defined for numbers. Positive values are defined as numbers and aligned right.
    All my statistics are wrong now. I don't where to find a sollution. Need to fix this asap.

    I may guarantee that the cell contains a standard minus symbol.
    I entered in the Index.xml to see if something was odd.
    All is perfect.
    I can't imagine that the OP replaced deliberately a wrong char by a correct one before sending the file to my mailbox.
    And I repeat,
    (1) in the file which I received, the cell was really treated as a text one.
    (2) on my machine, on the OP's alternate machine, on the OP's alternate user account, resetting the cell's status to numbers apply well.
    So, if a third party component is the culprit, it would be easy to identify: it must be in one of the user account able to receive third party items which means
    <userAccount>:Applications
    <userAccount>:Library:Address Book Plug-Ins
    <userAccount>:Library:Fonts
    <userAccount>:Library:Contextual Menu Items
    <userAccount>:Library:LaunchAgents
    <userAccount>:Library:PreferencesPanes
    <userAccount>:Library:Scripting Additions
    <userAccount>:Library:Services
    <userAccount>:Library:Widgets
    But from my point of view it would be more efficient to try to search a culprit in the
    <userAccount>:Library:Caches folder.
    An efficient tip would be to compress every subfolder of this folder as a .zip file and trash the original file.
    Reboot so that the account restarts without the caches.
    If th account continue to fail, my idea was bad.
    If it behaves well, the culprit was one of the caches.
    unpack them one by one so you will get the wrongdoer.
    Yvan KOENIG (VALLAURIS, France) mardi 8 septembre 2009 18:50:27

  • I have a valid Serial # for Adobe Acrobat XI, and it shows on my account, but when I try to install it seem to automatically go to "Pro" and says that my Serial # is invalid.  I need this right away!!!!  How can I fix this???

    I really need help with this!  I have a valid Serial # for Adobe Acrobat XI and it shows on my account with Adobe.  When I try to install on my new hard drive it says that the serial # is invalid..  I tried to install the free version to get me out of a jam and it keeps saying that it failed!!!!  What can I do?

    I am on Windows 7, and I was on Adobe.com.  I went to downloads and clicked on Acrobat XI standard.  It downloaded.  But when I went to run it said Acrobat XI Pro and would not accept my serial number.  I have done this now 4 times.  I think that the system is downloading the wrong version.  I am getting very frustrated and unhappy with Adobe!!!!
    Sent from my iPad

Maybe you are looking for