problem with JTable


problem with JTable

problem with JTable
1 Answer(s)      9 years ago
Posted in : Swing AWT
View Answers

March 31, 2009 at 4:10 PM

hi friend,

This code will help you

import java.text.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import javax.swing.table.TableCellRenderer;
import javax.swing.DefaultCellEditor;

public class TableFeature extends JFrame {
private JTable table;
private Vector rowData, columnHeaders;
private boolean bool;
private JPanel panel;
private JCheckBox check;
private Vector data;
private MyDefaultTableModel model;

public TableFeature() {
bool = true;
data = new Vector();
data.add(new Boolean(false));
rowData = new Vector();
columnHeaders = new Vector();

model = new MyDefaultTableModel(rowData, columnHeaders);
table = new JTable(model);
JScrollPane listScrollPane = new JScrollPane(table);

check = new JCheckBox();
check.addActionListener(new AddListener());
JPanel panel = new JPanel();

Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
listScrollPane.setPreferredSize(new Dimension(300, 200));
contentPane.add(listScrollPane, BorderLayout.CENTER);
contentPane.add(panel, BorderLayout.SOUTH);
public void setUpDateColumn(TableColumn col) {
public void setUpExerciseColumn(TableColumn col) {
col.setCellRenderer(new checkboxCellRender());
class MyDefaultTableModel extends DefaultTableModel {
public MyDefaultTableModel(Vector r, Vector c) {
super(r, c);
public boolean isCellEditable(int row, int col) {
if (col ==2)
return false;
return true;
class checkboxCellRender extends JCheckBox
implements TableCellRenderer{
public Component getTableCellRendererComponent( JTable t,
Object value, boolean isSelected, boolean hasFocus,
int row, int col)
JCheckBox cb = new JCheckBox();
boolean sel=check.isSelected();
return cb;
class AddListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Vector data = new Vector(2);
data.add(0, "A");
data.add(1, new Boolean(true));

public static void main(String s[]) {
JFrame frame = new TableFeature();

frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0); }



Related Tutorials/Questions & Answers:
jtable problem
jtable problem  how to make a cell text hypertext
problem Scrolling jTable in scrollpane
problem Scrolling jTable in scrollpane  hi i get into a problem of scrolling jtable in scrollpane.Only horizontal scroll is working, vertical scroll...)); tableModel =new DefaultTableModel(rowdata, colname); table = new JTable
problem Scrolling jTable in scrollpane
problem Scrolling jTable in scrollpane  hi i get into a problem of scrolling jtable in scrollpane.Only horizontal scroll is working, vertical scroll...)); tableModel =new DefaultTableModel(rowdata, colname); table = new JTable
problem with JTable - Swing AWT
problem with JTable  hi guys, i was a student and i am very new to swings.i was having an assignment like i need to create a JTable... an action event such that if i check the checkbox outside the JTable,all the checkboxes
problem scrolling jtable
problem scrolling jtable  hi, i've to query the table thousand...;}}; table = new JTable(tableModel...); MAIN PROBLEM HERE'S M TABLE IS NOT PROPERLY SETTING IN SCROLLPANE...REPLY SOON
jTable data problem
jTable data problem  Hello. I have a code that read file and store in arraylist and then convert to array(To use for table model) My class extends...(){ JFrame frame=new JFrame(); JTable table=new JTable(rftl); JPanel panel
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
JTable  below describes a program of research that results in a table, my problem is that this same table to see it only accepts a single line even..."}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
jtable  hi Sir i am working netbeans IDE,I have a jtable when i insert values in jtable then i am unable to print all inserted values,For eg if i insert 1,2,3,4,5,6,7,8 values then , i am getting output
JTable  Hi I have problems in setting values to a cell in Jtable which is in a jFrame which implements TableModelListener which has a abstract method tableChanged(TableModelEvent e) . I'll be loading values from data base when
JTable - Java Beginners
JTable search example  I've problem about JTable, i wan to search records when i types words in JTable cell,can u give the source code.I'm Beginner and i start begins learning java programming.Please send the example into my
JTABLE OF JAVA  i have a jtable in java,i have used checkbox in jtable. now i want to add(submit) only those records that i have checked by checkbox how? i want small example with coding
Jtable-Java  Hi all,I have a Jtable And i need to clear the data in the table .I only Need to remove the data in the table.not the rows.Please help me
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
sum in JTable
sum in JTable  how to calculate sum from JTable's one field like total
JTABLE Issue  Hi Eveyone, I am developing a small application on Swing-AWT. I have used JTABLE to show data. There is "input field" and "search... on basis of input data provided in input field. For JTABLE is on some other
jtable query
jtable query  I need a syntax...where i could fetch the whole data from the database once i click the cell in jtable...and that must be displayed in the nearby text field which i have set in the same frame
java jtable
java jtable  Hello Sir, I am developing a desktop application in which i have to display database records in jtable .now I want to read only... that in jtable. plz help me with the code
regarding jtable...
regarding jtable...  sir, im working with jtables. i wanted to populate a jtable from the database and when i click any row it should add a container... a container on the jtable. kindly help me sir. thanks in advance regards, rajahari
ABOUT Jtable
ABOUT Jtable  My Project is Exsice Management in java swing Desktop Application. I M Use Netbeans & Mysql . How can retrive Data in Jtable from Mysql Database in Net Beans
JTable - Swing AWT
JTable  Hi Deepak, i m facing a problem with jtable. i am able to display the values from the database into the jtable. but not able to modifying multiple cell values in a row. also i want to store those modified
JTable duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
How to add JTable in JPanel
How to add JTable in JPanel  How to add JTable in JPanel
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
(Exception e){} JTable table = new JTable(data, columnNames); JScrollPane scrollPane