Validate user-entered text in JTable

How do I validate user entered text in JTable cell, so only the values 1234567890. are acceptet? The cell should contain only doubles....

import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class aslan extends JFrame {
  public aslan() {
    TableModel model = new CustomTableModel();
    JTable table = new JTable(model);
    getContentPane().add(new JScrollPane(table), "Center");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(300,200);
    setLocation(300,300);
    setVisible(true);
  private class CustomTableModel extends AbstractTableModel {
    String[] headings = new String[] {
      "Cost", "Item", "Type"
    Object[][] data = new Object[][] {
      { new Double(12.75), "glue",   "tube" },
      { new Double(15.20), "hammer", "claw" },
      { new Double(8.32),  "saw",    "hack" }
    public int getRowCount() {
      return data.length;
    public int getColumnCount() {
      return data[0].length;
    public Object getValueAt(int row, int column) {
      return data[row][column];
    public void setValueAt(Object value, int row, int column) {
      data[row][column] = value;
      fireTableDataChanged();
    public String getColumnName(int column) {
      return headings[column];
    public Class getColumnClass(int column) {
      return data[0][column].getClass();
    public boolean isCellEditable(int row, int column) {
      return true;
  public static void main(String[] args) {
    new aslan();
}

Similar Messages

  • Validating User Entered text inside jtable

    I have a editable jtable.My problem is validation of user entered text.
    I know how to validate integer text but I want to validate string.such as no special chars are there,and field shud be not null.and as long as text is not valid focus is restricted to that column only.
    Any body having any idea abt this.plz do help me.

    Well you really have 2 requirements:
    such as no special chars This can be edited as the character is typed. You create a custom editor the uses a text field with a DocumentFilter. Then you can edit the text as it is typed. Read the Swing tutorial on "Text Component Feature" for an example of using a DocumentFilter:
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html
    field shud be not nullThis needs to be edited when you leave the cell. So you will need a custom editor. This posting has an example that should help you:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=575309

  • User entered text in a Report..

    For the Report that I am generating, most of the data will come from user entered text like descriptions and policies.
    I am thinking that the best way to do this, is use a Java GUI, and have this GUI prompt the user for all user entered data to be included in the report, and then have the GUI make an http call to rwcgi60.
    Is this the best approach?

    hello,
    well, this is one way todo it. you could also create a forms or portal-forms application to enter the data, save it into a database table and then invoke the report.
    that mainly depends on the requirements for your application.
    regards,
    the oracle reports team

  • User entered text at the bottom of my report

    Hi SDN
    I Need user entered text at the intial variable screen should come in my out put of the report as comment at the bottom
    Thanks,
    Chinna.

    which front end tool you want to use to create the report
    we have query designer, report designer, WAD, crystal reports and many?
    I am not sure that with query designer you will be able to acahieve it. But sure that not a straight forward soltuion.
    With report designer, and crystal reports, you can easily achieve it, it seems.

  • How i can validate a entered text against regular expressions ?

    Thank you for reading my post.
    how i can validate an entered text to checkk its syntax to ensure that it is a domain name ?
    I think i should use RE , but i do not know how i can do this.
    Thank you

    If you want to validate at client side, you need to create a javascript function (validation) and add it to the "onBlur" attribute of the TextField component In the propertysheet (Set it via JavaScrip->onBlur in the property sheet). To put the Actual Java Script, you need to edit the JSP page. If you need to do it server side, create a custom validator.
    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/customvalidator.html
    - WInston
    http://blogs.sun.com/winston

  • Interactive Report - comparing user entered text field against a table field - the comparison is not finding a hit when it should.

    Example
    User enters 12345 in a pre filter ----- item_number field and this value exist in the table but its defined as VARCHAR2(2000).
    No match is found.  Do I need to define this text field in a certain way so that a match occurs - say in the element or source for P1_ITEM_NUMBER.
    How does a user entered value of 12345 match a value in the table of 12345 - defined as a varchar2(2000).
    Thanks  

    Why are you storing numbers in a varchar2?
    This is bad designing.  (storing date information in a varchar2 field is even worst.)
    99% of the time, when the number 12345 does not match the string '12345', it is because the value in the table is actually '                         12345'
    Run the following SQL command in the SQL workshop.  (you'll need to adjust to match schema,table,column names)
    select item_number, length( item_number) as string_length
    from schema_name.table_name
    If '12345' does not have a string_length of 5, then you have bad data in your database.

  • Can you create a user entered text field that flows content in a subform?

    I am working on a conversion project taking a document library of over 600 forms from Word into PDF, for the most part it's simple and binding fields to the database schema and using subforms is working quite well - however, there are some instances where there is a combination of user entered fields mixed with database fields and in some cases the end user fields are all there are but the amount of content can vary from 250 characters to thousands.  The project manager wants a PDF that enables users to enter whatever amount of text they need to and have the form layout function the way it does as if all fields were populated by the database - I don't know of a way to make that work unless content is entered in the schema first (or implement CM and have all users working in LiveCycle, but the database uses PDF, sothat's not an option right now).
    If anyone has any ideas how to make these things work I would greatly appreciate hearing about it.
    Thank you so much,
    R

    Hi,
        If you can post your form in the post, I can have a look at it and provide my feedback.
        I created a sample file for your reference..
        1) The Content property for the Page1 was set to Flowed.
        2) Each text box is placed inside a Subform which is also has the content property set to Flowed.
        3) In the Form Properties, under the Default tab, set the PDF render format as Dynamic XML form.
        4) In the Form Properties, under the Preview tab, set the Preview Type as "Interactive Form" and Preview Adobe XML Form as "Dynamic XML form". (this step is for the previewing the PDF in the designer).
        5) Finally save the form as Dynamic XML form. (File Menu -> Save As).
    Hope this helps.
    If you still have issues, please post your form..
    Thanks
    Srini
    Please find the sample file at the below location
    https://acrobat.com/#d=qQohvZGsJrky-sTdPTJbzA

  • Placing fonts in a JEditorPane after user enters text in a text field

    Hello all,
    I am writing a chat application that enables me to place fonts in a JEditorPane.
    The user will write the text in a text field and when the user press the enter key and whatever is written on the text field will be shown on the JEditorPane along with the choosen font.
    The only thing I can acomplish now is getting the font's to change inside the text field.
    But I want the text to be send to the JEditorPane look like the choosen font that is set by the user after the user presses the enter key.
    Does anybody here know how to do that? And can you give me some samples so I may be able to work on it?

    When you insert the new text in the JEditorPane, you can do it using the insertString method of the editor pane's Document instance. This method allows you to pass an AttributeSet which can be used to pass the correct font. This is all well explained in the following tutorial :
    http://java.sun.com/docs/books/tutorial/uiswing/components/text.html

  • Entering Text in JTable

    Hi Every body
    I am bit new with using JTable, actually my problem is I want to develop a JTable in which number of rows can grow inadvertly during user entry. can anybody please please suggest me a right approach..b'coz I am bit confused with that..
    Thanks in advance

    One way to do this is to place two buttons "ADD ROW" and "DELETE ROW" near your table.
    The first would add a row, either at the end of the table or after the current row. The second would delete the current row, if a row is selected.
    When the add button is pressed you will need to:
    1) create a new data element for your table. This is dependent on your table model and how your table data is represented. But if your table holds an instance of class A in each row, create a new object of class A and add it to your table data vector.2) tell the table model that the number of rows has increased.
    3) Tell the table to update it's view. This can be done with a fireTableDataChanged() event.
    The delete button behaves similiarly except for decreasing elements.
    hope this helps,
    Terry

  • User entered Text in out put of report

    Hi Gurus....
    I am using WAD my user wants to input some comment while executing the report or after executing report .....
    user will take print out with that comment and send to seniors........
    Please help me i am strugling for past 2 weeks its urjent.......
    Thanks.....
    Chinna

    Hi,
    If its dynamic message just like current date..you have to include one text variable and you can use the same variable in the your template (WAD ). if its standard message (just like always fixed..name..etc). you can include a text box in your template and you hard code that text box.
    Please go through for more detials: http://help.sap.com/saphelp_nw70/helpdata/en/2a/2da2394fbf4e6ae10000000a11402f/frameset.htm
    hope its clear..
    Thanks,
    Ashok

  • How to get the user entered  header text on a delivery

    Hi All,
    I am looking for a internal table which holds the user entered text in header text of the delivery. I was able to find header data in XTHEAD table. But actual lines(entered text)  in which structure it holds. I checked TLINETAB but its empty.
    My requirement is to check the user enterd text to validate at userexi_save .
    Any help will be appreciated
    Thanks
    Sai.

    Hi all,
    Thanks for ur replies.
    I already tried READ_TEXT. but its not giving the current value.
    check the following code:
            CLEAR lv_valid.
            READ TABLE catalog
                  INTO ls_catalog
                  WITH KEY tdobject = c_vbbk1
                             tdname = likp-vbeln
                               tdid = c_z043.
            IF sy-subrc = 0.
              CHECK ls_catalog-function NE 'D'.
              CALL FUNCTION 'READ_TEXT'
                EXPORTING
                  id                      = ls_catalog-tdid
                  language                = ls_catalog-tdspras
                  name                    = ls_catalog-tdname
                  object                  = ls_catalog-tdobject
                TABLES
                  lines                   = lt_tline
                EXCEPTIONS
                  id                      = 1
                  language                = 2
                  name                    = 3
                  not_found               = 4
                  object                  = 5
                  reference_check         = 6
                  wrong_access_to_archive = 7
                  OTHERS                  = 8.
              IF sy-subrc = 0.
                CLEAR lv_valid.
                READ TABLE lt_tline INTO ls_tline INDEX 1.
                CALL METHOD z2cl_utilities=>is_valid_text
                  EXPORTING
                    p_text  = ls_tline-tdline
                  IMPORTING
                    p_text1 = lv_text1
                    p_text2 = lv_text2
                    p_valid = lv_valid.
                IF lv_valid IS  INITIAL.
                  MESSAGE e504(z2vl) WITH lv_text1 lv_text2.
                ENDIF.

  • How can I read the last cell of a JTable that a user Enters data

    I have a one column JTable with several rows that a user enters data to. Upon entering the last data, the user clicks a button to read all the data from the rows in the JTable and puts them in an arraylist. If the user does not click enter or navigates away from the last cell, then after clicking the button it does not read the last cell entered. Since the user is clicking on a button to indicate he is done entering data on the table, does he also have to hit the enter key to indicate he is done entering the data?
    The code below is my tablemodelListener:
    public class InteractiveTableModelListener implements TableModelListener {
    public void tableChanged(TableModelEvent evt) {
    if (evt.getType() == TableModelEvent.UPDATE) {
    int row = evt.getFirstRow();
    System.out.println("Update row:"+" "+row);
    jTable1.setRowSelectionInterval(row, row);
    }

    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
    In the future, Swing related questions should be posted in the Swing fourm. (This question has been asked and answered dozens of times).
    But there is not need to repost because [Table Stop Editing|http://www.camick.com/java/blog.html?name=table-stop-editing] explains whats happening and give a couple of solutions.

  • ADD ITEMS TO DROPDOWN BOX FROM A TEXT FIELD(USER ENTERS THE ITEM) AND BOUND VALUE ALSO

    I WANT TO ADD ITEMS  THE DROPDOWN BOX FROM THE TEXT FIELD(ITEM NAME) WHERE USER ENTER'S THE ITEM DESCRIPTION
    AND BOUND VALUE ALSO SHOULD BE ADDED TO THE SAME ITEM.
    SAME WAY REMOVE ITEMS FROM DROPDOWN BOX
    PLEASE GIVE SAMPLE FORM OR JAVASCRIPT FOR THE ABOVE SCENARIO.....
    INDEED HELPFUL FOR MY PROJECT PLEASE SEND ATTACHED PDF FORM

    Hi Praveen,
    Your form is not shared so I have not been able to access it.  But I have updated mine.  There are now two approaches, one that follows on from the above method and updates each drop down list in each row.  The second updates a separate dataset that the drop down list is bound to.  This second approach requires the remerge() method which can cause problems if your code has updates some form properties like a borders color as these will be reset, but the code is simplier and you will only have one list to maintain.  The add button click code is;
    var particulars = xfa.datasets.resolveNode("particulars");
    if (particulars === null)
        particulars = xfa.datasets.createNode("dataGroup","particulars");
        xfa.datasets.nodes.append(particulars);    
    var particular = xfa.datasets.createNode("dataValue","particular");
    particular.value = ItemName.rawValue;
    var boundValue = xfa.datasets.createNode("dataValue","id");
    boundValue.value = BoundValue.rawValue;
    particular.nodes.append(boundValue);
    boundValue.contains = "metaData";
    // find sorted position to insert
    for (var i = 0; i < particulars.nodes.length; i++)
        p = particulars.nodes.item(i);
        if (p.value > particular.value)
          particulars.nodes.insert(particular, p);       
                 break;
    // add to end if greater than all existing items
    if (particular.parent === null)
        particulars.nodes.append(particular);
    // clear source fields
    ItemName.rawValue = null;
    BoundValue.rawValue = null;
    // remerge form data to pick up new item
    xfa.form.remerge();
    And the binding looks like;
    I have updated my sample to include both methods, https://workspaces.acrobat.com/?d=OwysfJa-Q3HhPtFlgRb62g
    Regards
    Bruce

  • How to Get User entered value in a text variable

    Hi,
    I have made a text variable to show the user entered value in the column header.
    The user enteres value in a formula variable ABC whose default value is say '30'.
    I am using customer exit to capture this value in the text variable. The code is as follows
    IF i_vnam EQ 'txtvar'.
    if i_step = 2.
    LOOP AT i_t_var_range INTO loc_var_range
    WHERE vnam = 'ABC'.
    CLEAR l_s_range.
    l_s_range-low = loc_var_range-low.
    l_s_range-opt = 'EQ'.
    l_s_range-sign = 'I'.
    APPEND l_s_range TO e_t_range.
    EXIT.
    ENDLOOP.
    endif.
    endif.
    Now when I am executing the query I am getting the default value in the column header i,e, 30. But when the user changes this default value to something else while executing the query, I simply get blank in the column. The changed value is not getting captured in the text variable.
    Thanks

    Hi,
    Insted of  going for exit,
    just create a Text variable proceesing typr Default/ Manual Entry and set the default value as u wish,
    use it in the KF header; dont use the same Text Variable for Query Title.
    Now i tried this for you and it is working fine.
    Regards
    ReddY A

  • Allowing users to enter text into a web page

    Hi there,
    I'm not at all versed in Java, so I would like some advice on how to do the following in a web page.
    Imagine you have a group of four users and they have to be able to give you a response to a question and be able to see what the others have responded.
    Basically I want the users to be able to to enter text into the webpage, so that the question can be changed and also so that each person can change their reply (in a space under their name.)
    It would also be acceptable if the text was from a predetermined list, ie a drop down list which has a "memory"
    Any ideas would be most welcome, thanks in advance!
    -Ekipero-

    Hi again,
    I think I didn't explain myself clearly enough.
    Basically, all I need is a text box which can be edited by anyone who visits the webpage, and which once edited has a "memory" so the next person who visits the page can see what the person before wrote.
    I don't know any Java but I'm sure an applet to do this can't be too difficult right?
    Perhaps doing it through a text box and a Submit button which then pastes what has been written in the text box onto the page? Or perhaps the text can be chosen from a predetermined list?
    Thanks in advance to all ;-)
    -Ekipero-

Maybe you are looking for

  • Cannot connect to app store after updating to mavericks

    First time I've had to post here, never had a problem before. Couple days ago it pops up that I have an update to mavericks for my macbook pro. Go ahead and install it and all the sudden I can't connect to the app store. I click the sign in button an

  • What's wrong with my connection driver?

    I'm have a jsp page that doesn't get the data from the database. According to it's caught exception , I must implement a suitable driver.Tha problem is: I have tried 2 type of mysql drivers ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource" and "org.gj

  • How to convert date (dd/mm/yyyy) to week no. calendar?

    hi all, I have a question about if user enters 12/12/2004(dd/mm/yyyy), which week is that? I just know week no. should from 01 to no more than 53. How to convert date to week no.? Thanks

  • IBCM SCCM 2012 r2 DO WE HAVE TO OPEN PORT 8531 IN EXTERNAL firewall

    Hi All IBCM SCCM 2012 r2 DO WE HAVE TO OPEN PORT 8531 IN EXTERNAL firewall for our site syatem in DMZ with role MP,sup &DP

  • Imac and ipad music transfer

    i have a mac and ipad. i have some playlists and music on my iPad but am concerned if i sync them will lose music on my ipad ie it wil be overwritten by what is on imac. is that so?