How to update jTable from user input?

I create one jTable with 2 rows and 3 columns. the jtable colums contains deviceIP and Status. I am getting device IP from user input through jTextfield. so, when user enter IP and click add button, it must added in the jTable rows one by one.
how can I add it by user enter the IP. Also, I want to update the status column value by "UP" or "DOWN" by just getting string value from other function.
but, my problem is i need to update the correct IP status value to correct column (ie., I want to put IP 1(row 1) status to column 1 in status column list.
I don't know about jTable .
If any one have any examples please give me.

use
((DefaultTableModel)jTable.getModel()).addRow(Object[]);
Object[] is the array of row data values you want to insert;

Similar Messages

  • How to update Records from Internal table to u2018Zu2019 table?

    Hi Friends,
    How to update Records from Internal table to u2018Zu2019 table.
    I have records in Internal table , that records want to update on u2018Zmarau2019 Table.
    ( my internal table & u2018 Zu2019 table structures are same.)
    Thanking you.
    Regards,
    Subash

    Hi,
    loop at internal table.
    modify <Z- table > from values < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    endloop.
    or
    UPDATE <Z- table > from table < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    Prabhudas

  • HT1338 how to update software from 10.5 to 10.7?

    how to update software from 10.5 to 10.7?

    You need to buy a Mac OS X 10.6 DVD from the online Apple Store, and phone them and order a download code for Mac OS X 10.7. Mac OS X 10.7 requires a Mac with a Core 2 Duo(not Core Duo) or better CPU and at least 2GB of RAM.
    (77981)

  • How i can show the user input in alv list on the top

    hi all,
                   please tell me how i can show the user input in alv list on the top.
                         and  also tell me how i  can hide the toolbar in alv.
    regards
    vikas saini

    Hi,
    Use the Below Code.
    form top_of_page.                                          
      data : it_header type slis_t_listheader,
             is_header type slis_listheader.
      is_header-typ  = c_h.
      is_header-key  = space.
      is_header-info = 'Pending Order Information Report'(018).
      append is_header to it_header.
      call function 'REUSE_ALV_COMMENTARY_WRITE'
        exporting
          it_list_commentary = it_header.
    endform.                    "top_of_page
    and finally pass it to .
    call function 'REUSE_ALV_GRID_DISPLAY'
          exporting
            i_callback_program     = sy-repid
            i_callback_top_of_page = 'TOP_OF_PAGE'
    call function 'REUSE_ALV_GRID_DISPLAY'
          exporting
            i_callback_program     = sy-repid
            i_callback_top_of_page = 'TOP_OF_PAGE'
    Regards.
    Arbind

  • How to check the value from user input in database or not?

    Hello;
    I want to check the value of user input from JtextFiled in my database or not.
    If it is in database, then i will pop up a window to tell us, otherwise, it will tell us it is not in database.
    My problem is my code do not work properly, sometimes, it tell me correct information, sometime it tell wrong information.
    Could anyone help,please.Thanks
    The following code is for check whether the value in database or not, and pop up a window to tell us.
    while( rs.next()) {
                    System.out.println("i am testing");
                    bInt=new Integer(rs.getInt("id"));
                    if(aInt.equals(bInt)){ // If i find the value in data base, set flag to 1.
                  flag=1;  //I set a flag to check whether the id in database or not
                        break;
             System.out.println("falg" + flag);
                if(flag==1){ //?????????????????????
              String remove1 = "DELETE FROM Rental WHERE CustomerID=" + a;
              String remove2 = "DELETE FROM Revenus WHERE CustomerID=" +a;
              String remove3 = "DELETE FROM Customer WHERE id=" +a;
              s.executeUpdate(remove1);
              s.executeUpdate(remove2);
              s.executeUpdate(remove3);
                    JOptionPane.showMessageDialog(null,"you have success delete the value");
              s.close();
             else//???????????????????????????????
                  JOptionPane.showMessageDialog(null,"I could not found the value"); -------------------------------------------------------------------
    My whole program
    import java.sql.*;
    import java.awt.BorderLayout;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JOptionPane;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class DeleteC extends JFrame
        public static int index=0;   
        public static ResultSet rs;
        public static Statement s;
        public static Connection c;
        public static  Object cols[][];
        private static JTable table;
        private static JScrollPane scroller;
        private static int flag=0;
        public DeleteC()
            //information of our connection
            //the url of the database: protocol:subprotocol:subname:computer_name:port:database_name
            String strUrl      = "jdbc:oracle:thin:@augur.scms.waikato.ac.nz:1521:teaching";
            //user name and password
            String strUser      = "xbl1";
            String strPass      = "19681978";
            //try to load the driver
            try {
                Class.forName("oracle.jdbc.driver.OracleDriver");
            catch (ClassNotFoundException e) {
                System.out.println( "Cannot load the Oracle driver. Include it in your classpath.");
                System.exit( -1);
            //a null reference to a Connection object
            c = null;
            try {
                //open a connection to the database
                c = DriverManager.getConnection( strUrl, strUser, strPass);
            catch (SQLException e) {
                System.out.println("Cannot connect to the database. Here is the error:");
                e.printStackTrace();
                System.exit( -1);
           //create a statement object to execute sql statements
        public void getData(String a){
            try {
             //create a statement object to execute sql statements
             s = c.createStatement();
                int index=0;
                Integer aInt= Integer.valueOf(a);
                Integer bInt;
                  //our example query
                String strQuery = "select id from customer";
                //execute the query
                ResultSet rs = s.executeQuery( strQuery);
                //while there are rows in the result set
                while( rs.next()) {
                    System.out.println("i am testing");
                    bInt=new Integer(rs.getInt("id"));
                    if(aInt.equals(bInt)){
                  //JOptionPane.showMessageDialog(null,"I found the value"); 
                  flag=1;
                        break;
             System.out.println("falg" + flag);
                if(flag==1){
              String remove1 = "DELETE FROM Rental WHERE CustomerID=" + a;
              String remove2 = "DELETE FROM Revenus WHERE CustomerID=" +a;
              String remove3 = "DELETE FROM Customer WHERE id=" +a;
              s.executeUpdate(remove1);
              s.executeUpdate(remove2);
              s.executeUpdate(remove3);
                    JOptionPane.showMessageDialog(null,"you have success delete the value");
              s.close();
             else
                  JOptionPane.showMessageDialog(null,"I could not found the value");
            catch (SQLException e) {
                 JOptionPane.showMessageDialog(null,"You may enter wrong id");
    My main program for user input from JTextField.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.util.*;
    public class EnterID extends JFrame{
        public JTextField tF1;
        public EnterID enID;
        public String tF1Value;
        private JLabel label1, label2, label3;
        private static JButton button;
        private static ButtonHandler handler;
        private static String aString;
        private static Integer aInteger;
        private static Integer checkV=0;
        public static void main(String args[]){
           EnterID eId= new EnterID();
       public EnterID(){
          handler=new ButtonHandler();
          Container c= getContentPane();
          c.setLayout(new GridLayout(3,1));
          button= new JButton("ok");
          button.addActionListener(handler);
          label1 = new JLabel(" CustomerID, Please");
          label2 = new JLabel("Label2");
          label3 = new JLabel();
          label3.setLayout(new GridLayout(1,1));
          label3.add(button);
          label2.setLayout(new GridLayout(1,1));
          aString = "Enter Id Here";
          tF1 = new JTextField(aString);
          label2.add(tF1);
          c.add(label1);
          c.add(label2);         
          c.add(label3);            
          setSize(150,100);
          setVisible(true);     
       private class ButtonHandler implements ActionListener{
         public void actionPerformed(ActionEvent event){
             tF1Value=tF1.getText();
            //   CheckData cData = new CheckData();
             //  aInteger = Integer.valueOf(tF1Value);      
             if(tF1Value.equals(aString)){
              JOptionPane.showMessageDialog(null,"You didn't type value into box");
              setVisible(false); 
            else {
                DeleteC dC= new DeleteC();
                dC.getData(tF1Value);
                setVisible(false); 
    }

    You may have working code now, but the code you posted is horrible and I'm going to tell you a much much much better approach for the JDBC part. (You should probably isolate your database code from your user interface code as well, but I'm skipping over that structural problem...)
    Do this instead:
        public void getData(String a){
            PreparedStatement p;
            String strQuery = "select count(*) the_count from customer where id = ?";
            try {   
             //create a prepared statement object to execute sql statements, it's better, faster, safer
             p = c.prepareStatement(strQuery);
                // bind the parameter value to the "?"
                p.setInt(1, Integer.parseInt(a) );
                //execute the query
                ResultSet rs = p.executeQuery( );
                // if the query doesn't throw an exception, it will have exactly one row
                rs.next();
                System.out.println("i am testing");
                if (rs.getInt("the_count") > 0 ) {
                // it's there, do what you need to...
             else
                  JOptionPane.showMessageDialog(null,"I could not find the value");
            catch (SQLException e) {
                 // JOptionPane.showMessageDialog(null,"You may enter wrong id");
                 // if you get an exception, something is really wrong, and it's NOT user error
            // always, always, ALWAYS close JDBC resources in a finally block
            finally
                p.close();
        }First, this is simpler and easier to read.
    Second, this retrieves just the needed information, whether or not the id is in the database. Your way will get much much slower as more data goes into the database. My way, if there is an index on the id column, more data doesn;t slow it down very much.
    I've also left some important points in comments.
    No guarantees that there isn't a dumb typo in there; I didn't actually compile it, much less test it. It's at least close though...

  • How to calculate the total from users input in switch?

    I dont know how to hold the input from user. But here is part of my coding :
    System.out.println ("Type 1 for buying Ruler"+
    "\nType 2 for buying Pencil");
    stationaries = console.nextInt();
    switch (stationaries)
    case 1 : System.out.println("Ruler per unit : MYR1");
    System.out.println("How much does you want? : ")
    wantRuler = console.nextInt();
    sum = wantRuler * 1;
    break;
    case 2 : System.out.println("Pencil per unit : MYR2");
    System.out.println("How much does you want? : ")
    wantPencil = console.nextInt();
    sum = wantPencil * 2;
    break;
    How can I calculate the total for both of the stationaries if user wants 5 for ruler and 6 for pencil?

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.

  • Update JTable from a JDialog

    I'm wanting to update a JTable I have on a JFrame. This JFrame has a button on it which opens a JDialog box which populates a database. The main JFrame's JTable (ReceivedTable) holds this information. When a user inputs some more information and closes the dialog, I'd like to update the JTable in the main JFrame, but am not sure how to go about doing this. Can someone give me an idea to work from.
    Thanks.

    G'day mate,
    Make an extension of JDialog like so:
    //import appropriate classes here
    public class MyDialog extends JDialog implements ActionListener {
         //you would have some text fields or such here
         public MyDialog(Frame parent, String name) {
              super(parent, name, true);
              JPanel cp = (JPanel)getContentPane();
              //cp.add(fields here!);
              JButton submit = new JButton("Submit");
              submit.addActionListener(this);
              cp.add(submit);
         public void actionPerformed(ActionEvent ae) {
              Vector data = new Vector();
              //populate 2d data vector with data for the table
              Vector column_names = new Vector();
              //names for your table columns
              ((DefaultTableModel)((JFrame)getOwner()).getTable().getModel()).setDataVector(data, column_names);
              dispose();
    Note: In your JFrame you will need to define a method getTable().
    I think that should work for you... Obviously you'll have to add in a lot of code yourself, but that should be a reasonable skeleton.
    Good luck,
    Muel.

  • How to update attributes from OIM to AD in case of LDAPSync

    Hi All,
    In our scenario, we have LDAPSync configured for OIM AD Integration. OIM version is OIM 11gR2 PS1 (11.1.2.1.0.0)
    It is working fine and On user creation in OIM ,RealTime user creation under specified container in AD is happening.It is SSL enabled,so password is also getting updated from OIM to AD.
    But we have following conflicting scenario --
    -   As per our requirement we have to generate random password for User in OIM. For that we have PostProcess event handler implemented in OIM.
    - We have tested LDAPSync by creating user manually through OIM console. While creating user manually, we have provided value for password attribute along with other attributes.
        So, password attribute in AD will get updated for User along with all other attributes values mapped for AD from OIM.
    - But, in our scenario random password is generated for User through OIM post process event handler and it will be updated again in user profile of user created manually in OIM. This password is sent to User through mail.
      As this password event handler will get triggered after LDAPSnyc only, this password will not be update in AD for manually created user in OIM. So he can log into OIM with this new password but not to AD system.
      He will be able to login to AD system with same User ID but with password which was set at time of manual User Creation in OIM and not with the password updated in OIM user profile by PostProcess event handler.
    Is it possible to set password for user through PreProcess even handler implementation for Random Password generation. In this case also , the default OIM post process
    password generator will override the PreProcess event handler.How to resolve this issue.
    Also,when AD connector is in place in OIM environment we would be having change/update tasks for any attribute update to be send from OIM to AD.
    How this update scenario will be implemented from OIM to AD in case of LDAPSync ?
    Please provide any helpful pointer on this.
    Thanks,
    RPB

    Password :
    Increase order of calling for custom password event handler than OOTB handler.
    Update:
    you wanted to update custom fields?
    Did you check default update tasks comes with connector?

  • How can I make my user input on the same line as the question?

    The only way I know of doing it is
    System.out.println ("Please enter an uppercase letter of the English Alphabet: ");
              letter = dataIn.readLine ();But that makes Please enter an uppercase letter of the English Alphabet:
    **User input here, a line down**So how can I make it all fit into one line with this sort of layout:
    Please enter an uppercase letter of the English Alphabet:  **USER INPUTS HERE, SAME LINE**

    change your call from println to print.
    check the API docs for this stuff, it tells you everything you need to know.
    Good Luck
    Lee

  • Update infotype from user exit

    Hi,
    My requirement is to update a infotype from a user exit. I have a internal table with some records created in the user exit pbas0001. Now i need to update these records in the infotype 2001(absences). I tried using HR
    INFOTYPEOPERATIONS directly from the user exit and it didn't work. If i create a include program and create a subroutine within the include program and call it in the user exit still i am getting a error message. How can update the infotype from the user exit.
    Can someone send the example code for how to export the internal table from the user exit and import it in another program and update the infotype from that prgm.

    Put the entire code in another Report & SUBMIT that report from the User exit.. this will isolate the two work processes & the Z table should get updated..
    ~Suresh

  • How to Read string from keyboard input??

    Hi,
    I am writing an application that requires the user to input string
    text. I have declared a variable String[] SData. The user will enter
    several words in a line of string, and I want to be able to split
    these and assign it to different variables, e.g. A= SData[1]
    My problem is how do you assign the SData to what is being inputted?
    I was using SData = System.in.read()
    But I got a type compatibility error.
    Is there another way I can get user input into a string?
    Does anyone have any ideas? Any help would be greatly appreciated.
    Thank you.

    Is there another way I can get user input into a
    string?
    KeyboardInput
    Adapted from Jacquie Barker's "Beginning Java Objects" (2002)
    pp. 324 - 325
    To use, in main():
    KeyboardInput k = new KeyboardInput();
    k.readLine();
    To get the input stored in k,
    k.getKeyboardInput();
    import java.io.*;
    class KeyboardInput
    //User input is saved in this string
    private static String keyboardInput;
    public String readLine()
    char in;
    // Clears previous input
    keyboardInput = "";
    try
    // Read one integer and cast it into a character.
    // Keeps going until a newline character is read.
    do
    in = (char) System.in.read();
    keyboardInput = keyboardInput + in;
    } while ( in != '\n' );
    catch (IOException e)
    // Reset the input
    keyboardInput = "";
    System.out.print("\n\nError in reading keyboardInput: \n" +
    e + "\n\n");
    // Strips off any leading and/or trailing whitespace
    keyboardInput = keyboardInput.trim();
    // Return the complete String;
    return keyboardInput;
    } // End String readLine()
    public String getKeyboardInput()
    return keyboardInput;
    } // End String getKeyboardInput()
    } // End class KeyboardInput

  • How to update JTable when clicking outside the table?

    Hi
    (Sorry if this has been asked before but I can't seem to see exactly how to do this from previous posts.)
    I have a JTable which sits on a jPanel which itself is part of a frame.
    When I click anywhere outside the table when I'm editing a cell in the table, how do I end the edit mode of the table (so that the cell is updated with the new contents).Currently I can only update a cell's contents during edit when hitting 'enter' or by clicking on another cell within the table.
    It seems that the following code is used in the process but I'm sure that I'm still missing something:
    if(table1.getCellEditor()!=null)
    table1.getCellEditor().stopCellEditing();
    If anyone out there knows how to do this,I'd really appreciate hearing how.
    Thanks a lot
    LGS

    Thanks for your comments but I'm still having problems.
    When I add the following code:
    table1.addFocusListener(new java.awt.event.FocusAdapter()
    public void focusLost(java.awt.event.FocusEvent evt)
    if (table1.getCellEditor() != null)
    table1.getCellEditor().stopCellEditing();
    and then try to edit my table,as soon as I double click on any cell in the table,my setValueAt method in my Table Model is being called before I even edit the cells contents. The above code is in the same method in which I actaully create table1 i.e.createTable().
    Can anyone help?

  • Updating JTable From List

    hi all
    i am having trouble updating a jtable from a list.
    the table is declared as follows
    //TableTracks.java
    String[] columnNames = {"Track Number",
      "Mute",
      "File/Track Name",
      "Number of Loops",
    Object[][] data = {
    {"1", "0", "", "1" , },
    {"2", "0", "", "1" , },
    {"3", "0", "", "1" , },
    {"4", "0", "", "1" , },
    {"5", "0", "", "1" , },
    {"6", "0", "", "1" , },
    {"7", "0", "", "1" , },
    {"8", "0", "", "1" , },
         final JTable table = new JTable(data, columnNames);I would like to select a value in a List by using the arrow keys, then when pressing enter key the selected List value appears in a cell in the table.
    The list works fine for me, i get a Listvalue string from the following method
    //Part of FileList.java
    //tableTracks class constructor
    TableTracks tableTrack = new TableTracks();
    public void keyReleased(KeyEvent e) {
    switch(e.getKeyCode()) {
    case KeyEvent.VK_ENTER:
       value = jlst.getSelectedValue().toString();;
       if (value.endsWith(".wav"))
       iNameLen = value.length();
       value = value.substring(iEntryType,iNameLen);
       System.out.println("sending..... " + value);
       tableTrack.insertValue(value);
       break;
    }So far so good! in the above i call the insertValue method and below is that method
    //TableTracks.java
    void insertValue(String file)
      System.out.println("insertVal: " + file);
       table.setValueAt(file, 3, 3 );
    }in both of the system.out.println statements in the above 2 methods, the correct value is displayed. But it simply will not display the vlaue in the table.
    Before i added the List option to my program, i had it working by allowing the user to select a file name using a FileChooser. With this method, the table.setValue worked fine. But now, it will not.
    Any help or suggestions would be very greatly appreciated.
    cheers
    RC

    You probably defined the "table" variable twice. Once as a class variable and once as a local variable and your "insertValue" method is referring to the wrong variable and therefore updating the wrong table.

  • Hashmap from user input

    I am writing a battleship program and I have created an array of xycoordinates in my board class, in my player class i created a method to accept user input for an xy coordinate to place the ship. In my game class (where the main method is in) I want to be able to put this coordinate in the ship hashmap with the ship name.
    I am not sure how to get the user input from my method in the player class to the hashmap in the game class.

    I was originally calling this method when the player selected to play the game. I have created the method in my player class:
    public String placeBships() {
              System.out.println("Enter xy coordinates for: Battleship");
              Scanner blocationxy = new Scanner(System.in);
              String bxycoordinate;
              bxycoordinate = blocationxy.next();
              System.out.println("You Chose " + bxycoordinate);
              return bxycoordinate;
    how do make it return to the Game class?
    I am not sure how to load it to my hashmap "ships". I tried ships.put(myplayer.placeBships());

  • Slow response from user input

    Hi.
    I have a very strange problem with some of my clients. Sometimes they experience a huge delay between key pressed on keyboard and actual character printed on monitor. So there is a simple text item involved and when the user starts typing the delay could be two or even three seconds between user input (each character) and actual forms displaying it.
    First I suspected network contention but I am not quite sure if there is any network traffic (client browser -> application server) involved while user is typing text into text item. Next I tried to monitor clients machine processes (like anti virus program) but no luck. I have also tried various JRE versions but again no luck.
    I am using 11.1.2.1 version of forms with Mozilla and JRE 1.6.35 on client side.
    Does anybody have/had similar experience? Any suggestion in helping resolving the issue appreciated.
    Also I am really curious what is happening (is there any network traffic involved) while user is typing text into text item where there is no trigger on that item except when_validate_item.
    Best regards.

    Also I am really curious what is happening (is there any network traffic involved) while user is typing text into text item where there is no trigger on that item except when_validate_item.Unless you have implemented a Java Bean on the item to monitor the keystrokes in the field, no events are trigger by the act of typing characters in a field. The act of typing characters in a field occurs completly on the client - no network traffic at this point. Only when a field event occurs (navigation away from the item) will an event occur that would cause network communication between the client and the appilcation server.
    Sometimes they experience a huge delay between key pressed on keyboard and actual character printed on monitor. I encountered something similar to this with a user once who complained about how slow the application ran on their computer. The slowness was intermitant and there was no apparent pattern. Like you, I looked at JRE and other things. Finally, told the user to call me when the slowness occured so I could come look at the computer while it was occuring. Turns out, the user had at least 30+ applications running at the same time. The workstation was running Windows XP with 2gb Ram. Looking at their system resources, there was no memory available and the pc was memory thrashing really bad. I had the user close all but the absolute necessary programs and our Forms application started responding quickly again. After a little user education - miraculously, the slowness problem went away. :)
    Craig...

Maybe you are looking for