Results 1 to 2 of 2
  1. #1
    ashim is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Unhappy checkBox with jtable and mysql

    checkBox with jtable and mysql-page.png

    I have created a table which is being populated at runtime from a database.
    The first column contains check boxes and all db name which is coming from database, but the the checkbox are not visible.
    value is shown true/false. I want the checkbox to be displayed with a check n uncheck option.

    This is my code:-

    import java.sql.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.TableColumn;

    public class AccessPermission_db {
    public static void main(String[] args) {
    Vector columnNames = new Vector();
    Vector data = new Vector();
    JCheckBox chk = null;
    JPanel panel = new JPanel(); //
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    Connection con = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/solr_search", "root", "root");
    String sql = "SHOW DATABASES";
    Statement statement = con.createStatement();
    ResultSet resultSet = statement.executeQuery(sql);
    ResultSetMetaData metaData = resultSet.getMetaData();
    int columns = metaData.getColumnCount();
    for (int i = 1; i <= columns; i++) {
    columnNames.addElement(metaData.getColumnName(i));

    }
    columnNames.addElement("Permission");
    while (resultSet.next()) {
    Vector row = new Vector(columns);
    String[] row1=new String[columns];
    for (int i = 1; i <= columns; i++) {
    row.addElement(resultSet.getObject(i));
    // row.addElement("Test");

    //new Boolean(true);
    //JFrame frame = new JFrame("Check Box Frame");
    //chk = new JCheckBox();


    //frame.add(chk);
    //frame.setSize(400, 400);
    //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    //frame.setVisible(true);

    }
    row.addElement(new Boolean(false));
    // data.addElement( row );
    data.addElement(row);
    }
    resultSet.close();
    statement.close();
    } catch (Exception e) {
    System.out.println(e);
    }
    JTable table = new JTable(data, columnNames);
    TableColumn column;
    for (int i = 0; i < table.getColumnCount(); i++) {
    column = table.getColumnModel().getColumn(i);
    column.setMaxWidth(250);
    }
    JScrollPane scrollPane = new JScrollPane(table);
    panel.add(scrollPane);
    JFrame frame = new JFrame();
    frame.add(panel); //adding panel to the frame
    frame.setSize(600, 400); //setting frame size
    frame.setVisible(true); //setting visibility true
    }
    }

    Please help me by writing and modifying the code.. I am very new in java programming.

    Thank you...

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

    Default Re: checkBox with jtable and mysql

    Quote Originally Posted by ashim View Post
    Please help me by writing and modifying the code.. I am very new in java programming.
    No, this is a forum -- not a code factory. How do you expect to ever learn stuff if others write your code for you?

    Override getColumnClass(...) for the table or its model to return Boolean.class for the column that holds true/false data.

    Also, go through BB Code List - Java Programming Forum and edit your post accordingly.

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

Similar Threads

  1. Checkbox editor for JTable column
    By ShamPhadtale in forum AWT / Swing
    Replies: 12
    Last Post: 10-11-2011, 05:38 PM
  2. Disable a checkbox in jtable
    By pink123 in forum AWT / Swing
    Replies: 8
    Last Post: 03-24-2011, 06:29 PM
  3. Adding Checkbox to Jtable through vectors
    By indra00 in forum AWT / Swing
    Replies: 2
    Last Post: 12-08-2010, 08:45 AM
  4. CheckBox in JTable
    By nikosa in forum AWT / Swing
    Replies: 1
    Last Post: 08-05-2009, 05:01 AM
  5. checkBox in Jtable renderining problem
    By pothraj in forum AWT / Swing
    Replies: 1
    Last Post: 12-18-2008, 11:39 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
  •