Results 1 to 1 of 1
Thread: Adding New JTable in JTable
- 01-27-2010, 08:27 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 88
- Rep Power
- 0
Adding New JTable in JTable
Hello i am add a new JTable in Existing JTable .Now my problem is after losing the focus of cell of existing table the cell value of new jtable is lost??
my code is below
Please help meJava Code:import java.awt.Component; import javax.swing.*; import javax.swing.table.*; public class Table extends javax.swing.JFrame { /** Creates new form Table */ public Table() { initComponents(); this.jTable1.getColumnModel().getColumn(0).setCellRenderer(new cellRender()); this.jTable1.getColumnModel().getColumn(0).setCellEditor(new cellEditor()); } /** 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. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTable1.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 [] { "Title 1", "Title 2", "Title 3", "Title 4" } )); jScrollPane1.setViewportView(jTable1); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// </editor-fold>//GEN-END:initComponents /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Table().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; // End of variables declaration//GEN-END:variables } class cellRender implements TableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { for(int i=0;i<table.getRowCount();i++) { JTable jt=new JTable(i+1,1); jt.setTableHeader(null); jt.setShowGrid(false); table.setRowHeight(i, (table.getRowHeight()*(i+1))+1); if(i==row) return jt; } return null; } } class cellEditor extends AbstractCellEditor implements TableCellEditor { String val=""; public Object getCellEditorValue() { return null; } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { for(int i=0;i<table.getRowCount();i++) { JTable jt=new JTable(i+1,1); jt.setTableHeader(null); jt.setShowGrid(false); table.setRowHeight(i, (table.getRowHeight()*(i+1))+4); if(i==row) return jt; } return null; } }
Similar Threads
-
Reading from file and adding to JTable
By purple in forum New To JavaReplies: 11Last Post: 04-14-2011, 10:33 PM -
JTable insertRows() just adding blank rows
By Jacob_ in forum AWT / SwingReplies: 4Last Post: 10-10-2009, 03:56 AM -
Adding JButton to a JTable
By ting.at.net@hotmail.com in forum AWT / SwingReplies: 6Last Post: 05-26-2009, 03:37 AM -
Unable to use fireTableRow after adding sorter on JTable
By swat_katz in forum AWT / SwingReplies: 2Last Post: 04-09-2009, 11:59 PM -
Adding information to a JTable in a JTabbedPane
By bigpappatrader in forum AWT / SwingReplies: 0Last Post: 12-05-2007, 07:09 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks