Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: get value from jTable to jDateChooser

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default get value from jTable to jDateChooser

    how to get value from jTable?
    i use mouse click event for my jtable and then, i want to set value to datechooser

    usually my behaviour for get value from jTable to Textfield, i'm using this method
    txtNamaKlien.setText(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(), 1)));
    and then value from jTable success fill to textfield.

    my problem value from jTable not success fill to jdatechooser, i'm using this method
    Date tanggal = (Date) jTable1.getValueAt(jTable1.getSelectedRow(), 2);
    jDateChooser1.setDate(tanggal);

    and i'm get an error

    java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date

    How to fix that?
    i'm using database mySQL

    when inserting data, i use this method
    java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd");
    String formattedDate1 = fmt.format(jDateChooser1.getDate());

    please help me, and sorry for my bad english


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: get value from jTable to jDateChooser

    As the error says you cannot just cast a String to a Date you need to create a Date object from the String. I see the code at the bottom uses a SimpleDateFormat. Hmmm how can that help?
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: get value from jTable to jDateChooser

    Quote Originally Posted by Junky View Post
    As the error says you cannot just cast a String to a Date you need to create a Date object from the String. I see the code at the bottom uses a SimpleDateFormat. Hmmm how can that help?
    how implementation create a Date object from the String from my code?
    can you help me?

    i'm using this method
    jDateChooser1.setDate((java.util.Date) jTable1.getValueAt(jTable1.getSelectedRow(),2));

    and this

    jDateChooser1.setDateFormatString((String) jTable1.getValueAt(jTable1.getSelectedRow(),2));

    cannot work too
    Last edited by bhapux; August 12th, 2014 at 09:36 PM.

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: get value from jTable to jDateChooser

    I did. Read above post again. It tells you which class to use.
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: get value from jTable to jDateChooser

    Quote Originally Posted by Junky View Post
    I did. Read above post again. It tells you which class to use.
    i'm using jCalendar
    pattern jDateChooser dd MMM yy

    which post you mean?

  6. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: get value from jTable to jDateChooser

    The invisible one!
    Improving the world one idiot at a time!

  7. #7
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: get value from jTable to jDateChooser

    Quote Originally Posted by Junky View Post
    The invisible one!
    invisible one? :s

    sorry i'm newbie
    Last edited by bhapux; August 12th, 2014 at 10:25 PM.

Similar Threads

  1. Replies: 1
    Last Post: February 5th, 2014, 09:22 AM
  2. Help me please, Jtable
    By mazaoa in forum AWT / Java Swing
    Replies: 1
    Last Post: December 9th, 2012, 09:16 AM
  3. Replies: 21
    Last Post: November 27th, 2012, 10:58 PM