Results 1 to 3 of 3
  1. #1
    abhiN is offline Member
    Join Date
    Jan 2008
    Posts
    23
    Rep Power
    0

    Default Passing data from one JFrame to another

    Hi

    I am developing an application in which i want to pass the data from one JFrame to another..

    Actually what i want is like--

    On my first frame i m displaying a blank JTable(Table1)..
    Now when i click on the first row from the table1 it'll generate new frame containing a JTable(table2) with the values from the database..

    Now i want to pass the values from the table2 to table1 dynamically.. means when i double click on any row from table2, all data from that row will be added to 1st row in table1..

    weather it is possible to pass the data in such a manner or is there any another way to pass data from one frame to another..

    plz reply..
    thanks..

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    There may be a lot of ways to put something like this together. In general it is better to have only one JFrame and to use JDialogs for additional top–level containers.
    Java Code:
    class Frame1
        JTable table
    
        Frame1() {
            table.addMouselistener(listener);
            show table in frame
        }
    
        private MouseListener listener = new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                Point p = e.getPoint
                int row = table.rowAtPoint(p);
                int col = table.columnAtPoint(p);
                openDialog(row, col);
            }
        };
    
        private void openDialog(int row, int col) {
            JTable localTable = new JTable
            localTable.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    if(e.getClickCount == 2) {
                        int row = localTable.getRowAtPoint(e.getPoint())
                        collect row data from localTable
                        set data in table
                    }
                }
            ));
            populate table with data base data for row/col
            show table in JDialog/JFrame
        }
    }

  3. #3
    abhiN is offline Member
    Join Date
    Jan 2008
    Posts
    23
    Rep Power
    0

    Default

    Thanks hardwired for reply.

    According to ur code it'll generate the table with values from DB by clicking on row in table1, but how do I get the values from the database table(table2) to my current table(table1).

    I want to get the entire row from the table2,on which user will double click to be get added to table1...
    weather it is possible??

    plz reply..
    thanks..

Similar Threads

  1. Passing a value..
    By Lagarto in forum New To Java
    Replies: 3
    Last Post: 01-23-2011, 05:58 PM
  2. JNI - passing and returning parameters by value
    By java_to_c in forum New To Java
    Replies: 0
    Last Post: 01-31-2008, 08:49 PM
  3. passing data dynamically
    By abhiN in forum Advanced Java
    Replies: 1
    Last Post: 01-22-2008, 09:43 AM
  4. passing dynamic data
    By abhiN in forum Web Frameworks
    Replies: 0
    Last Post: 01-17-2008, 01:16 PM
  5. Passing the Values
    By Lagarto in forum JDBC
    Replies: 1
    Last Post: 07-16-2007, 03:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •