problem with JTable

problem with JTable

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() {
super("Table");
bool = true;
data = new Vector();
data.add("A");
data.add(new Boolean(false));
rowData = new Vector();
columnHeaders = new Vector();
columnHeaders.add("Name");
columnHeaders.add("Selection");

rowData.add(data);
model = new MyDefaultTableModel(rowData, columnHeaders);
table = new JTable(model);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane listScrollPane = new JScrollPane(table);
setUpDateColumn(table.getColumnModel().getColumn(0));
setUpExerciseColumn(table.getColumnModel().getColumn(1));

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

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) {
col.setPreferredWidth(100);
}
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;
else
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();
if(sel){
cb.setSelected(Boolean.TRUE);
}
else{
cb.setSelected(Boolean.FALSE);
}
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));

model.removeRow(0);
model.insertRow(0,data);
}
}
public static void main(String s[]) {
JFrame frame = new TableFeature();

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

Thanks









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
Advertisements
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... = new JTable(tableModel...); pane.setSize(600,300); pane.setVisible(true); MAIN PROBLEM
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
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
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
JTable
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
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
JTable
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
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
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
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
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
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
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
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
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 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
REPORT WITH JTABLE
(Exception e){} JTable table = new JTable(data, columnNames); JScrollPane scrollPane
JTable - JDBC
JTable   Hello..... I have Jtable with four rows and columns and i have also entered some records in MsSql database. i want to increase Jtable's... { JFrame f; JPanel p; JLabel l; JTextField tf; JButton btn; JTable tb
jtable
JTable - Swing AWT
JTable row selection event   Hi, it will be great if someone can share an example of row selection event in JTable
JTable hold different components
JTable hold different components  create Jtable with two coloums,one coloumn is combobox and other normal
Connecting JTable to database - JDBC
Connecting JTable to database  Hi.. I am doing a project on Project... interface in which i have used JTables.. Now my problem is I dont know how to how to store this JTable content in my database table.. This is a very important
JTable Pagination
JTable Pagination  Hello , I have the following Code. I am able to fetch the Data from the Database. But i need to implement pagination for the same. Can someone please help me out with this ? I have tried out many things from
JTable in java - Java Beginners
JTable in java  Sir , I have created an application with a JTable showing the records of an MS Access database table. On the same frame I have... given one , JTable table; ....... .... table.print(); Here the error
JTable - Java Beginners
JTable  Hi, I have some problem with JTable. On show All button hit.... my problem is with Jtable, sometimes it is visible and sometimes it is not. when... it is on the panel with records. An another problem is that, i want
JTable - Java Beginners
JTable  can we merge two cells of one row in jtable
restrict jtable editing
restrict jtable editing  How to restrict jtable from editing or JTable disable editing?   public class MyTableModel extends...){ return false; } }   Disabling User Edits in a JTable Component
regarding JTable - JDBC
regarding JTable  how to populate a JTable with mysql data after clicking JButton please explain with the example
JAVA DATABASE CONNECTION WITH JTABLE
JAVA DATABASE CONNECTION WITH JTABLE  HOw To Load Database Contents From Access Database to JTable without using Vector
jtable query compare with date
jtable query compare with date  how to transfer daytable data to monthtable when complete a month
Jtable with servlet - Java Beginners
Jtable with servlet   Actually I have embedded the html... time I want the JTable to display the record saved in the database,the JTable... of the page and the bottom half will consists of JTable to display the record information
Jbutton in JTable cells
Jbutton in JTable cells  I am a Java Beginner... I want a code in which I display data in Jtable from database and correspondingly a JButton for each cell and when i click on that button a new window should open
JTable populate with resultset.
JTable populate with resultset.  How to diplay data of resultset using JTable?   JTable is component of java swing toolkit. JTable class is helpful in displaying data in tabular format. You can also edit data. JTable
JTable with Date Picker
JTable with Date Picker  Hi, I'd like to implement the following but I have no idea where to start: I have a JTable with 1 column containing... in the backing object(that populated the JTable
jtable query compare with date
jtable query compare with date  how to transfer daytable data... in which i have to display database records in jtable .now I want to transfer particular data which month is over to another jtable. plz sir give me the code
jtable query compare with date
jtable query compare with date  how to transfer daytable data... in which i have to display database records in jtable .now I want to transfer particular data which month is over to another jtable. plz sir give me the code

Ads