Results 1 to 2 of 2
  1. #1
    asai is offline Senior Member
    Join Date
    Feb 2012
    Rep Power

    Default Get selected row


    I am working on a small program, and I have written most of it and it works pretty good.
    But I want to make it a little more user friendly..

    The program adds, gets and edits data in a MySQL database.
    I have made a jTable that shows the data from one table.
    To add a new entry into the database, I have a button that opens a new window for entering the data. This is ok.
    I also have a button that opens another window for editing. This works somewhat, but the user has to manually enter the ID for the entry that will be edited. What i would like is a way to get the selected row into this edit window.
    I think I am almost there with this code:
    Java Code:
    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
                int selectedRow = jTable1.getSelectedRow();
                int Id = Integer.parseInt(jTable1.getModel().getValueAt(selectedRow, 0).toString());
                PersonEditForm personeditform = new PersonEditForm();
    However I am not sure how to use the selected row in the new window that opens.
    Any pointers would be great!
    Last edited by asai; 06-06-2012 at 05:22 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Get selected row

    Insufficient information for any specific advice, except to recommend that you ditch the visual designer / code generator until you're more proficient in Java and the API.

    To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem. And write the code, don't auto-generate it.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. How to get Line Selected
    By AryanArs in forum New To Java
    Replies: 2
    Last Post: 03-01-2012, 12:50 AM
  2. how to get selected value
    By gedas in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 05-03-2011, 08:08 AM
  3. how to get the currently selected row fo a jtable?
    By kulangotski in forum AWT / Swing
    Replies: 4
    Last Post: 01-16-2011, 06:22 AM
  4. JButton selected
    By sky in forum AWT / Swing
    Replies: 6
    Last Post: 12-05-2009, 10:36 PM
  5. JTable Gridline in selected row
    By arubin in forum AWT / Swing
    Replies: 11
    Last Post: 11-24-2009, 08:05 PM

Posting Permissions

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