Please help on JTable

Hello ,
Please i need help in the following topic:
I have a JTable with 50 rows i will like to do some processing when ever the row
and column change in my JTable. So I think i have to add a listener to my table but i don't really
know which listener. Can some one help me please and may be a sample code?
many thanks.

You need to add a TableModelListener to the table's model:
public class MyTableModelListener implements TableModelListener
  public void tableChanged(TableModelEvent e)
    System.out.println("THE TABLE HAS CHANGED!");
myTable.getModel().addTableModelListener(new MyTableModelListener());That should get you started.
Hope this helps.

Similar Messages

  • Please help about JTable...thanks

    HI everyone!
    Please tell me how to write a ACTIONLISTENER for a JTABLE?
    JTABLE table;
    Object[][] myArray = {  {"Mary", new Integer(5)},
    {"Alison", new Integer(3)},
    {"Angela", new Integer(1)}
    String[] columnNames = {"First Name", "Scores"};
    table = new JTable(myArray, columnNames);
    how do you write a actionlistener for a JTable?
    thanks

    One of the things I'd recommend is reading the tutorial on "How to use Tables" at the Sun website. Unless you have a button or something like that on the container the JTable is in, I don't think you want an ActionListener. One of the things you can do is set up a ListSelectionListener. It allows you to do something when a value changes in the ListSelectionModel. When you select rows in a JTable, a ListSelectionModel is created. Retrieve the ListSelectionModel from your JTable, and add a listener to it, something like:
    JTable runTable = new JTable(yourTableModel);
    runTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); // set mode
    //or use default
    ListSelectionModel rowSM = runTable.getSelectionModel();
    rowSM.addListSelectionListener(new TimeSelectionListener());
    class TimeSelectionListener implements ListSelectionListener {
    public void valueChanged(ListSelectionEvent e) {
    //Ignore extra messages.
    if (e.getValueIsAdjusting()) return;
    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
    if (lsm.isSelectionEmpty()) {
    // ...//no rows are selected
    } else {
    ... // If some rows are selected, do something here!!!
    I hope this helps.

  • Please Help.JTable insert styled text

    Hi all java guru,
    on post http://forum.java.sun.com/thread.jsp?forum=57&thread=485469 i've depicted my scenario in which i have a JTable where i want to add styled text.
    i've implemented a CustomTableModel that maintains information about text style, in such way that when renderer cell, i can rebuild exact text with its style....same method is adopted for CellEditor.
    It is possible to have more than one JTable in my application....then to correctly handle all JTables ' put them in a vector and during editing and rendering i find current focusable/selected JTable and edit/render it.
    Clearly i maintain information about style of text when i insert it, that is when i insert text, i update my CustomTableModel...same thing must be done when i delete text from JTable...that is, i must update CustomTableModel too in this case.
    Because my CellEditor is a JEditorPane component (extend it) i've registered document associated to it to a DocumentListener that notify every time that a remove operation is happens.
    What is the problem now???problem is that when i finish to edit a cell and click on another cell i've got a removeUpdate(DocumenEvent e) event, and i can't distinguish it.....it seems a real remove event....
    In this case(when i change cell) the code that is executes returns wrong result and invalidate all the rest.
    I think error is where i register celleditor , now i do it in CustomCellRenderer class that extend JEditorPane and implements TableCellRenderer.
    Please help me...this is a great trouble that invalidate all my work :(
    Any new idea is welcome.
    regards,
    anti-shock

    Hi stanislav, of course i can...you're a myth :)
    public class CustomCellEditor extends AbstractCellEditor implements TableCellEditor {
           CellEditor cellArea;
         JTable table;
         public CustomCellEditor(JTable ta) {
              super();
              table = ta;
              // this component relies on having this renderer for the String class
              MultiLineCellRenderer renderer = new MultiLineCellRenderer();
              table.setDefaultRenderer(String.class,renderer);
         public Object getCellEditorValue() {
              return cellArea.getText();
         public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,     int row, int column) {
              int start = 0;
              int end = 0;
                                               // Get current selected table
              TableEditor tb = (TableEditor) TableEditor.getSelectedTable();
              TableModel model = (TableModel) tb.getModel();
              Vector fontInfo = model.getFontFor(row,column);
              CellEditor cellArea = (CellEditor) ((CustomCellEditor)tb.getCellEditor (row,column)).getCellEditor();
              Document doc = cellArea.getDocument();
              String content = tb.getValueAt(row,column).toString();     
              if (doc!=null && fontInfo.size()>0 && !content.equals("")) {
                                                     // This method reads from model and get right style info
                                                     // for current text, and restore them
                                                     restoreFontWithAttributes(doc,fontInfo,content);
              else
                   cellArea.setText(tb.getValueAt(row,column).toString());
              cellArea.rowEditing = row;
              cellArea.columnEditing = column;
              cellArea.lastPreferredHeight = cellArea.getPreferredSize().height;
              return cellArea;
          * @return
         public CellEditor getCellEditor() {
              return cellArea;
         public class CellEditor extends JEditorPane {
              private CellStyledEditorKit k;
              public CellEditor() {
                    super("text/plain","");
                    k = new CellStyledEditorKit();
                    setEditorKit(k);
                    // I tried to add document here, but i have had wrong behavior
                   doc = new DocumentListener() {
                   public void removeUpdate(DocumentEvent e) {
                      // Get current selected table
                      TableEditor tb = (TableEditor) TableEditor.getSelectedTable();
                      TableModel model = (TableModel) tb.getModel();
                      model.updateFontInfo();
                   getDocument().addDocumentListener(doc);
    }Ok, stan...this is my CustomCellRenderer class....as i have already said, i have some style text info mainteined by CustomTableModel associated with JTable.
    I update CustomTableModel every time that an insert and remove operation happens.
    If i add a DocumentListener to CellEditor (that rapresents editor cell of my table) happens that, if i remove some character from an editing cell, i got a removeUpdate event.....and this is right!!! But if i change cell (e.g. supposing editing cell(1,1), click on cell(2,1) then stop edit cell(1,1) and start edit cell(2,1)) i got a removeUpdate event, that I don't wait for to me..
    Look at this:
    empty cell | some text
    cell 0 ------- cell1
    supposing you're in cell1 and you have finished to insert "some text".Then click on cell0, that is empty....then document associated with CellArea(extend JEditorPane) before of the click on cell0 had some text, but after click have no text, then for it a removeUpdate is happens.....and is that one i got..
    it's as if an unique document is associated to all cells, while should be one document for each cell (i hope this is right).
    Clearly, i've same code for renderer, in such way that i can restore style of text on rendering.
    Hope is clear....if U have any idea or suggestion please give to me.
    Tnx a lot Stanislav..
    regards,
    anti-shock

  • Please help me..about JTable ..Please please

    I have a JTable and tried to set the width for its columns..but I dont
    know why it doesnt work..here's my codes:
    Please help me..thanks..
    import javax.swing.table.TableColumn;
    import javax.swing.table.*;
    JTable table = new JTable();
    //a method{
    DefaultTableModel model = new DefaultTableModel(rowData, columnNames) {
    public boolean isCellEditable(int row, int col){   return false; }
    table.setModel(model);
    TableColumn column = tblEntryList.getColumnModel().getColumn(0);
    column.setPreferredWidth(25);
    column = tblEntryList.getColumnModel().getColumn(1);
    column.setPreferredWidth(100);

    I did feed the data into the table..you can tell by looking at my codes..
    please show me..dont know why it doesnt work.
    I just have my tlbEntrylist declared as
    String[][] rowData = new String[0][];
    String[] columnNames = {"Cnt","Name","Text"};
    JTable tblEntryList = new JTable(rowData, columnNames);
    //then whenever I click a a button , will call loadTableEntries()
    to remove all row data and refresh with new data..so I have to
    set new new model for this table.
    private void loadTableEntries()
    tblEntryList.removeAll(); // Remove old entries
    Object[][] rowData = new Object[entries.length][3];
    //feed the table of new data
    for(int i=0;i<rowData.length;i++)
    rowData[0] =new Integer(entries[i].getTimesUsed());
    rowData[i][1] = entries[i].getName();
    rowData[i][2] = entries[i].getText();
    String[] columnNames = {"Cnt","Name","Text"};
    // Create a new model and load it with new values
    DefaultTableModel model = new DefaultTableModel(rowData, columnNames) {
    public boolean isCellEditable(int row, int col){   return false; }
    tblEntryList.setModel(model);
    TableColumn col = tblEntryList.getColumn(tblEntryList.getModel().getColumnName(0));
    col.setPreferredWidth(10);
    col = tblEntryList.getColumn(tblEntryList.getModel().getColumnName(1));
    col.setPreferredWidth(25);
    I dont know what i'm doing wrong here but it ddint work..

  • Jtable Update problem .. Please help !!!!!!!!

    Hi ,
    I am trying to get my updated Jtable, stored in a table of database over a previous table ......after updating it via drag n drop ....
    But even after I change the cell position to make the changes ... it still takes up the old value of that cell and not the new one while writing the data in the database table...
    Here is the code .... Please see it and tell me if it is possible :
    package newpackage;
    import java.sql.*;
    import java.util.Vector;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Dimension;
    import java.text.*;
    import newpackage.ExcelExporter;
    import java.awt.Dimension;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import java.awt.datatransfer.*;
    import java.awt.dnd.*;
    import java.awt.image.*;
    import java.io.*;
    import java.util.*;
    import java.awt.print.*;
    import java.awt.*;
    import java.io.*;
    import java.util.Random.*;
    import javax.swing.*;
    import java.text.*;
    import javax.swing.DefaultCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.TableColumn;
    public class tab7le extends javax.swing.JFrame {
        Vector columnNames = new Vector();
        Vector data = new Vector();
        Connection con;
    Statement stat;
    ResultSet rs;
    int li_cols = 0;
    Vector allRows;
    Vector row;
    Vector newRow;
    Vector colNames;
    String dbColNames[];
    String pkValues[];
    String tableName;
    ResultSetMetaData myM;
    String pKeyCol;
    Vector deletedKeys;
    Vector newRows;
    boolean ibRowNew = false;
    boolean ibRowInserted = false;
        private Map<String, Color> colormap = new HashMap<String, Color>();
        /** Creates new form tab7le */
        public tab7le() {
            populate();
            initComponents();
           public void updateDB(){
                     try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          catch (ClassNotFoundException e){
                System.out.println("Cannot Load Driver!");
          try{
             String url = "jdbc:odbc:FAMS";
             con = DriverManager.getConnection(url);
             stat = con.createStatement();
             rs = stat.executeQuery("Select * from SubAllot");
             deletedKeys = new Vector();
             newRows = new Vector();
             myM = rs.getMetaData();
             tableName = myM.getTableName(1);
             li_cols = myM.getColumnCount();
             dbColNames = new String[li_cols];
             for(int col = 0; col < li_cols; col ++){
                dbColNames[col] = myM.getColumnName(col + 1);
             allRows = new Vector();
             while(rs.next()){
                newRow = new Vector();
                for(int i = 1; i <= li_cols; i++){
                   newRow.addElement(rs.getObject(i));
                } // for
                allRows.addElement(newRow);
             } // while
          catch(SQLException e){
             System.out.println(e.getMessage());
    String updateLine[] = new String[dbColNames.length];
          try{
             DatabaseMetaData dbData = con.getMetaData();
             String catalog;
             // Get the name of all of the columns for this table
             String curCol;
             colNames = new Vector();
             ResultSet rset1 = dbData.getColumns(null,null,tableName,null);
             while (rset1.next()) {
                curCol = rset1.getString(4);
                colNames.addElement(curCol);
             rset1.close();
             pKeyCol = colNames.firstElement().toString();
             // Go through the rows and perform INSERTS/UPDATES/DELETES
             int totalrows;
             totalrows = allRows.size();
             String dbValues[];
             Vector currentRow = new Vector();
             pkValues = new String[allRows.size()];
             // Get column names and values
             for(int i=0;i < totalrows;i++){
                currentRow = (Vector) allRows.elementAt(i);
                int numElements = currentRow.size();
                dbValues = new String[numElements];
                for(int x = 0; x < numElements; x++){
                   String classType = currentRow.elementAt(x).getClass().toString();
                   int pos = classType.indexOf("String");
                   if(pos > 0){ // we have a String
                      dbValues[x] = "'" + currentRow.elementAt(x) + "'";
                      updateLine[x] = dbColNames[x] + " = " + "'" + currentRow.elementAt(x) + "',";
                      if (dbColNames[x].toUpperCase().equals(pKeyCol.toUpperCase())){
                        pkValues[i] = currentRow.elementAt(x).toString() ;
                   pos = classType.indexOf("Integer");
                   if(pos > 0){ // we have an Integer
                      dbValues[x] = currentRow.elementAt(x).toString();
                      if (dbColNames[x].toUpperCase().equals(pKeyCol.toUpperCase())){
                         pkValues[i] = currentRow.elementAt(x).toString();
                      else{
                         updateLine[x] = dbColNames[x] + " = " + currentRow.elementAt(x).toString() + ",";
                   pos = classType.indexOf("Boolean");
                   if(pos > 0){ // we have a Boolean
                      dbValues[x] = currentRow.elementAt(x).toString();
                      updateLine[x] = dbColNames[x] + " = " + currentRow.elementAt(x).toString() + ",";
                      if (dbColNames[x].toUpperCase().equals(pKeyCol.toUpperCase())){
                         pkValues[i] = currentRow.elementAt(x).toString() ;
                } // For Loop
                // If we are here, we have read one entire row of data. Do an UPDATE or an INSERT
                int numNewRows = newRows.size();
                int insertRow = 0;
                boolean newRowFound;
                for (int z = 0;z < numNewRows;z++){
                   insertRow = ((Integer) newRows.get(z)).intValue();
                   if(insertRow == i+1){
                      StringBuffer InsertSQL = new StringBuffer();
                      InsertSQL.append("INSERT INTO " + tableName + " (");
                      for(int zz=0;zz<=dbColNames.length-1;zz++){
                         if (dbColNames[zz] != null){
                            InsertSQL.append(dbColNames[zz] + ",");
                      // Strip out last comma
                      InsertSQL.replace(InsertSQL.length()-1,InsertSQL.length(),")");
                      InsertSQL.append(" VALUES(" + pkValues[i] + ",");
                      for(int c=1;c < dbValues.length;c++){
                         InsertSQL.append(dbValues[c] + ",");
                      InsertSQL.replace(InsertSQL.length()-1,InsertSQL.length(),")");
                      System.out.println(InsertSQL.toString());
                      stat.executeUpdate(InsertSQL.toString());
                      ibRowInserted=true;
                } // End of INSERT Logic
                // If row has not been INSERTED perform an UPDATE
                if(ibRowInserted == false){
                   StringBuffer updateSQL = new StringBuffer();
                   updateSQL.append("UPDATE " + tableName + " SET ");
                   for(int z=0;z<=updateLine.length-1;z++){
                      if (updateLine[z] != null){
                         updateSQL.append(updateLine[z]);
                   // Replace the last ',' in the SQL statement with a blank. Then add WHERE clause
                   updateSQL.replace(updateSQL.length()-1,updateSQL.length()," ");
                   updateSQL.append(" WHERE " + pKeyCol + " = " + pkValues[i] );
                   System.out.println(updateSQL.toString());
                   stat.executeUpdate(updateSQL.toString());
                   } //for
             catch(Exception ex){
                System.out.println("SQL Error! Cannot perform SQL UPDATE " + ex.getMessage());
             // Delete records from the DB
             try{
                int numDeletes = deletedKeys.size();
                String deleteSQL;
                for(int i = 0; i < numDeletes;i++){
                   deleteSQL = "DELETE FROM " + tableName + " WHERE " + pKeyCol + " = " +
                                                ((Integer) deletedKeys.get(i)).toString();
                System.out.println(deleteSQL);
                   stat.executeUpdate(deleteSQL);
                // Assume deletes where successful. Recreate Vector holding PK Keys
                deletedKeys = new Vector();
             catch(Exception ex){
                System.out.println(ex.getMessage());
        public void populate()
            try
                //  Connect to the Database
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection con = DriverManager.getConnection("Jdbc:Odbc:FAMS"," "," ");
                System.out.println("ok1");
                //  Read data from a table
                String sql;
                 sql = "Select * from SubAllot";
                 System.out.println("ok1");
                Statement stmt = con.createStatement();
                System.out.println("ok1");
                ResultSet rs = stmt.executeQuery( sql );
                System.out.println("ok1");
                ResultSetMetaData md = rs.getMetaData();
                System.out.println("ok1");
                int columns = md.getColumnCount();
                for(int i = 0;i<columns;i++){
                    columnNames.addElement(md.getColumnName(i+1));
                    System.out.println("ok2");
                while (rs.next())
                    Vector row = new Vector(columns);
                    for (int i = 1; i <columns+1; i++)
                        row.addElement( rs.getObject(i) );
                    data.addElement( row );
            catch(Exception e){
                e.printStackTrace();
                 public void dropmenu(JTable table,TableColumn subpref1) {
            //Set up the editor for the sport cells.
            JComboBox comboBox = new JComboBox();
          for (int i = 0;i<=20;i++)
           comboBox.addItem(i);
            subpref1.setCellEditor(new DefaultCellEditor(comboBox));
            //Set up tool tips for the sport cells.
            DefaultTableCellRenderer renderer =
                    new DefaultTableCellRenderer();
            renderer.setToolTipText("Click for combo box");
            subpref1.setCellRenderer(renderer);
                       abstract class StringTransferHandler extends TransferHandler {
            public int dropAction;
            protected abstract String exportString(final JComponent c);
            protected abstract void importString(final JComponent c, final String str);
            @Override
            protected Transferable createTransferable(final JComponent c) {
                return new StringSelection(exportString(c));
            @Override
            public int getSourceActions(final JComponent c) {
                return MOVE;
            @Override
            public boolean importData(final JComponent c, final Transferable t) {
                if (canImport(c, t.getTransferDataFlavors())) {
                    try {
                        String str = (String) t.getTransferData(DataFlavor.stringFlavor);
                        importString(c, str);
                        return true;
                    } catch (UnsupportedFlavorException ufe) {
                    } catch (IOException ioe) {
                return false;
            @Override
            public boolean canImport(final JComponent c, final DataFlavor[] flavors) {
                for (int ndx = 0; ndx < flavors.length; ndx++) {
                    if (DataFlavor.stringFlavor.equals(flavors[ndx])) {
                        return true;
                return false;
        class TableTransferHandler extends StringTransferHandler {
            private int dragRow;
            private int[] dragColumns;
            private BufferedImage[] image;
            private int row;
            private int[] columns;
            public JTable target;
            private Map<String, Color> colormap;
            private TableTransferHandler(final Map<String, Color> colormap) {
                this.colormap = colormap;
            @Override
            protected Transferable createTransferable(final JComponent c) {
                JTable table = (JTable) c;
                dragRow = table.getSelectedRow();
                dragColumns = table.getSelectedColumns();
                createDragImage(table);
                return new StringSelection(exportString(c));
            protected String exportString(final JComponent c) {
                JTable table = (JTable) c;
                row = table.getSelectedRow();
                columns = table.getSelectedColumns();
                StringBuffer buff = new StringBuffer();
                colormap.clear();
                for (int j = 0; j < columns.length; j++) {
                    Object val = table.getValueAt(row, columns[j]);
                    buff.append(val == null ? "" : val.toString());
                    if (j != columns.length - 1) {
                        buff.append(",");
                    colormap.put(row+","+columns[j], Color.LIGHT_GRAY);
                table.repaint();
                return buff.toString();
            protected void importString(final JComponent c, final String str) {
                target = (JTable) c;
                DefaultTableModel model = (DefaultTableModel) target.getModel();
                String[] values = str.split("\n");
                int colCount = target.getSelectedColumn();
                int max = target.getColumnCount();
                for (int ndx = 0; ndx < values.length; ndx++) {
                    String[] data = values[ndx].split(",");
                    for (int i = 0; i < data.length; i++) {
                        String string = data;
    if(colCount < max){
    Object val = model.getValueAt(target.getSelectedRow(), colCount);
    model.setValueAt(string, target.getSelectedRow(), colCount);
    model.setValueAt(val, dragRow, dragColumns[i]);
    colCount++;
    public BufferedImage[] getDragImage() {
    return image;
    private void createDragImage(final JTable table) {
    if (dragColumns != null) {
    try {
    image = new BufferedImage[dragColumns.length];
    for (int i = 0; i < dragColumns.length; i++) {
    Rectangle cellBounds = table.getCellRect(dragRow, i, true);
    TableCellRenderer r = table.getCellRenderer(dragRow, i);
    DefaultTableModel m = (DefaultTableModel) table.getModel();
    JComponent lbl = (JComponent) r.getTableCellRendererComponent(table,
    table.getValueAt(dragRow, dragColumns[i]), false, false, dragRow, i);
    lbl.setBounds(cellBounds);
    BufferedImage img = new BufferedImage(lbl.getWidth(), lbl.getHeight(),
    BufferedImage.TYPE_INT_ARGB_PRE);
    Graphics2D graphics = img.createGraphics();
    graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
    lbl.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
    lbl.paint(graphics);
    graphics.dispose();
    image[i] = img;
    } catch (RuntimeException re) {
    class TableDropTarget extends DropTarget {
    private Insets autoscrollInsets = new Insets(20, 20, 20, 20);
    private Rectangle rect2D = new Rectangle();
    private TableTransferHandler handler;
    public TableDropTarget(final TableTransferHandler h) {
    super();
    this.handler = h;
    @Override
    public void dragOver(final DropTargetDragEvent dtde) {
    handler.dropAction = dtde.getDropAction();
    JTable table = (JTable) dtde.getDropTargetContext().getComponent();
    Point location = dtde.getLocation();
    int row = table.rowAtPoint(location);
    int column = table.columnAtPoint(location);
    table.changeSelection(row, column, false, false);
    paintImage(table, location);
    autoscroll(table, location);
    super.dragOver(dtde);
    public void dragExit(final DropTargetDragEvent dtde) {
    clearImage((JTable) dtde.getDropTargetContext().getComponent());
    super.dragExit(dtde);
    @Override
    public void drop(final DropTargetDropEvent dtde) {
    Transferable data = dtde.getTransferable();
    JTable table = (JTable) dtde.getDropTargetContext().getComponent();
    clearImage(table);
    handler.importData(table, data);
    super.drop(dtde);
    private final void paintImage(final JTable table, final Point location) {
    Point pt = new Point(location);
    BufferedImage[] image = handler.getDragImage();
    if (image != null) {
    table.paintImmediately(rect2D.getBounds());
    rect2D.setLocation(pt.x - 15, pt.y - 15);
    int wRect2D = 0;
    int hRect2D = 0;
    for (int i = 0; i < image.length; i++) {
    table.getGraphics().drawImage(image[i], pt.x - 15, pt.y - 15, table);
    pt.x += image[i].getWidth();
    if (hRect2D < image[i].getHeight()) {
    hRect2D = image[i].getHeight();
    wRect2D += image[i].getWidth();
    rect2D.setSize(wRect2D, hRect2D);
    private final void clearImage(final JTable table) {
    table.paintImmediately(rect2D.getBounds());
    private Insets getAutoscrollInsets() {
    return autoscrollInsets;
    private void autoscroll(final JTable table, final Point cursorLocation) {
    Insets insets = getAutoscrollInsets();
    Rectangle outer = table.getVisibleRect();
    Rectangle inner = new Rectangle(outer.x + insets.left,
    outer.y + insets.top,
    outer.width - (insets.left + insets.right),
    outer.height - (insets.top + insets.bottom));
    if (!inner.contains(cursorLocation)) {
    Rectangle scrollRect = new Rectangle(cursorLocation.x - insets.left,
    cursorLocation.y - insets.top,
    insets.left + insets.right,
    insets.top + insets.bottom);
    table.scrollRectToVisible(scrollRect);
    /** 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.
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    table = new javax.swing.JTable();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    table.setModel(new javax.swing.table.DefaultTableModel(
    data, columnNames
    jScrollPane1.setViewportView(table);
    //populate();
    table.getTableHeader().setReorderingAllowed(false);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setCellSelectionEnabled(true);
    table.setDragEnabled(true);
    TableTransferHandler th = new TableTransferHandler(colormap);
    table.setTransferHandler(th);
    table.setDropTarget(new TableDropTarget(th));
    dropmenu(table, table.getColumnModel().getColumn(11));
    jButton1.setText("Update");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    jButton2.setText("Ex");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton2ActionPerformed(evt);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(92, 92, 92)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 605, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(layout.createSequentialGroup()
    .addGap(347, 347, 347)
    .addComponent(jButton1)
    .addGap(115, 115, 115)
    .addComponent(jButton2)))
    .addContainerGap(73, Short.MAX_VALUE))
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(47, 47, 47)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(58, 58, 58)
    .addComponent(jButton1)
    .addContainerGap(83, Short.MAX_VALUE))
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jButton2)
    .addGap(65, 65, 65))))
    pack();
    }// </editor-fold>
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    updateDB(); // TODO add your handling code here:
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    try {
    String pathToDesktop = System.getProperty("user.home")+File.separator+"Desktop";
    pathToDesktop = pathToDesktop + "//Final Allotment.xls";
    ExcelExporter exp = new ExcelExporter();
    exp.exportTable(table, new File(pathToDesktop));
    JOptionPane.showMessageDialog(this,"File exported and saved on desktop!");
    catch (IOException ex) {
    System.out.println(ex.getMessage());
    ex.printStackTrace();
    } // TODO add your handling code here:
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new tab7le().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable table;
    // End of variables declaration
    Please help !!!!!!!!
    Thanks in advance.....                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

    Here is the code Do you expect people to read through 400 lines of code to understand what you are doing?
    Why post code with access to a database? We can't access the database.
    Search the forum for my "Database Information" (without the space) example class which shows you how to refresh a table with new data.
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.

  • Please help in storing JTable in database

    hai Abrami,
    I saw in JDK\bin\demo\jfc\Tableexample. but it contans example only for populating the Table with the values from database which I finished alraedy. But I treid of storing the Table values in database using VArray. but it contradicts with the several operations such as retireving Single field from database Updating the database when value single populated table changes.
    So please help me in this.This isthe final part of project.

    Bathina,
    Did you try doing an Internet search? I did one for the terms "jtable" and "database". Here are my results:
    http://tinyurl.com/4ttl4
    And if you just want someone to do your work for you, then try HotDispatch or Rent-A-Coder (or similar -- there are lots of others like these two).
    Good Luck,
    Avi.

  • Please help! How to add a combobox on a jtable

    Hi, I have seen on google and here many codes to add a combobox in a jtable but none of them seem to work, I need the urgently.
    My problem is that I must add a comboBox or a JComboBox to a cell inside a JTable on a predefined column. It means that on the column 2 I must add diferent comboboxes for eac row. How can I do it, please help.

    The celleditor is the component shown and the cellrenderer is the first render of a component in the cell and dont have to be the same jcombo box?
    The code on ther post does this:?
    returning a diferent combobox for all the cells on the column depending on the row selected, but as long as only one cell can be selected at a time it seems to hace different jcomboboxes added a time?
    Is there anyway to render any combobox with different values, my program must let the user chose the teacher it want to teach a definen subject, so the combo must have the teacher of a subject loaded on a database, the combos are not constants. I guess I can manage to use the way you showed me, but is there anyway to render a combo just by adding it to a cell! maybe doing changes to the tablemodel or things like that?

  • Please Help !!!!!! Autofill in Jtable

    Hi ,
    I am new to Java Programming and currently working for a project... I having few problems at various places ... But for now I want to know if there is some feature with which I can provide AUTOFILL feature in Jtable with String column type.... For eg. if in a particular place I start typing 'So.. then it shud be able to show 'Software' in autofill entry ... I need only few predefined entry to come up ...
    Please help me if someone can ... Also tell if it is at all possible
    Thanxxx in advance ..

    Yes exactly .. they'll be bunch of predefined strings ..... What I want to achieve is that I have 38 course subjects .. I want that when i start typing the subject initials then the full name of that subject to appear ..
    Tell me if combo box is good option for my table is really long .... I mean I have to make entries of subjects like that in 6X25 Jtable cell , so I would have to embed 150 combo boxes that ways ..
    Is there any other way to have it ....

  • Please help - Stuck with JTable???

    Hi everyone, i have had this problem now for ages and really wanna solve it - hope u can help!
    I have a Jtable and basically column 3 has a value in it, column 4 is editable and takes in a value that the user enters. I need to take the value from column 3 and multiply it by the number entered into column 4 to update column 5 with the result.
    I have looked over and over the API for this and saw working examples, however i am using my own table model class and finding it hard to adapt these examples to work with my code, below is my table model class and the method i have written to try undertake this piece of functionality, can anyone help me get this working - dukes!!
    class ResultSetTableModel extends AbstractTableModel {
    protected Vector columnHeaders;
    protected Vector tableData;
    protected Vector rowData;
    private Connection con;    
    private int column_count;
    int QTY_COLUMN = 4;
    private double value;
    private JTable table;
    public void fillTableModel (ResultSet result) throws SQLException {
         ResultSetMetaData rsmd = result.getMetaData();
         int count = rsmd.getColumnCount();
         columnHeaders = new Vector();
         tableData = new Vector ();
         for (int i = 1; i <= count; i++)
              columnHeaders.addElement(rsmd.getColumnName (i));
              //System.out.println(rsmd.getColumnName(i));
         columnHeaders.addElement("Qty");
         columnHeaders.addElement("Total");
         while (result.next())
              rowData = new Vector (count);
              int row = 0;
              for (int i = 1; i <= count ; i++)
                   rowData.addElement (result.getObject(i));          
              rowData.addElement("4");
              rowData.addElement("0.00");
              tableData.addElement (rowData);
         result.close();
         fireTableDataChanged();
    public int getColumnCount ()
         return columnHeaders.size();     
    public int getRowCount ()
         return tableData.size();          
    /*public Object getValueAt (int row, int column)
         Vector rowData = (Vector) (tableData.elementAt (row));   
         return rowData.elementAt (column);
    public Object getValueAt(int row, int col){  //This is the method i have written
         int sum = 0; 
         if(col == 5) {   
         try {     
              sum = Integer.parseInt((String)getValueAt(row, 3)) * Integer.parseInt((String)getValueAt(row,4));//Need to take a user input here instead of a value - i think!   
         catch (Exception e)    { //Sum above not working as column 5 displays the number 4 in each row     
              sum = 4;   
         return (new Double(sum)); 
         else  {   
              Vector rowData = (Vector) (tableData.elementAt (row));   
              return rowData.elementAt (col); 
    public boolean isCellEditable (int row, int column )
         return (column == QTY_COLUMN);
    public String getColumnName (int column)
         return (String) (columnHeaders.elementAt (column));
    public void emptyColumn(int column){   
         int rowCount = tableData.size();       
         for (int i = 0; i < rowCount; i++)    {       
              Vector rowData = (Vector)tableData.elementAt(i);               
              rowData.setElementAt("", column);   
         fireTableDataChanged();
    public void setValueAt(Object value, int row, int column) {
             ((Vector)tableData.elementAt(row)).setElementAt(value, column);
             fireTableCellUpdated(row, 5);
    }Can anyone please help and yes im desperate, he he
    Thanks in advance

    Here's something:import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Test extends JFrame {
        public Test () {
            getContentPane ().setLayout (new BorderLayout ());
            getContentPane ().add (new JTable (new TestModel ()));
            setDefaultCloseOperation (EXIT_ON_CLOSE);
            setTitle ("Test");
            pack ();
            setLocationRelativeTo (null);
            show ();
        public static void main (String[] parameters) {
            new Test ();
        private class TestModel extends AbstractTableModel {
            private java.util.List data;
            public TestModel () {
                data = new ArrayList ();
                data.add (new Pair (3, 4));
                data.add (new Pair (1, 7));
                data.add (new Pair (2, 9));
                data.add (new Pair (6, 5));
                data.add (new Pair (8, 0));
            public int getRowCount () {
                return data.size ();
            public int getColumnCount () {
                return 3;
            public Object getValueAt (int r, int c) {
                Pair pair = (Pair) data.get (r);
                int value;
                switch (c) {
                    case 0:
                        value = pair.a;
                        break;
                    case 1:
                        value = pair.b;
                        break;
                    default:
                        value = pair.a * pair.b;
                        break;
                return new Integer (value);
            public Class getColumnClass (int c) {
                return Integer.class;
            public boolean isCellEditable (int r, int c) {
                return c < 2;
            public void setValueAt (Object wrappedValue, int r, int c) {
                Pair pair = (Pair) data.get (r);
                int value = ((Integer) wrappedValue).intValue ();
                switch (c) {
                    case 0:
                        pair.a = value;
                        break;
                    case 1:
                        pair.b = value;
                        break;
                fireTableRowsUpdated (r, r);
            private class Pair {
                public int a;
                public int b;
                public Pair (int a, int b) {
                    this.a = a;
                    this.b = b;
    }Kind regards,
      Levi

  • PLEASE HELP-JTable cell editor-change one cell, changes all cells of column

    for example i have 3 rows 4 columns, column 3 and 4 are dates. now if i change the date to a new value (eg for of column 3)
    for any row, and then i click on any other cell. All cell values ie all rows for that column are changed to that new value.
    ie it changed column 3 for all rows 1, 2 and 3 to that new value which i changed in only one cell of that column.
    PLEASE HELP me , tell me what change i make to the code to fix it ....
    this is my cell renderer for date
    class DateCellRenderer extends JbcDateTimeChooser implements TableCellRenderer {
      protected Border m_noFocusBorder;
      public DateCellRenderer() {
        super();
        setStylePattern(JbcDateTimeChooser.MEDIUM);
        m_noFocusBorder = new EmptyBorder(1, 2, 1, 2);
        setOpaque(true);
        setBorder(m_noFocusBorder);
      public Component getTableCellRendererComponent(JTable table,
       Object value, boolean isSelected, boolean hasFocus,
       int row, int column)
      if(value instanceof Date) {
          Date b = (Date)value;
          setDate(b);
        setFont(table.getFont());
        setBorder(hasFocus ? UIManager.getBorder(
          "Table.focusCellHighlightBorder") : m_noFocusBorder);
        return this;
    }I have this custom cell editor date
    class DateCellEditor extends AbstractCellEditor implements TableCellEditor {
      protected JbcDateTimeChooser editor;
      public DateCellEditor() {
        super();
        editor = new JbcDateTimeChooser();
        editor.setStylePattern(JbcDateTimeChooser.MEDIUM);
      public Object getCellEditorValue() {
        return editor.getDate();
      public Component getTableCellEditorComponent(JTable table,
       Object value, boolean isSelected, int row, int column)
        if(value instanceof Date) {
          editor.setDate((Date)value);
        return editor;
    }and this is how i defined in jtable
        lnnTableModel = new CellSiteLNNTableModel();
        lnnTable.setModel(lnnTableModel);
        lnnTableModel.addColumn("ABC");
        lnnTableModel.addColumn("DEF");
        lnnTableModel.addColumn("Date From");
        lnnTableModel.addColumn("Date To");
        for(int k = 0; k < lnnTableModel.getColumnCount(); k++) {
          TableColumn col = lnnTable.getColumn(lnnTableModel.getColumnName(k));
          TableCellRenderer renderer;
            DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer();
            renderer = textRenderer;
          TableCellEditor editor;
          JTextField textColumn = new JTextField();
          if((k == CellSiteLNN.DATE_FROM) || (k == CellSiteLNN.DATE_TO)) {
            editor = new DateCellEditor();  //  this is the cell editor
         renderer = new DateCellRenderer(); // this is the assigned cell renderer
          } else {
            editor = new DefaultCellEditor(textColumn);
          col.setCellRenderer(renderer);
          col.setCellEditor(editor);
        }

    table model is extended from AbstractTableModel
    and have these methods
    do you see anything wrong here.....
      public Object getValueAt(int row, int column) {
        Vector rowVector = (Vector)dataVector.elementAt(row);
        return rowVector.elementAt(column);
      public void setValueAt(Object aValue, int row, int column) {
        Vector rowVector = (Vector)dataVector.elementAt(row);
        rowVector.setElementAt(aValue, column);
        // generate notification
        fireTableChanged(new TableModelEvent(this, row, row, column));
      } // end method (setValueAt)

  • Remove the key listener from JTable problem please help

    Hi
    I�m trying to remove the key listener from my table, it doesn�t work,
    I�m pressing the enter key it still goes to the next row from the table,
    hear is my code
    KeyListener[] mls = (KeyListener[])(table.getListeners(KeyListener.class));
    for(int i = 0; i < mls.length; i++ )
    table.removeKeyListener(mls);
    Please help thanks

    Hm ...
    that should indeed remove all the KeyListeners from your table - the question is only, when does this happen?- Where in your code do you remove the KeyListeners?- I am quite sure, you remove them successfully, but after your have removed them, one or more KeyListeners are added to the table.
    greetings Marsian

  • Please help me in creating a form using Swing.

    (I m sorry if I've posted similar post in some other thread.I am new to this forum..:))
    There are several problems which I am facing while coding a form.
    1. In the form I have one JComboBox
    of Country and other of State. Now I want it in such a way that when
    I select a country from the Country JComboBox ,the corresponding states
    automatically appears in the State JComboBox.
    2. I need to add picture frame in the 6th tab so that the picture shows up when clicked browse and open.
    3.I need to add tables in 1st and 5th tab which shows up the details through database when added through several textboxes and combo boxes.
    so please help me!
    Here's my code
    ==========================================================
    import javax.swing.JFrame;
    import javax.swing.JTabbedPane;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JCheckBox;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import javax.swing.Box;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Design extends JFrame
    public Design()
    super("Tenant Form");
    setLayout(new BorderLayout());
    JTabbedPane tabbedPane=new JTabbedPane(); //creating tabbed buttons
    //<--------coding for first tab--------->
    JPanel panel1=new JPanel();
    tabbedPane.addTab("Detail of Landlord",null,panel1,"first tab"); //here panel1 is created for tab1
    GridBagConstraints gbc=new GridBagConstraints();
    gbc.insets=new Insets(2,2,2,2);
    gbc.anchor=GridBagConstraints.WEST;
    JPanel jp11 = new JPanel(); //1st panel in 1st tab for top labels and buttons
    jp11.setLayout(new GridBagLayout());
    JLabel l241 = new JLabel("Name Of LandLord");
    jp11.add(l241,gbc);
    JComboBox jc01=new JComboBox();
    jc01.addItem("Select");
    jc01.addItem("Mr.");
    jc01.addItem("Mrs.");
    gbc.gridx=1;
    jp11.add(jc01,gbc);
    JTextField f01=new JTextField(10);
    gbc.gridx=2;
    jp11.add(f01,gbc);
    JLabel l251 = new JLabel("Sex");
    gbc.gridx=5;
    gbc.insets=new Insets(2,20,2,2);
    jp11.add(l251,gbc);
    JComboBox jc11=new JComboBox();
    jc11.addItem("Select");
    jc11.addItem("Male");
    jc11.addItem("Female");
    gbc.gridx=6;
    gbc.insets=new Insets(2,2,2,2);
    jp11.add(jc11,gbc);
    JLabel l261 = new JLabel("Age(Yrs)");
    gbc.gridx=8;
    gbc.insets=new Insets(2,20,2,2);
    jp11.add(l261,gbc);
    JTextField f11=new JTextField(3);
    gbc.gridx=9;
    gbc.insets=new Insets(2,2,2,2);
    jp11.add(f11,gbc);
    JLabel l271 = new JLabel("Occupation");
    gbc.gridx= 11;
    gbc.insets=new Insets(2,20,2,2);
    jp11.add(l271,gbc);
    JComboBox jc21=new JComboBox();
    jc21.addItem("Select");
    jc21.addItem("Engineer");
    jc21.addItem("Business");
    gbc.gridx=12;
    gbc.insets=new Insets(2,2,2,2);
    jp11.add(jc21,gbc);
    JButton ab1=new JButton("ADD");
    gbc.gridx=14;
    gbc.insets=new Insets(2,20,2,2);
    jp11.add(ab1,gbc);
    panel1.add(jp11);
    //<--coding for adding table with scroll pane #yet to be coded#-->
    JTable jtab1=new JTable();
    //start of p21 panel. 1st of two titledborder panels in tab 1
    JPanel jp21=new JPanel();
    jp21.setBorder(new TitledBorder("Address Of Landlord Property"));
    jp21.setLayout(new GridBagLayout());
    JLabel l11=new JLabel("Property/House/Building Address");
    gbc.gridx=0;
    gbc.gridy=0;
    jp21.add(l11,gbc);
    JTextArea ta11=new JTextArea(3,15);
    ta11.setLineWrap(true);
    int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
    JScrollPane scroll11=new JScrollPane(ta11,v,h);
    gbc.gridx=1;
    jp21.add(scroll11);
    jp21.add(ta11,gbc);
    JLabel l21=new JLabel("Land Mark");
    gbc.gridx=0;
    gbc.gridy=1;
    gbc.ipady=0;
    gbc.gridheight=1;
    jp21.add(l21,gbc);
    JTextField tf21=new JTextField(15);
    gbc.gridx=1;
    gbc.gridy=1;
    jp21.add(tf21,gbc);
    JLabel l31=new JLabel("Country");
    gbc.gridx=0;
    gbc.gridy=2;
    jp21.add(l31,gbc);
    JComboBox c11=new JComboBox();
    c11.addItem("India");
    c11.addItem("US");
    c11.addItem("Australia");
    gbc.gridx=1;
    gbc.gridy=2;
    jp21.add(c11,gbc);
    JLabel l41=new JLabel("State");
    gbc.gridx=0;
    gbc.gridy=3;
    jp21.add(l41,gbc);
    JComboBox c21=new JComboBox();
    c21.addItem("Rajasthan");
    c21.addItem("Delhi");
    c21.addItem("Maharastra");
    gbc.gridx=1;
    gbc.gridy=3;
    jp21.add(c21,gbc);
    JLabel l51=new JLabel("District");
    gbc.gridx=0;
    gbc.gridy=4;
    jp21.add(l51,gbc);
    JComboBox c31=new JComboBox();
    c31.addItem("jaipur");
    c31.addItem("ajmer");
    c31.addItem("alwar");
    gbc.gridx=1;
    gbc.gridy=4;
    jp21.add(c31,gbc);
    JLabel l61=new JLabel("City/Town");
    gbc.gridx=0;
    gbc.gridy=5;
    jp21.add(l61,gbc);
    JTextField tf31=new JTextField(15);
    gbc.gridx=1;
    gbc.gridy=5;
    jp21.add(tf31,gbc);
    JLabel l71=new JLabel("Police District");
    gbc.gridx=0;
    gbc.gridy=6;
    jp21.add(l71,gbc);
    JComboBox c41=new JComboBox();
    c41.addItem("Jaipur");
    c41.addItem("Alwar");
    c41.addItem("Ajmer");
    gbc.gridx=1;
    gbc.gridy=6;
    jp21.add(c41,gbc);
    JLabel l81=new JLabel("Police Circle");
    gbc.gridx=0;
    gbc.gridy=7;
    jp21.add(l81,gbc);
    JComboBox c51=new JComboBox();
    c51.addItem("India");
    c51.addItem("US");
    c51.addItem("Australia");
    gbc.gridx=1;
    gbc.gridy=7;
    jp21.add(c51,gbc);
    JLabel l91=new JLabel("Police station");
    gbc.gridx=0;
    gbc.gridy=8;
    jp21.add(l91,gbc);
    JComboBox c61=new JComboBox();
    c61.addItem("Bani Park");
    c61.addItem("Raja Park");
    c61.addItem("Malviya Nagar");
    gbc.gridx=1;
    gbc.gridy=8;
    jp21.add(c61,gbc);
    JLabel l101=new JLabel("Pin No.");
    gbc.gridx=0;
    gbc.gridy=9;
    jp21.add(l101,gbc);
    JTextField tf41=new JTextField(15);
    gbc.gridx=1;
    gbc.gridy=9;
    jp21.add(tf41,gbc);
    JLabel l111=new JLabel("Phone No.(R)");
    gbc.gridx=0;
    gbc.gridy=10;
    jp21.add(l111,gbc);
    JTextField tf51=new JTextField(15);
    gbc.gridx=1;
    gbc.gridy=10;
    jp21.add(tf51,gbc);
    //start of p31.2nd of two titledborder panels in tab 1
    JPanel jp31=new JPanel();
    jp31.setBorder(new TitledBorder("Address Of Landlord Office"));
    jp31.setLayout(new GridBagLayout());
    JLabel l121=new JLabel("Office Address");
    gbc.gridx=0;
    gbc.gridy=0;
    jp31.add(l121,gbc);
    JTextArea ta61=new JTextArea(3,15);
    ta61.setLineWrap(true);
    JScrollPane scroll2=new JScrollPane(ta61);
    gbc.gridx=1;
    gbc.gridy=0;
    jp31.add(ta61,gbc);
    JLabel l131=new JLabel("Country");
    gbc.gridx=0;
    gbc.gridy=1;
    gbc.gridheight=1;
    jp31.add(l131,gbc);
    JComboBox c12=new JComboBox();
    c12.addItem("India");
    c12.addItem("US");
    c12.addItem("Australia");
    gbc.gridx=1;
    gbc.gridy=1;
    jp31.add(c12,gbc);
    JLabel l141=new JLabel("State");
    gbc.gridx=0;
    gbc.gridy=2;
    jp31.add(l141,gbc);
    JComboBox c22=new JComboBox();
    c22.addItem("Rajasthan");
    c22.addItem("Delhi");
    c22.addItem("Maharastra");
    gbc.gridx=1;
    gbc.gridy=2;
    jp31.add(c22,gbc);
    JLabel l151=new JLabel("District");
    gbc.gridx=0;
    gbc.gridy=3;
    jp31.add(l151,gbc);
    JComboBox c32=new JComboBox();
    c32.addItem("jaipur");
    c32.addItem("ajmer");
    c32.addItem("alwar");
    gbc.gridx=1;
    gbc.gridy=3;
    jp31.add(c32,gbc);
    JLabel l161=new JLabel("City/Town");
    gbc.gridx=0;
    gbc.gridy=4;
    jp31.add(l161,gbc);
    JTextField tf71=new JTextField(15);
    gbc.gridx=1;
    gbc.gridy=4;
    jp31.add(tf71,gbc);
    JLabel l171=new JLabel("Police District");
    gbc.gridx=0;
    gbc.gridy=5;
    jp31.add(l171,gbc);
    JComboBox c42=new JComboBox();
    c42.addItem("Jaipur");
    c42.addItem("Alwar");
    c42.addItem("Ajmer");
    gbc.gridx=1;
    gbc.gridy=5;
    jp31.add(c42,gbc);
    JLabel l181=new JLabel("Police Circle");
    gbc.gridx=0;
    gbc.gridy=6;
    jp31.add(l181,gbc);
    JComboBox c52=new JComboBox();
    c52.addItem("India");
    c52.addItem("US");
    c52.addItem("Australia");
    gbc.gridx=1;
    gbc.gridy=6;
    jp31.add(c52,gbc);
    JLabel l191=new JLabel("Police station");
    gbc.gridx=0;
    gbc.gridy=7;
    jp31.add(l191,gbc);
    JComboBox c62=new JComboBox();
    c62.addItem("Bani Park");
    c62.addItem("Raja Park");
    c62.addItem("Malviya Nagar");
    gbc.gridx=1;
    gbc.gridy=7;
    jp31.add(c62,gbc);
    JLabel l201=new JLabel("Pin No.");
    gbc.gridx=0;
    gbc.gridy=8;
    jp31.add(l201,gbc);
    JTextField tf81=new JTextField(15);
    gbc.gridx=1;
    gbc.gridy=8;
    jp31.add(tf81,gbc);
    JLabel l211=new JLabel("Phone No.(O)");
    gbc.gridx=0;
    gbc.gridy=9;
    jp31.add(l211,gbc);
    JTextField tf91=new JTextField(15);
    gbc.gridx=1;
    gbc.gridy=9;
    jp31.add(tf91,gbc);
    JLabel l221=new JLabel("Phone No.(M)");
    gbc.gridx=0;
    gbc.gridy=10;
    gbc.gridheight=1;
    jp31.add(l221,gbc);
    JTextField tf101=new JTextField(15);
    gbc.gridx=1;
    gbc.gridy=10;
    jp31.add(tf101,gbc);
    JLabel l231=new JLabel("E-mail");
    gbc.gridx=0;
    gbc.gridy=11;
    gbc.gridheight=1;
    jp31.add(l231,gbc);
    JTextField tf111=new JTextField(15);
    gbc.gridx=1;
    gbc.gridy=11;
    jp31.add(tf111,gbc);
    JPanel jp41=new JPanel(); //adding above two panels p21 and p31 to p41 panel.
    jp41.setLayout(new BoxLayout(jp41,BoxLayout.X_AXIS));
    jp41.add(jp21);
    jp41.add(Box.createHorizontalStrut(50));
    jp41.add(jp31);
    panel1.add(jp41); //adding p41 panel to panel1
    //<--------coding for second tab--------->
    JPanel panel2 = new JPanel();
    tabbedPane.addTab("Id of Landlord",null,panel2,"second tab");
    panel2.setLayout(new FlowLayout());
    //adding radiobutton above TitledBorder panel
    JPanel jp02=new JPanel();
    JLabel l12=new JLabel("Identity Known");
    JRadioButton jrb12=new JRadioButton("Yes");
    JRadioButton jrb22=new JRadioButton("No");
    ButtonGroup bg12=new ButtonGroup();
    bg12.add(jrb12);
    bg12.add(jrb22);
    jp02.add(l12);
    jp02.add(jrb12);
    jp02.add(jrb22);
    //adding TitledBorder panel
    JPanel jp12=new JPanel();
    jp12.setBorder(new TitledBorder("Identity Detail"));
    jp12.setLayout(new GridBagLayout());
    gbc.insets=new Insets(5,5,5,5);
    JLabel l22=new JLabel("Identity Card");
    gbc.gridx=0;
    gbc.gridy=0;
    jp12.add(l22,gbc);
    JTextField jtf12=new JTextField(10);
    gbc.gridx=1;
    jp12.add(jtf12,gbc);
    JLabel l32=new JLabel("Date of Issue");
    gbc.gridx=0;
    gbc.gridy=1;
    jp12.add(l32,gbc);
    JTextField jtf22=new JTextField(10);
    gbc.insets=new Insets(5,5,5,25);
    gbc.gridx=1;
    jp12.add(jtf22,gbc);
    JLabel l42=new JLabel("Identity Number");
    gbc.insets=new Insets(5,5,5,5);
    gbc.gridx=2;
    jp12.add(l42,gbc);
    JTextField jtf32=new JTextField(10);
    gbc.gridx=3;
    jp12.add(jtf32,gbc);
    JLabel l52=new JLabel("Name Of Issuer");
    gbc.gridx=0;
    gbc.gridy=2;
    jp12.add(l52,gbc);
    JTextField jtf42=new JTextField(10);
    gbc.insets=new Insets(5,5,5,25);
    gbc.gridx=1;
    jp12.add(jtf42,gbc);
    JLabel l62= new JLabel("Place Of Issuer");
    gbc.insets=new Insets(5,5,5,5);
    gbc.gridx=2;
    jp12.add(l62,gbc);
    JTextField jtf52=new JTextField(10);
    gbc.gridx=3;
    jp12.add(jtf52,gbc);
    gbc.gridx=0;
    gbc.gridy=2;
    Box b12 =Box.createVerticalBox(); //adding both panels to vertica box and adding it to panel2
    b12.add(jp02);
    b12.add(jp12);
    panel2.add(b12);
    //<--------coding for third tab--------->
    JPanel panel3 = new JPanel();
    tabbedPane.addTab("Detail of Tenant",null,panel3,"third tab");
    //adding panel for top data
    JPanel jp13=new JPanel(); //jp13 panel for details above 3 TitledBorder panels
    jp13.setLayout(new GridBagLayout());
    JLabel l13=new JLabel("Name");
    gbc.insets=new Insets(2,2,2,2);
    gbc.gridx=0;
    gbc.gridy=0;
    jp13.add(l13,gbc);
    JComboBox c13=new JComboBox();
    c13.addItem("Select");
    c13.addItem("Mr.");
    c13.addItem("Mrs.");
    gbc.gridx=1;
    jp13.add(c13,gbc);
    JTextField jtf13=new JTextField(16);
    gbc.gridx=2;
    gbc.gridwidth=2;
    jp13.add(jtf13,gbc);
    JLabel l23=new JLabel("Sex");
    gbc.insets=new Insets(2,20,2,2);
    gbc.gridx=4;
    gbc.gridwidth=1;
    jp13.add(l23,gbc);
    JComboBox c23=new JComboBox();
    c23.addItem("Select");
    c23.addItem("Male");
    c23.addItem("Female");
    gbc.insets=new Insets(2,2,2,2);
    gbc.gridx=5;
    jp13.add(c23,gbc);
    JLabel l33=new JLabel("Father/Mother/Husband's Name");
    gbc.gridy=1;
    gbc.gridx=0;
    jp13.add(l33,gbc);
    JComboBox c33=new JComboBox();
    c33.addItem("Select");
    c33.addItem("Mr.");
    c33.addItem("Mrs.");
    gbc.gridx=1;
    jp13.add(c33,gbc);
    JComboBox c43=new JComboBox();
    c43.addItem("Select");
    c43.addItem("Mr.");
    c43.addItem("Mrs.");
    gbc.gridx=2;
    jp13.add(c43,gbc);
    JTextField jtf23=new JTextField(10);
    gbc.gridx=3;
    jp13.add(jtf23,gbc);
    JLabel l43=new JLabel("Age(Yrs)");
    gbc.insets=new Insets(2,20,2,2);
    gbc.gridx=4;
    jp13.add(l43,gbc);
    JTextField jtf33=new JTextField(3);
    gbc.insets=new Insets(2,2,2,2);
    gbc.gridx=5;
    jp13.add(jtf33,gbc);
    JLabel l53=new JLabel("Citizenship");
    gbc.gridy=2;
    gbc.gridx=0;
    jp13.add(l53,gbc);
    JComboBox c53=new JComboBox();
    c53.addItem("Select");
    c53.addItem("Indian");
    c53.addItem("Australian");
    gbc.gridx=1;
    gbc.gridwidth=2;
    jp13.add(c53,gbc);
    JLabel l63=new JLabel("Occupation");
    gbc.insets=new Insets(2,20,2,2);
    gbc.gridx=4;
    gbc.gridwidth=1;
    jp13.add(l63,gbc);
    JComboBox c63=new JComboBox();
    c63.addItem("Select");
    c63.addItem("Engineer");
    c63.addItem("Doctor");
    gbc.insets=new Insets(2,2,2,2);
    gbc.gridx=5;
    jp13.add(c63,gbc);
    panel3.add(jp13);
    JPanel jp23=new JPanel(); //first of 3 TitledBorder panels
    jp23.setBorder(new TitledBorder("Local Address"));
    jp23.setLayout(new GridBagLayout());
    JLabel l73=new JLabel("Local Address");
    gbc.gridx=0;
    gbc.gridy=0;
    jp23.add(l73,gbc);
    JTextArea ta43=new JTextArea(3,10);
    ta43.setLineWrap(true);
    JScrollPane scroll13=new JScrollPane(ta43);
    gbc.gridx=1;
    gbc.gridy=0;
    jp23.add(ta43,gbc);
    JLabel l83=new JLabel("Country");
    gbc.gridx=0;
    gbc.gridy=1;
    gbc.gridheight=1;
    jp23.add(l83,gbc);
    JComboBox c73=new JComboBox();
    c73.addItem("India");
    c73.addItem("US");
    c73.addItem("Australia");
    gbc.gridx=1;
    gbc.gridy=1;
    jp23.add(c73,gbc);
    JLabel l93=new JLabel("State");
    gbc.gridx=0;
    gbc.gridy=2;
    jp23.add(l93,gbc);
    JComboBox c83=new JComboBox();
    c83.addItem("Rajasthan");
    c83.addItem("Delhi");
    c83.addItem("Maharastra");
    gbc.gridx=1;
    gbc.gridy=2;
    jp23.add(c83,gbc);
    JLabel l103=new JLabel("District");
    gbc.gridx=0;
    gbc.gridy=3;
    jp23.add(l103,gbc);
    JComboBox c93=new JComboBox();
    c93.addItem("jaipur");
    c93.addItem("ajmer");
    c93.addItem("alwar");
    gbc.gridx=1;
    gbc.gridy=3;
    jp23.add(c93,gbc);
    JLabel l113=new JLabel("City/Town");
    gbc.gridx=0;
    gbc.gridy=4;
    jp23.add(l113,gbc);
    JTextField tf53=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=4;
    jp23.add(tf53,gbc);
    JLabel l123=new JLabel("Police District");
    gbc.gridx=0;
    gbc.gridy=5;
    jp23.add(l123,gbc);
    JComboBox c103=new JComboBox();
    c103.addItem("Jaipur");
    c103.addItem("Alwar");
    c103.addItem("Ajmer");
    gbc.gridx=1;
    gbc.gridy=5;
    jp23.add(c103,gbc);
    JLabel l133=new JLabel("Police Circle");
    gbc.gridx=0;
    gbc.gridy=6;
    jp23.add(l133,gbc);
    JComboBox c113=new JComboBox();
    c113.addItem("India");
    c113.addItem("US");
    c113.addItem("Australia");
    gbc.gridx=1;
    gbc.gridy=6;
    jp23.add(c113,gbc);
    JLabel l143=new JLabel("Police station");
    gbc.gridx=0;
    gbc.gridy=7;
    jp23.add(l143,gbc);
    JComboBox c123=new JComboBox();
    c123.addItem("Bani Park");
    c123.addItem("Raja Park");
    c123.addItem("Malviya Nagar");
    gbc.gridx=1;
    gbc.gridy=7;
    jp23.add(c123,gbc);
    JLabel l153=new JLabel("Pin No.");
    gbc.gridx=0;
    gbc.gridy=8;
    jp23.add(l153,gbc);
    JTextField tf63=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=8;
    jp23.add(tf63,gbc);
    JLabel l163=new JLabel("Phone No.(R)");
    gbc.gridx=0;
    gbc.gridy=9;
    jp23.add(l163,gbc);
    JTextField tf73=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=9;
    jp23.add(tf73,gbc);
    JLabel l173=new JLabel("E-mail");
    gbc.gridx=0;
    gbc.gridy=10;
    gbc.gridheight=1;
    jp23.add(l173,gbc);
    JTextField tf83=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=10;
    jp23.add(tf83,gbc);
    JPanel jp33=new JPanel(); //second of 3 TitledBorder panels
    jp33.setBorder(new TitledBorder("Permanent Address"));
    jp33.setLayout(new GridBagLayout());
    JLabel l183=new JLabel("Perm. Address");
    gbc.gridx=0;
    gbc.gridy=0;
    jp33.add(l183,gbc);
    JTextArea ta93=new JTextArea(5,10);
    JScrollPane scroll23=new JScrollPane(ta43);
    ta93.setLineWrap(true);
    gbc.gridx=1;
    gbc.gridy=0;
    jp33.add(ta43,gbc);
    JLabel l193=new JLabel("Country");
    gbc.gridx=0;
    gbc.gridy=1;
    gbc.gridheight=1;
    jp33.add(l193,gbc);
    JComboBox c133=new JComboBox();
    c133.addItem("India");
    c133.addItem("US");
    c133.addItem("Australia");
    gbc.gridx=1;
    gbc.gridy=1;
    jp33.add(c133,gbc);
    JLabel l203=new JLabel("State");
    gbc.gridx=0;
    gbc.gridy=2;
    jp33.add(l203,gbc);
    JComboBox c143=new JComboBox();
    c143.addItem("Rajasthan");
    c143.addItem("Delhi");
    c143.addItem("Maharastra");
    gbc.gridx=1;
    gbc.gridy=2;
    jp33.add(c143,gbc);
    JLabel l213=new JLabel("District");
    gbc.gridx=0;
    gbc.gridy=3;
    jp33.add(l213,gbc);
    JComboBox c153=new JComboBox();
    c153.addItem("jaipur");
    c153.addItem("ajmer");
    c153.addItem("alwar");
    gbc.gridx=1;
    gbc.gridy=3;
    jp33.add(c153,gbc);
    JLabel l223=new JLabel("City/Town");
    gbc.gridx=0;
    gbc.gridy=4;
    jp33.add(l223,gbc);
    JTextField tf103=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=4;
    jp33.add(tf103,gbc);
    JLabel l233=new JLabel("Police District");
    gbc.gridx=0;
    gbc.gridy=5;
    jp33.add(l233,gbc);
    JComboBox c163=new JComboBox();
    c163.addItem("Jaipur");
    c163.addItem("Alwar");
    c163.addItem("Ajmer");
    gbc.gridx=1;
    gbc.gridy=5;
    jp33.add(c163,gbc);
    JLabel l243=new JLabel("Police Circle");
    gbc.gridx=0;
    gbc.gridy=6;
    jp33.add(l243,gbc);
    JComboBox c173=new JComboBox();
    c173.addItem("India");
    c173.addItem("US");
    c173.addItem("Australia");
    gbc.gridx=1;
    gbc.gridy=6;
    jp33.add(c173,gbc);
    JLabel l253=new JLabel("Police station");
    gbc.gridx=0;
    gbc.gridy=7;
    jp33.add(l253,gbc);
    JComboBox c183=new JComboBox();
    c183.addItem("Bani Park");
    c183.addItem("Raja Park");
    c183.addItem("Malviya Nagar");
    gbc.gridx=1;
    gbc.gridy=7;
    jp33.add(c183,gbc);
    JLabel l263=new JLabel("Pin No.");
    gbc.gridx=0;
    gbc.gridy=8;
    jp33.add(l263,gbc);
    JTextField tf113=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=8;
    jp33.add(tf113,gbc);
    JLabel l273=new JLabel("Phone No.(R)");
    gbc.gridx=0;
    gbc.gridy=9;
    jp33.add(l273,gbc);
    JTextField tf123=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=9;
    jp33.add(tf123,gbc);
    JLabel l283=new JLabel("phone No.(M)");
    gbc.gridx=0;
    gbc.gridy=10;
    gbc.gridheight=1;
    jp33.add(l283,gbc);
    JTextField tf133=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=10;
    jp33.add(tf133,gbc);
    JPanel jp43=new JPanel(); //third of 3 TitledBorder panels
    jp43.setBorder(new TitledBorder("Ex-Home Address"));
    jp43.setLayout(new GridBagLayout());
    JLabel l293=new JLabel("Address");
    gbc.gridx=0;
    gbc.gridy=0;
    jp43.add(l293,gbc);
    JTextArea ta143=new JTextArea(3,10);
    ta143.setLineWrap(true);
    JScrollPane scroll33=new JScrollPane(ta143);
    gbc.gridx=1;
    gbc.gridy=0;
    jp43.add(ta143,gbc);
    JLabel l303=new JLabel("Country");
    gbc.gridx=0;
    gbc.gridy=1;
    gbc.gridheight=1;
    jp43.add(l303,gbc);
    JComboBox c193=new JComboBox();
    c193.addItem("India");
    c193.addItem("US");
    c193.addItem("Australia");
    gbc.gridx=1;
    gbc.gridy=1;
    jp43.add(c193,gbc);
    JLabel l313=new JLabel("State");
    gbc.gridx=0;
    gbc.gridy=2;
    jp43.add(l313,gbc);
    JComboBox c203=new JComboBox();
    c203.addItem("Rajasthan");
    c203.addItem("Delhi");
    c203.addItem("Maharastra");
    gbc.gridx=1;
    gbc.gridy=2;
    jp43.add(c203,gbc);
    JLabel l323=new JLabel("District");
    gbc.gridx=0;
    gbc.gridy=3;
    jp43.add(l323,gbc);
    JComboBox c213=new JComboBox();
    c213.addItem("jaipur");
    c213.addItem("ajmer");
    c213.addItem("alwar");
    gbc.gridx=1;
    gbc.gridy=3;
    jp43.add(c213,gbc);
    JLabel l333=new JLabel("City/Town");
    gbc.gridx=0;
    gbc.gridy=4;
    jp43.add(l333,gbc);
    JTextField tf153=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=4;
    jp43.add(tf153,gbc);
    JLabel l343=new JLabel("Police District");
    gbc.gridx=0;
    gbc.gridy=5;
    jp43.add(l343,gbc);
    JComboBox c223=new JComboBox();
    c223.addItem("Jaipur");
    c223.addItem("Alwar");
    c223.addItem("Ajmer");
    gbc.gridx=1;
    gbc.gridy=5;
    jp43.add(c223,gbc);
    JLabel l353=new JLabel("Police Circle");
    gbc.gridx=0;
    gbc.gridy=6;
    jp43.add(l353,gbc);
    JComboBox c233=new JComboBox();
    c233.addItem("India");
    c233.addItem("US");
    c233.addItem("Australia");
    gbc.gridx=1;
    gbc.gridy=6;
    jp43.add(c233,gbc);
    JLabel l363=new JLabel("Police station");
    gbc.gridx=0;
    gbc.gridy=7;
    jp43.add(l363,gbc);
    JComboBox c243=new JComboBox();
    c243.addItem("Bani Park");
    c243.addItem("Raja Park");
    c243.addItem("Malviya Nagar");
    gbc.gridx=1;
    gbc.gridy=7;
    jp43.add(c123,gbc);
    JLabel l373=new JLabel("Pin No.");
    gbc.gridx=0;
    gbc.gridy=8;
    jp43.add(l373,gbc);
    JTextField tf163=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=8;
    jp43.add(tf163,gbc);
    JLabel l383=new JLabel("Phone");
    gbc.gridx=0;
    gbc.gridy=9;
    jp43.add(l383,gbc);
    JTextField tf173=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=9;
    jp43.add(tf173,gbc);
    JLabel l393=new JLabel("Leaving Date");
    gbc.gridx=0;
    gbc.gridy=10;
    gbc.gridheight=1;
    jp43.add(l393,gbc);
    JTextField tf183=new JTextField(10);
    gbc.gridx=1;
    gbc.gridy=10;
    jp43.add(tf183,gbc);
    /*JCheckBox cb13=new JCheckBox("Approx");
    gbc.gridx=2;
    gbc.gridy=10;
    jp43.add(cb13);*/
    JPanel jp53=new JPanel(); //panel for addin all 3 TitledBorder panels
    jp53.setLayout(new BoxLayout(jp53,BoxLayout.X_AXIS));
    jp53.add(jp23);
    jp53.add(Box.createHorizontalStrut(30)); //giving space between each TitledBorder panel
    jp53.add(jp33);
    jp53.add(Box.createHorizontalStrut(30));
    jp53.add(jp43);
    panel3.add(jp53); //adding panel which contains all 3 TitledBorder panels to panel3
    JPanel jp63=new JPanel(); //jp63 panel for bottom data
    jp63.setBorder(new TitledBorder("Tennancy Start/End"));
    JLabel l403=new JLabel("From Date");
    jp63.add(l403);
    JTextField jtf193=new JTextField(12);
    jp63.add(jtf193);
    JCheckBox jcb23=new JCheckBox("Approx");
    jp63.add(jcb23);
    JLabel l413=new JLabel("To Date");
    jp63.add(l413);
    JTextField jtf203=new JTextField(12);
    jp63.add(jtf203);
    JCheckBox jcb33=new JCheckBox("Approx");
    jp63.add(jcb33);
    panel3.add(jp63); //adding bottom details panel jp63 to panel3
    //<--------coding for fourth tab--------->
    JPanel panel4 = new JPanel();
    tabbedPane.addTab("Id of Tenant",null,panel4,"fourth tab");
    panel4.setLayout(new FlowLayout());
    //adding radiobutton above TitledBorder panel jp14
    JPanel jp04=new JPanel();
    JLabel l14=new JLabel("Identity Known");
    JRadioButton jrb14=new JRadioButton("Yes");
    JRadioButton jrb24=new JRadioButton("No");
    ButtonGroup bg14=new ButtonGroup();
    bg14.add(jrb14);
    bg14.add(jrb24);
    jp04.add(l14);
    jp04.add(jrb14);
    jp04.add(jrb24);
    //adding TitledBorder panel jp14
    JPanel jp14=new JPanel();
    jp14.setBorder(new TitledBorder("Identity Detail"));
    jp14.setLayout(new GridBagLayout());
    gbc.insets=new Insets(5,5,5,5);
    JLabel l24=new JLabel("Identity Card");
    gbc.gridx=0;
    gbc.gridy=0;
    jp14.add(l24,gbc);
    JTextField jtf14=new JTextField(10);
    gbc.gridx=1;
    jp14.add(jtf14,gbc);
    JLabel l34=new JLabel("Date of Issue");
    gbc.gridx=0;
    gbc.gridy=1;
    jp14.add(l34,gbc);
    JTextField jtf24=new JTextField(10);
    gbc.insets=new Insets(5,5,5,25);
    gbc.gridx=1;
    jp14.add(jtf24,gbc);
    JLabel l44=new JLabel("Identity Number");
    gbc.insets=new Insets(5,5,5,5);
    gbc.gridx=2;
    jp14.add(l44,gbc);
    JTextField jtf34=new JTextField(10);
    gbc.gridx=3;
    jp14.add(jtf34,gbc);
    JLabel l54=new JLabel("Name Of Issuer");
    gbc.gridx=0;
    gbc.gridy=2;
    jp14.add(l54,gbc);
    JTextField jtf44=new JTextField(10);
    gbc.insets=new Insets(5,5,5,25);
    gbc.gridx=1;
    jp14.add(jtf44,gbc);
    JLabel l64=new JLabel("Place Of Issuer");
    gbc.insets=new Insets(5,5,5,5);
    gbc.gridx=2;
    jp14.add(l64,gbc);
    JTextField jtf54=new JTextField(10);
    gbc.gridx=3;
    jp14.add(jtf54,gbc);
    gbc.gridx=0;
    gbc.gridy=2;
    Box b14=Box.createVerticalBox(); //adding both panels to panel4 in vertical box
    b14.add(jp04);
    b14.add(jp14);
    panel4.add(b14);
    //<--------coding for fifth tab--------->
    JPanel panel5 = new JPanel();
    tabbedPane.addTab("Info Of Other Members",null,panel5,"fifth tab");
    JPanel jp15=new JPanel(); //top panel jp15 for details above add delete buttons
    jp15.setLayout(new GridBagLayout());
    JLabel l15=new JLabel("Name");
    gbc.gridx=0;
    gbc.gridy=0;
    gbc.insets=new Insets(10,10,10,10);
    jp15.add(l15,gbc);
    JTextField jtf15=new JTextField(10);
    gbc.gridx=1;
    jp15.add(jtf15,gbc);
    JLabel l25=new JLabel("Sex");
    gbc.gridx=2;
    gbc.insets=new Insets(10,80,10,10);
    jp15.add(l25,gbc);
    JComboBox jcb15=new JComboBox();
    jcb15.addItem("Male");
    jcb15.addItem("Female");
    gbc.gridx=3;
    gbc.insets=new Insets(10,10,10,10);
    jp15.add(jcb15,gbc);
    JLabel l35=new JLabel("Relation");
    gbc.gridx=0;
    gbc.gridy=1;
    gbc.insets=new Insets(10,10,40,10);
    jp15.add(l35,gbc);
    JTextField jtf25=new JTextField(10);
    gbc.gridx=1;
    jp15.add(jtf25,gbc);
    JLabel l45=new JLabel("Age");
    gbc.gridx=2;
    gbc.insets=new Insets(10,80,40,10);
    jp15.add(l45,gbc);
    JTextField jtf35 =new JTextField(10);
    gbc.gridx=3;
    gbc.insets=new Insets(10,10,40,10);
    jp15.add(jtf35,gbc);
    JPanel jp25=new JPanel(); //middle panel jp25 for adding "add" and "delete" buttons
    JButton jb15=new JButton("Add");
    JButton jb25=new JButton("Delete");
    jp25.add(jb15);
    jp25.add(jb25);
    //adding table #yet to be coded#
    Box b15=Box.createVerticalBox();
    b15.add(jp15);
    b15.add(jp25);
    panel5.add(b15); //adding jp15 and jp25 to panel5 in vertical box
    //<--------coding for sixth tab--------->
    JPanel panel6 = new JPanel();
    tabbedPane.addTab("Related To Office",null,panel6,"sixth tab");
    panel6.setLayout(new GridBagLayout());
    //adding 4 labels and textfields vertically
    JLabel l16=new JLabel("Investigation Officer");
    gbc.gridx=0;
    gbc.gridy=0;
    gbc.insets=new Insets(40,40,20,10);
    panel6.add(l16,gbc);
    JTextField jtf16 =new JTextField(10);
    gbc.gridx=1;
    gbc.insets=new Insets(40,20,20,40);
    panel6.add(jtf16,gbc);
    JLabel l26=new JLabel("S.No.");
    gbc.gridx=0;
    gbc.gridy=1;
    gbc.insets=new Insets(10,40,20,10);
    panel6.add(l26,gbc);
    JTextField jtf26 =new JTextField(10);
    gbc.gridx=1;
    gbc.insets=new Insets(10,20,20,40);
    panel6.add(jtf26,gbc);
    JLabel l36=new JLabel("Page No.");
    gbc.gridx=0;
    gbc.gridy=2;
    gbc.insets=new Insets(10,40,20,10);
    panel6.add(l36,gbc);
    JTextField jtf36 =new JTextField(10);
    gbc.gridx=1;
    gbc.insets=new Insets(10,20,20,40);
    panel6.add(jtf36,gbc);
    JLabel l46=new JLabel("Date");
    gbc.gridx=0;
    gbc.gridy=3;
    gbc.insets=new Insets(10,40,20,10);
    panel6.add(l46,gbc);
    JTextField jtf46=new JTextField(10);
    gbc.gridx=1;
    gbc.insets=new Insets(10,20,20,40);
    panel6.add(jtf46,gbc);
    /* Canvas c16=new Canvas(); //creating a rectangle frame for adding image
    Image i16=c.createImage(200,100);
    gbc.gridx=2;
    gbc.gridy=0;
    gbc.insets=new Insets(40,20,20,40);
    gbc.gridheight=3;
    panel6.add(i16,gbc);*/
    JButton jb16=new JButton("Browse"); //adding "browse" and "save" buttons
    gbc.insets=new Insets(10,20,20,40);
    gbc.gridy=3;
    panel6.add(jb16,gbc);
    JButton jb26=new JButton("Save");
    gbc.insets=new Insets(50,20,20,40);
    gbc.gridy=4;
    panel6.add(jb26,gbc);
    //<-------end of sixth tab------->
    add(tabbedPane);
    //lower panel for cancel button
    JPanel jp1=new JPanel();
    jp1.setLayout(new FlowLayout(FlowLayout.RIGHT));
    JButton can=new JButton("Cancel"); //initialising cancel button
    jp1.add(can);
    add(jp1,BorderLayout.SOUTH);
    class Blistener implements ActionListener // class for action listener
    public void actionPerformed(ActionEvent ae)
    Object obj=ae.getSource();
    try{
    if(obj == can) //condition for cancel button
    System.exit(0);
    }catch(Exception e)
    {System.out.println(e);
    public class Project
    public static void main(String args[]) //main method for the program
    Design tabbedwin= new Design();
    tabbedwin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    tabbedwin.setSize(900,700);
    tab

    First things first. Next time please use the code formating tags when posting your code.
    Secondly, we cant help you do your entire project or more specifically we cant do it for you. We can probably help you with one section at a time.
    Thirdly, do not post your entire code. Create a Short, Self Contained, Compilable Example (SSCCE) that demonstrates the problem section, and that is independent of any third party libraries and can compiled instantly and tested.
    Now, lets see if we can answer one problem here.
    Ques 1. In the form I have one JComboBox of Country and other of State. Now I want it in such a way that whenI select a country from the Country JComboBox ,the corresponding states automatically appears in the State JComboBox.
    Ans 1: Use an ItemListener or an ActionListener (javax.swing.event) for this. Once an item is selected, the event will be fired and then you populate your ComboBox with the requried data.
    Ques 2. I need to add picture frame in the 6th tab so that the picture shows up when clicked browse and open.
    Ans 2: You haven't created the JButton for the browse action, nor have you created the JLabel to show the picture in. Create the JButton, then the JLabel, attach an ActionListener to the button to listen for the button click, open a JFileChooser, select the image file, create an ImageIcon and pass the File object returned to it. Then call the JLabel.setIcon( the ImageIcon) to display the picture. You'll have to store the picture File information some where so can reference it when saving.
    Ques 3.I need to add tables in 1st and 5th tab which shows up the details through database when added through several textboxes and combo boxes.
    You need to do some reading. The Swing Tutorial has everything you need, from How to use Tables to How to connect to databases. There are also some examples in your JDK installation folder, ie, jdk/demos/jfc/tableExample. Here is the link to the swing tutorial on how to use Tables: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html. You find other useful links there.
    ICE

  • Need help about JTable

    Can some one please help me about how to sort a column in a JTable when click on the the column title

    Can't tell you off the top of my head but I know you will find it here...
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#selection

  • Please Help!!! Getting data to a table

    I am having real problems with this I want a table with a header which lists the contents of a file. In this file on each line there are the header titles eg each line is set out the same just containing different parameters etc Event No: 0     Time Elapsed: 1.0 Event String: Algoritm changed Parameter: algo: Monitoring
    In the table the constructor says Object [][] and Object [] please help how do I get my code to compile.
         FileReader file = new FileReader("c:\\projects\\FirstSupport\\logfile2.txt");
              BufferedReader inputfile = new BufferedReader (file);
              Object[] columnNames = {"Event No",
    "Time Elapsed",
    "Event String",
    "Parameter"};
              Object[] values;
              MessageFormat mf = new MessageFormat("Event No:{0,number} Time Elapsed: {1,number} Event String:{2} Parameter:{3,number}");
              text = "Event No: 0     Time Elapsed: 1.0 Event String: Algoritm changed Parameter: algo: Monitoring";
              while ((Line = inputfile.readLine()) != null);
                   System.out.println(text);
                   values = mf.parse(text);
                   int eventNo = ((Number)values[0]).intValue();
                   double time = ((Number)values[1]).doubleValue();
                   String eventString = (String)values[2];
                   int param = ((Number)values[3]).intValue();
    JTable table = new JTable(values,columnNames);

    Hi,
    where is the problem? Does the part reading the file work? If so I would use a class extending DefaultTableModel .
    Have a look at :
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    Phil

  • Making a Table cell editable. Please Help

    Hello there,
    I have written an Inner class called CallHeaderRenderer
    which is used to select to highlight a row from a table.
    But i am unable to edit the column data I click on.
    Please can any one tell me how to edit the column value when you double click on it??
    Attached is my Inner class used to select the concerned row.
    I am unable to edit the concerned column.....
    Please help.!!!
    What is the statement to make the cell editable!!!
    class CallHeaderRenderer extends DefaultTableCellRenderer{
    public CallHeaderRenderer(){
    super();
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
    // Set the highlight for record chosen.
    super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
    return this;
    }

    A renderer has nothing to do with editing the cell. I suggest you read this section from the Swing tutorial on "Using Tables" for an explanation of how tables work. The tutorial will give one method for making a cell editable:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    Here is an alternate way to make a cell editable:
    table = new JTable( ... )
        public boolean isCellEditable(int row, int column)
            //  All columns, except the first, are editable
            if (column == 0)
                return false;
            else
                return true;
    };

Maybe you are looking for