Results 1 to 4 of 4
Like Tree3Likes
  • 3 Post By JosAH

Thread: Need Help With Jtable :(

  1. #1
    arunvdev123 is offline Member
    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Unhappy Need Help With Jtable :(

    friends i'm new to java, i need to do a form for attendance registration using a table, need to place a jcheckbox in the last column, i just cant figure out a way to do so, i got some working codes by googling, but its too complex to understand, it will be a lot helpful if you could help


    Here's the code

    import java.awt.Checkbox;
    import java.awt.Color;
    import java.awt.Component;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellEditor;

    /**
    *
    * @author arun
    */
    public class DailyAttendance extends javax.swing.JFrame {

    /**
    * Creates new form DailyAttendance
    */

    final DefaultTableModel model;
    JCheckBox checkBox = new javax.swing.JCheckBox();
    dbconn db=new dbconn();

    //private final JTable table;

    public DailyAttendance() throws SQLException {

    final String[] columnNames = {"Batch", "Student Name", "Present"};

    String s="select * from studentreg where batch='it'";
    ResultSet rs=db.resultset(s);
    //Object[][] data = {};
    Object[][] data = new Object[2][3];
    model = new DefaultTableModel(data, columnNames);

    /*
    dataModel.addRow(
    new Object[] {"", "", "", new Integer(0), new Boolean(false)}

    */
    while(rs.next())
    {
    model.addRow(new Object[]{ rs.getString("batch"), rs.getString("sname"), new JCheckBox()});

    // table.add("","" new PriceColumnGenerator());
    //table.addContainerProperty("myprop", Component.class, null);

    // Item kk = table.getItem(ii);
    //data [0][2]= new JCheckBox();

    //model.addRow(new Object[]{data});




    //table.getColumnModel().getColumn(2).… CheckBoxCellEditor());

    //model.addRow(data);
    }
    //JCheckBox.setSelected(((Boolean) value).booleanValue()) ;
    // table.getColumn(2).setCellEditor(new DefaultCellEditor(checkBox));

    initComponents();

    }

    public static void main(String args[]) {
    /*
    * Set the Nimbus look and feel
    */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /*
    * If Nimbus (introduced in Java SE 6) is not available, stay with the
    * default look and feel. For details see
    * How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)
    */
    try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAn… {
    if ("Nimbus".equals(info.getName())) {
    javax.swing.UIManager.setLookAndFeel(i…
    break;
    }
    }
    } catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(Dai… null, ex);
    } catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(Dai… null, ex);
    } catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(Dai… null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelExcep… ex) {
    java.util.logging.Logger.getLogger(Dai… null, ex);
    }
    //</editor-fold>

    /*
    * Create and display the form
    */
    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {
    try {
    new DailyAttendance().setVisible(true);
    } catch (SQLException ex) {
    Logger.getLogger(DailyAttendance.class… null, ex);
    }
    }
    });
    }
    // Variables declaration - do not modify
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable table;
    // End of variables declaration
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Need Help With Jtable :(

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

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Need Help With Jtable :(

    Quote Originally Posted by arunvdev123 View Post
    friends i'm new to java, i need to do a form for attendance registration using a table, need to place a jcheckbox in the last column, i just cant figure out a way to do so, i got some working codes by googling, but its too complex to understand, it will be a lot helpful if you could help
    So let me get this right -- you're asking us to help fix "found" code that you don't understand?

    I strongly urge you not to go this route as it will cause nothing but frustration in you and in us. Instead I suggest that you learn how to use JTables and their models by studying the JTable tutorial, and then try to write your own code to solve this and not use borrowed code. Then if you are still having problems, show us your code, ask your questions, and we'll be able to better have an intelligent discussion and be better able to help you.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,996
    Blog Entries
    7
    Rep Power
    19

    Default Re: Need Help With Jtable :(

    The moment I see imports from SQL stuff and Swing stuff for one single class I go "nah, that needs better refactoring".

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Jtable inside Jtable
    By anchitanc in forum AWT / Swing
    Replies: 5
    Last Post: 05-26-2012, 08:10 PM
  2. Replies: 4
    Last Post: 04-02-2012, 07:57 PM
  3. Adding New JTable in JTable
    By anilkumar_vist in forum New To Java
    Replies: 0
    Last Post: 01-27-2010, 08:27 AM
  4. Regarding the JTable
    By suresh.uvce in forum AWT / Swing
    Replies: 5
    Last Post: 02-11-2009, 06:46 AM
  5. Replies: 2
    Last Post: 05-15-2008, 10:15 AM

Tags for this Thread

Posting Permissions

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