Results 1 to 2 of 2
Thread: checkBox with jtable and mysql
- 09-15-2012, 12:56 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 1
- Rep Power
- 0
checkBox with jtable and mysql

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...
- 09-15-2012, 01:22 PM #2
Re: checkBox with jtable and mysql
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Checkbox editor for JTable column
By ShamPhadtale in forum AWT / SwingReplies: 12Last Post: 10-11-2011, 05:38 PM -
Disable a checkbox in jtable
By pink123 in forum AWT / SwingReplies: 8Last Post: 03-24-2011, 06:29 PM -
Adding Checkbox to Jtable through vectors
By indra00 in forum AWT / SwingReplies: 2Last Post: 12-08-2010, 08:45 AM -
CheckBox in JTable
By nikosa in forum AWT / SwingReplies: 1Last Post: 08-05-2009, 05:01 AM -
checkBox in Jtable renderining problem
By pothraj in forum AWT / SwingReplies: 1Last Post: 12-18-2008, 11:39 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks