Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Liutauras Vilda
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Devaka Cooray
Paul Clapham
Saloon Keepers:
Scott Selikoff
Tim Holloway
Piet Souris
Mikalai Zaikin
Frits Walraven
Bartenders:
Stephan van Hulst
Carey Brown
Forum:
Swing / AWT / SWT
checkbox in jTable
Anand Karia
Ranch Hand
Posts: 158
I like...
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can any one tell me why checkboxes are not appering in my jTable. Where I am wrong?
I am using NetBeansIDE 3.6. Firstly i drag jTable then manually adjust it according to my need
Thanks in advance.
import javax.swing.table.*; public class jTableTest extends javax.swing.JFrame { javax.swing.table.DefaultTableModel t_Dtl=new javax.swing.table.DefaultTableModel(); /** Creates new form jTableTest */ public jTableTest() { initComponents(); setGrid_Detail(); } //My function to set grid private void setGrid_Detail() { t_Dtl.addColumn((Object) "Col-A"); t_Dtl.addColumn((Object) "Col-B"); t_Dtl.addColumn(new Boolean("Col-C")); t_Dtl.addColumn((Object) "Col-D"); myTable.setModel(t_Dtl); addRow(); } private void addRow() { try { t_Dtl.addRow( new Object [] {"","","",""}); } catch(Exception e) { } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ //These are all autogenerated codes. private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); myTable = new javax.swing.JTable(); getContentPane().setLayout(null); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); myTable.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Col 1", "Col 2", "Col 3", "Col 4" } ) { Class[] types = new Class [] { java.lang.Object.class, java.lang.Object.class, java.lang.Boolean.class, java.lang.Object.class }; public Class getColumnClass(int columnIndex) { return types [columnIndex]; } }); jScrollPane1.setViewportView(myTable); getContentPane().add(jScrollPane1); jScrollPane1.setBounds(20, 40, 360, 150); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300); } /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) { System.exit(0); } /** * @param args the command line arguments */ public static void main(String args[]) { new jTableTest().show(); } // Variables declaration - do not modify private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable myTable; // End of variables declaration }
Love is GOD and GOD is Love.
Anand Karia
IT Concretor.......
M/s. Anand Karia Concreting IT
Michael Dunn
Ranch Hand
Posts: 4632
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
can't help with netbeans-generated code, but here's a simple demo
import java.awt.*; import javax.swing.*; import javax.swing.table.*; class Testing extends JFrame { String colNames[] = {"CheckBox", "String", "String"}; Object[][] data = {}; DefaultTableModel dtm; public Testing() { setLocation(400,100); setDefaultCloseOperation(EXIT_ON_CLOSE); dtm = new DefaultTableModel(data,colNames); JTable table = new JTable(dtm); JScrollPane sp = new JScrollPane(table); TableColumn tc = table.getColumnModel().getColumn(0); tc.setCellEditor(table.getDefaultEditor(Boolean.class)); tc.setCellRenderer(table.getDefaultRenderer(Boolean.class)); getContentPane().add(sp); for(int x = 0; x < 5; x++) { dtm.addRow(new Object[]{new Boolean(false),"Row "+(x+1)+" Col 2","Row "+(x+1)+" Col 3"}); } pack(); } public static void main (String[] args){new Testing().setVisible(true);} }
Anand Karia
Ranch Hand
Posts: 158
I like...
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I thank you very much Michael Dunn.
Your these line of code solve my problem.
TableColumn tc = tblDetail.getColumnModel().getColumn(7); tc.setCellEditor(tblDetail.getDefaultEditor(Boolean.class)); tc.setCellRenderer(tblDetail.getDefaultRenderer(Boolean.class));
Love is GOD and GOD is Love.
Anand Karia
IT Concretor.......
M/s. Anand Karia Concreting IT
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JTable numeric validation
JTable cell rendering
call another form/frame(?) show method
Tab order in JTable
JTable - selecting multiple rows by selecting checkbox column
More...