We help IT Professionals succeed at work.

OutOfMemoryError: Java heap space

zolf
zolf asked
on
821 Views
Last Modified: 2013-11-05
hello there,

i have a java application with JTree and the jtree is created from the db and when a tree node is clicked.data is displayed onthe right side of the jsplitpane.when i keep opening the tree nodes for about 8-9 tree nodes.i get this error.please help me solve this problem.

Exception in thread "Thread-40" java.lang.OutOfMemoryError: Java heap space
      at javax.swing.text.GapContent.allocateArray(Unknown Source)
      at javax.swing.text.GapVector.<init>(Unknown Source)
      at javax.swing.text.GapContent.<init>(Unknown Source)
      at javax.swing.text.html.HTMLDocument.<init>(Unknown Source)
      at javax.swing.plaf.basic.BasicHTML$BasicDocument.<init>(Unknown Source)
      at javax.swing.plaf.basic.BasicHTML$BasicEditorKit.createDefaultDocument(Unknown Source)
      at javax.swing.plaf.basic.BasicHTML.createHTMLView(Unknown Source)
      at javax.swing.plaf.basic.BasicHTML.updateRenderer(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonListener.propertyChange(Unknown Source)
      at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
      at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
      at java.awt.Component.firePropertyChange(Unknown Source)
      at javax.swing.AbstractButton.setText(Unknown Source)
      at src.com.victa.TreeTableInternalFrame.createTerminalButtonsPanel(TreeTableInternalFrame.java:1070)
      at src.com.victa.TreeTableInternalFrame$2.run(TreeTableInternalFrame.java:458)
      at java.lang.Thread.run(Unknown Source)
Comment
Watch Question

You may need to increase the heap size of the application.
use

-Xmx512m

on the command line of the java if you want to set the max heap size as 512M.

Commented:
I think you should explore your codes and release unnecessary arrays and objects you are no longer use them or at least you don't need them this very soon.

Author

Commented:

Ajay-Singh:
the ram on my system is 512.if i give it all 512 then wont it reduce my system performance.my aplication starts using JNLP

mnrz:
can you please help me more on your comment.please help me sort this.

Commented:
post the code written when a node is being clicked

Author

Commented:
public class TreeTableInternalFrame extends JInternalFrame
{
      public final String CITY_CO_DSLAM_PANEL = "city_co_dslam_panel";
      public final String CO_DETALED_PANEL = "co_detaled_panel";
      public final String MDF_PANEL = "mdf_panel";
      public final String BUTTON_PANEL = "button_panel";
      public final String SPLITTER_PANEL = "splitter_panel";
      
      private ImageIcon testIcon;
      private ImageIcon cityIcon;
    private ImageIcon coIcon;
    private ImageIcon dslamIcon;
    private ImageIcon linecardIcon;
    private ImageIcon refreshIcon;
    private ImageIcon mapIcon;
    private ImageIcon cityMap;
   
    private ImageIcon dslamGroupIcon;
    private ImageIcon splitterGroupIcon;
    private ImageIcon mdfGroupIcon;
    private ImageIcon mdfIcon;
    private ImageIcon splitterIcon;
   
    private DefaultMutableTreeNode lastSelectedNode;
      
      private JTree tree;
      private JTable cityTable;
      private JTable coTable;
      private JTable dslamTable;
      private JTable linecardTable;
      private JTabbedPane tabPane;
      private JLabel label;
      private JPopupMenu treePopupMenu;
      
      private Vector cityCollect;
      private Vector coCollect;
      private Vector dslamCollect;
      private Vector linecardCollect;      
      private Vector mdfCollect;
      private Vector splitterCollect;
            
      private Vector cityPrivilegeCollect;
      private Vector coPrivilegeCollect;
      private Vector dslamPrivilegeCollect;
      private Vector linecardPrivilegeCollect;      
      private Vector mdfPrivilegeCollect;
      private Vector splitterPrivilegeCollect;
      
      private JPanel rightCardPanel = null;
      private JLabel coId;
      private JLabel coFarsiName;
      private JLabel coEnglishName;
      private JPanel innerCardPanel = null;
      private JTabbedPane mdfTabPane;
      private JTabbedPane  splitterTabPane;
      private JTable mdfTable;
      private JTable splitterTable;
      PictMenuFrameDemo JFParentFrame;
      int pk;
      int fk;
      ImageIcon iIcon;
      JPanel mapPane;
      JScrollPane jspMap;
      int buttonNo;
      JPanel coDetaledPanel;
      private ThumbnailPanel thnPanel;
      private Connection connection;
      private JScrollPane jspPhoto;
      private String homeDir = "";
      private ImageIcon addIcon;
      private ImageIcon delIcon;
      private ImageIcon photoIcon;
      boolean flag = true;
      JSplitPane splitPane;
      TreePath selPath;
      DefaultMutableTreeNode coselect;
      Vector cov = null;
      CoRow co;
      Vector vc= null;
      TreePath[] paths;
      TreePath paths1;
      Object [] o;
      JProgressBar progressBar;      
      JPanel buttonPanel = null;
      int privilege = 0;
      int city_id = 0;
      
    public TreeTableInternalFrame(final PictMenuFrameDemo frame)
    {
        super("B├╝cht Automation",
              true, //resizable
              true, //closable
              true, //maximizable
              true);//iconifiable

        Dimension deskSize = frame.getDesktop().getSize();
        setSize((int)deskSize.getWidth(), (int)deskSize.getHeight());
        //Set the window's location.
        setLocation(0, 0);
        JFParentFrame = frame;
       
        privilege = Login.privilege;
        //privilege = 1;
       
        //get database result in to collections
        //initCollections(PictMenuFrameDemo.getDBConnection());
       
        if(privilege == 1 || privilege == 0)
        {
              initCollections(PictMenuFrameDemo.getDBConnection());
        }
        else if(privilege == 2)
        {
              city_id = Login.cityView;
              initPrivilegeCollections(PictMenuFrameDemo.getDBConnection(),city_id);
        }
        else if(privilege == 3)
        {
              city_id = Login.cityView;
              initPrivilegeCollections(PictMenuFrameDemo.getDBConnection(),city_id);
        }
       
        progressBar = new JProgressBar();    
     
        testIcon = new ImageIcon(getClass().getResource("/images/dslamIcon.png"));

          //cityIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/cityIcon.png"));
        cityIcon = new ImageIcon(getClass().getResource("/images/cityIcon.png"));

          //coIcon =  new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/coIcon.png"));
          coIcon = new ImageIcon(getClass().getResource("/images/coIcon.png"));
          
          //dslamIcon =  new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/dslamIcon.png"));
          dslamIcon = new ImageIcon(getClass().getResource("/images/dslamIcon.png"));
                 
          //linecardIcon =  new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/cardIcon.png"));
          linecardIcon = new ImageIcon(getClass().getResource("/images/cardIcon.png"));
          refreshIcon = new ImageIcon(getClass().getResource("/images/refresh.jpg"));
          mapIcon = new ImageIcon(getClass().getResource("/images/map.png"));

          //ImageIcon iIcon = null;
          
          dslamGroupIcon = new ImageIcon(getClass().getResource("/images/dsIcon.PNG"));
        splitterGroupIcon = new ImageIcon(getClass().getResource("/images/spIcon.PNG"));
        mdfGroupIcon = new ImageIcon(getClass().getResource("/images/mIcon.PNG"));
        mdfIcon = new ImageIcon(getClass().getResource("/images/mdfIcon.PNG"));
        splitterIcon = new ImageIcon(getClass().getResource("/images/splitterIcon.PNG"));
        addIcon = new ImageIcon(getClass().getResource("/images/addIcon.PNG"));
        delIcon = new ImageIcon(getClass().getResource("/images/delIcon.PNG"));
        photoIcon = new ImageIcon(getClass().getResource("/images/photoIcon.png"));
       
        //set layout for frame content panel
        Container cp = getContentPane();
        cp.setLayout(new BorderLayout());
       
        //create toolbar
        JToolBar toolbar = createToolbar();
        cp.add(toolbar, BorderLayout.NORTH);
       
       
        // create popup menu for tree
        //treePopupMenu = createPopupMenu();

        // create tree element
       // createAndInitPrivilegeTree();
        //createAndInitTree();
       
        if(privilege == 1 || privilege == 0)
        {
              createAndInitTree();
        }
        else if(privilege == 2)
        {
              createAndInitPrivilegeTree();
        }
        else if(privilege == 3)
        {
              createAndInitPrivilegeTree();
        }
       
        tree.addMouseListener(new MouseAdapter() {
              public void mousePressed(MouseEvent me) {
                  Object obj = tree.getLastSelectedPathComponent();
                  if(obj != null) {
                        DefaultMutableTreeNode select = (DefaultMutableTreeNode)obj;
                        //System.out.print("select != lastSelectedNode  ");
                        //System.out.println(select != lastSelectedNode);
                        if (select != lastSelectedNode)
                        {
 
                              Object uObject = select.getUserObject();
                              
                              pk = ((BaseRow)uObject).getPrimaryKey();
                              fk = ((BaseRow)uObject).getForeignKey();
                              //System.out.println(pk);
                              //System.out.println(fk);
                              switch(((BaseRow)uObject).getType()) {
                                     case BaseRow.CITY_TYPE : {
                                           changeCard(rightCardPanel, CITY_CO_DSLAM_PANEL);
                                           int index = 0;
                                           if(privilege == 1 || privilege == 0)
                                           {
                                                 index= Collections.binarySearch(cityCollect, obj, new PrimaryKeyComparator());      
                                           }
                                           else if(privilege == 2)
                                           {
                                                 index = Collections.binarySearch(cityPrivilegeCollect, obj, new PrimaryKeyComparator());
                                           }
                                           else if(privilege == 3)
                                       {
                                                 index = Collections.binarySearch(cityPrivilegeCollect, obj, new PrimaryKeyComparator());
                                       }
                                           cityTable.setRowSelectionInterval(index, index);
                                           cityTable.scrollRectToVisible(cityTable.getCellRect(index, 0, true));
                                           tabPane.setSelectedIndex(0);
                                           fk = ((BaseRow)uObject).getForeignKey();                                    
                                           ImageIcon im = getIm(fk);
                                           label.setIcon(im);
                                           //System.out.println("Mouse Image "+fk);
                                           //iIcon = getImage(fk);
                                           //updateMapPanel(fk);
                                           initChildrenTables(select);
                                           
                                           int cityId = ((CityRow)uObject).getCityId().intValue();
                                           thnPanel.clear();
                                           
                                           fillThumbnails(false, cityId);
                                           thnPanel.sort();
                                           thnPanel.recountOnResize(jspPhoto.getViewport().getWidth());
                                           thnPanel.repaint();
                                           break;
                                     }
                                     case BaseRow.CO_TYPE : {
                                           changeCard(rightCardPanel, CITY_CO_DSLAM_PANEL);
                                           Vector cov = getNodesThisLevel(coCollect, select);
                                           int selIndex = Collections.binarySearch(cov, select, new PrimaryKeyComparator());
                                           
                                           if (!isSameBranch(select,lastSelectedNode)) {
                                                 removeAllRows(coTable);
                                                 initCoTable(cov);
                                           }
                                           coTable.setRowSelectionInterval(selIndex, selIndex);
                                           
                                           tabPane.setSelectedIndex(1);
                                           
                                           initChildrenTables(select);
                                           initParentsTables(select);
                                           break;
                                     }
                                     case BaseRow.DSLAM_TYPE : {
                                           changeCard(rightCardPanel, CITY_CO_DSLAM_PANEL);
                                           Vector cod = getNodesThisLevel(dslamCollect, select);
                                           int selIndex = Collections.binarySearch(cod, select, new PrimaryKeyComparator());
                                           
                                           if (!isSameBranch(select,lastSelectedNode)) {
                                                 removeAllRows(dslamTable);
                                                 initDslamTable(cod);
                                           }
                                           dslamTable.setRowSelectionInterval(selIndex, selIndex);
                                           
                                           tabPane.setSelectedIndex(2);
                                           initChildrenTables(select);
                                           initParentsTables(select);
                                           
                                           break;
                                     }
                                     case BaseRow.LINECARD_TYPE : {
                                           changeCard(rightCardPanel, CITY_CO_DSLAM_PANEL);
                                           Vector col = getNodesThisLevel(linecardCollect, select);
                                           int selIndex = Collections.binarySearch(col, select, new PrimaryKeyComparator());
                                           
                                           if (!isSameBranch(select,lastSelectedNode))
                                           {
                                                 removeAllRows(linecardTable);
                                                 initLinecardTable(col);
                                           }
                                           linecardTable.setRowSelectionInterval(selIndex, selIndex);
                                           tabPane.setSelectedIndex(3);
                                           initParentsTables(select);
                                           break;
                                     }
                                     
                                     case BaseRow.NAME_TYPE : {
                                           String name = ((BaseRow)uObject).toString();
                                           if (name.equals("DSLAM"))
                                           {
                                                 changeCard(rightCardPanel, CITY_CO_DSLAM_PANEL);
                                                 DefaultMutableTreeNode pselect = (DefaultMutableTreeNode)select.getParent();
                                                 //System.out.println("AFTER   "+pselect);
                                                 Vector cov = getNodesThisLevel(coCollect, pselect);
                                                 //System.out.println("DSLAM "+cov.size());
                                               int selIndex = Collections.binarySearch(cov, pselect, new PrimaryKeyComparator());
                                               
                                               if (!isSameBranch(pselect,lastSelectedNode))
                                               {
                                                     removeAllRows(coTable);
                                                     initCoTable(cov);
                                               }
                                               coTable.setRowSelectionInterval(selIndex, selIndex);
                                               tabPane.setSelectedIndex(2);
                                               initChildrenTables(pselect);
                                               initParentsTables(pselect);
                                               
                                           }
                                           else
                                           {
                                                 changeCard(rightCardPanel, CO_DETALED_PANEL);
                                                 DefaultMutableTreeNode pselect = (DefaultMutableTreeNode)select.getParent();
                                                 co = (CoRow)pselect.getUserObject();                                   
                                                 
                                                 if (name.equals("TERMINAL"))
                                                 {
                                                       //System.out.println("INSIDE ");
                                                       //System.out.println("AFTER "+co.getCoId().toString()+" "+co.getCoEngName()+" "+co.getCoDirection());
                                                     //changeCard(innerCardPanel, MDF_PANEL);
                                                     coselect = (DefaultMutableTreeNode)select.getParent();
                                                     //return mdfData;
                                                     //Vector getMdfCollection(Connection connect,int id)
                                                     DefaultMutableTreeNode terminal = (DefaultMutableTreeNode)select;
                                                     //System.out.println("after C "+terminal);
                                                     cov = getTerminalNodesThisLevel(mdfCollect, coselect);
                                                     //System.out.println("after TERMINAL CLCIKED"+cov.toString());
                                                     vc = getTerminalPriNodesThisLevel(mdfCollect, coselect);
                                                     //System.out.println("after TERMINAL CLCIKED"+vc.toString());
                                                     //Vector v = getMdfCollection(frame.getDBConnection(),int id);
                                                     buttonNo = cov.size();
                                                     //System.out.println("after Vector  "+buttonNo);
                                                     //rightCardPanel.removeAll();//Arrays.asList(node.getPath())
                                                     //System.out.println("after Vector  "+Arrays.asList(coselect.getPath()));
                                                     ///////TreeNode tn = coselect.getPath();
                                                     
                                                     paths = tree.getSelectionPaths();
                                                     paths1 = tree.getSelectionPath();
                                                     
                                                     Object[]path = null;
                                               if(paths == null)
                                               return;
                                               
                                               for(int i=0;i<paths.length;i++)
                                               {
                                                   path = paths[i].getPath();
                                                   for (int j=0; j<path.length; j++)
                                                   {
                                                       //System.out.print(path[j] + "/");
                                                   }
                                               }
                                              // System.out.println("-"+paths1);
                                               //expandNode(tree, paths1);
                                               //tree.expandPath(paths1);
                                                //tree.setSelectionPath(paths1);
                                                     coDetaledPanel = createTerminalPanel(createButtons(buttonNo,cov,vc,paths1,terminal),co.getCoDirection().intValue());
                                                     rightCardPanel.add(coDetaledPanel, CO_DETALED_PANEL);                                                    
                                                 changeCard(rightCardPanel, CO_DETALED_PANEL);
                                                 changeCard(innerCardPanel, MDF_PANEL);
                                                 rightCardPanel.revalidate();
                                                    rightCardPanel.repaint();
                                                
                                               }
                                                 /*else if (name.equals("SPLITTER"))
                                                 {
                                                     changeCard(innerCardPanel, SPLITTER_PANEL);
                                                   splitterTabPane.setSelectedIndex(0);
                                               }*/
                                           }
                                           break;
                                     }
                                     
                                     case BaseRow.MDF_TYPE : {
                                           changeCard(rightCardPanel, CO_DETALED_PANEL);
                                           changeCard(innerCardPanel, BUTTON_PANEL);
                                           //System.out.println("INSIDE MDF");
                                           DefaultMutableTreeNode pselect = (DefaultMutableTreeNode)select.getParent().getParent();
                                             CoRow co = (CoRow)pselect.getUserObject();
                                   
                                           Vector cov = getNodesThisLevel(mdfCollect, select);
                                           
                                           int selIndex = Collections.binarySearch(cov, select, new PrimaryKeyComparator());
                                           
                                           final Progress p = new Progress();
                                           try
                                     {
                                          p.runProgress();
                                          
                                     }
                                     catch(Exception e)
                                     {
                                           e.printStackTrace ();
                                     }
                                           Thread t = new Thread(new Runnable(){
                                                 public void run()
                                                 {
                                                       
                                                       try
                                                       {
                                                             //System.out.println("INSIDE TRY");
                                                             buttonPanel = createTerminalButtonsPanel(pk);
                                                             JScrollPane jspMap = new JScrollPane(buttonPanel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                                             innerCardPanel.add(jspMap, BUTTON_PANEL);
                                                             changeCard(rightCardPanel, CO_DETALED_PANEL);
                                                             changeCard(innerCardPanel, BUTTON_PANEL);
                                                             p.hide();
                                                       }
                                                       catch(Exception e)
                                                       {
                                                             e.printStackTrace ();
                                                       }                        
                                                 }
                                           });
                                /*Thread th = new Thread(new Runnable() {
                                         public void run() {
                                              
                                        try
                                          {
                                               p.runProgress();
                                               
                                          }
                                          catch(Exception e)
                                          {
                                                e.printStackTrace ();
                                          }
                                         }
                                     });*/
                                    
                                              
                               // th.start();                                      
                                t.start();                              
                               // th.destroy();
                                      
                                             
                                           if (!isSameBranch(select, lastSelectedNode))
                                           {
                                                 //System.out.println("pk  "+pk);
                                                 //removeAllRows(mdfTable);
                                                 //initMdfTable(cov);
                                           }
                                           //mdfTable.setRowSelectionInterval(selIndex, selIndex);
                                         
                                           break;
                                     }
                                     
                                     /*case BaseRow.SPLITTER_TYPE : {
                                           changeCard(rightCardPanel, CO_DETALED_PANEL);
                                           changeCard(innerCardPanel, SPLITTER_PANEL);
                                           
                                           DefaultMutableTreeNode pselect = (DefaultMutableTreeNode)select.getParent().getParent();
                                             CoRow co = (CoRow)pselect.getUserObject();
                                             
                                             coId.setText(co.getCoId().toString());
                                             coFarsiName.setText(co.getCoFarsiName());
                                             coEnglishName.setText(co.getCoEngName());
                                           Vector cov = getNodesThisLevel(splitterCollect, select);
                                           
                                           int selIndex = Collections.binarySearch(cov, select, new PrimaryKeyComparator());
                                           
                                           if (!isSameBranch(select, lastSelectedNode))
                                           {
                                                 removeAllRows(splitterTable);
                                                 initSplitterTable(cov);
                                           }
                                           splitterTable.setRowSelectionInterval(selIndex, selIndex);
 
                                           break;
                                     }*/

                              }
                              lastSelectedNode = select;
                        }
                  }
              }
                             
              public void mouseReleased(MouseEvent me)
              {
                    if (me.isPopupTrigger())
                    {
                          DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
                          //treePopupMenu.show(me.getComponent(), me.getX(), me.getY());
                          selPath = tree.getPathForLocation(me.getX(), me.getY());
                          //System.out.println(selPath.getLastPathComponent());
                          //System.out.println("selPath.getPath()  "+Arrays.asList(selPath.getPath()));
                          o = selPath.getPath();
                          /*for(int i=0;i<o.length;i++)
                          {
                                System.out.println("path  "+o[i]);
                          }*/
                          //System.out.println("path  "+selPath.getPathCount());
                          Object ob = selPath.getPathComponent(1);
                          //System.out.println("path q  "+ob);
                          Object obj = selPath.getLastPathComponent();
                          
                          String str= null;
                      if(obj != null)
                      {
                            DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode)obj;
                            //System.out.println("selectNode    "+selectNode.getLeafCount());
                            //System.out.println("selectNode    "+selPath.getParentPath().getLastPathComponent());
                            str = selPath.getParentPath().getLastPathComponent().toString();
                            //System.out.println("selectNode    "+str);
                            if (selectNode != lastSelectedNode)
                            {
                                  //System.out.println(selectNode);
                                  Object uObject = selectNode.getUserObject();
                                  ///System.out.println("clciked +++ "+uObject);
                                  
                                  //System.out.println("FK "+((BaseRow)uObject).getPrimaryKey());
                                  pk = ((BaseRow)uObject).getPrimaryKey();
                                  //System.out.println(" pk  "+pk);
                            }
                      }
                          
                          
                          if(selPath.getPathCount()== 2)
                          {            
                                treePopupMenu = createPopupMenuCo();
                                treePopupMenu.show(me.getComponent(), me.getX(), me.getY());
                                //System.out.println("path ss ");                                
                          }
                          
                          if(selPath.getPathCount()== 3)
                          {
                                treePopupMenu = createPopupMenuDslam();
                                treePopupMenu.show(me.getComponent(), me.getX(), me.getY());
                                //System.out.println("path ss ");
                          }
                          
                          /*if(selPath.getPathCount()== 5)
                          {
                                treePopupMenu = createPopupMenuLinecard();
                                treePopupMenu.show(me.getComponent(), me.getX(), me.getY());
                                //System.out.println("path ss ");
                          } */
                          
                          
                          if(selPath.getPathCount()== 6)
                          {
                                treePopupMenu = createPopupMenuLine();
                                treePopupMenu.show(me.getComponent(), me.getX(), me.getY());
                                //System.out.println("path ss ");
                          }
                          
                          if(str.equals("DSLAM"))
                          {
                                treePopupMenu = createPopupMenuLinecard();
                                treePopupMenu.show(me.getComponent(), me.getX(), me.getY());
                          }
                          
                          if(str.equals("TERMINAL"))
                          {
                                treePopupMenu = createPopupMenuTerminal();
                                treePopupMenu.show(me.getComponent(), me.getX(), me.getY());
                          }
                          
                          /*if(str.equals("SPLITTER"))
                          {
                                treePopupMenu = createPopupMenuSplitter();
                                treePopupMenu.show(me.getComponent(), me.getX(), me.getY());
                          }*/
                    }
              }
        });
       
        JScrollPane jsp = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
       
        rightCardPanel = new JPanel();
        rightCardPanel.setLayout(new CardLayout());
       
       
        //create tab panel
        tabPane = new JTabbedPane();
       
        JPanel cityPane = new JPanel(new BorderLayout());
       
       
       
        //createCityTable();
       
        if(privilege == 1 || privilege == 0)
        {
              createCityTable();      
        }
        else if(privilege == 2)
        {
              createCityPrivilegeTable();
        }
        else if(privilege == 3)
        {
              createCityPrivilegeTable();
        }
       
       
       
        JScrollPane jspCity = new JScrollPane(cityTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        cityPane.add(jspCity, BorderLayout.CENTER);
        tabPane.addTab("  City  ", cityIcon, cityPane);
       
        JPanel coPane = new JPanel(new BorderLayout());
        createCoTable();
        JScrollPane jspCo = new JScrollPane(coTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        coPane.add(jspCo, BorderLayout.CENTER);
        tabPane.addTab("   Co   ", coIcon, coPane);
       
        JPanel dslamPane = new JPanel(new BorderLayout());
        createDslamTable();
        JScrollPane jspDslam = new JScrollPane(dslamTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        dslamPane.add(jspDslam, BorderLayout.CENTER);
        tabPane.addTab("  Dslam  ", dslamIcon, dslamPane);
       
       
        JPanel linecardPane = new JPanel(new BorderLayout());
        createlinecardTable();
        JScrollPane jspLinecard = new JScrollPane(linecardTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        linecardPane.add(jspLinecard, BorderLayout.CENTER);
        tabPane.addTab("  Linecard  ", linecardIcon, linecardPane);
       
        mapPane = new JPanel(new BorderLayout());
        label = getImage(fk);
        //System.out.println("foreign "+fk);
         //iIcon = DBImage.dbImage(29);
        //iIcon = DBImage.dbImage(fk);
        //cityMap = new ImageIcon(getClass().getResource("/images/tehran.gif"));
       
        //System.out.print("Image "+iIcon);
        jspMap = new JScrollPane(label,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
       
        mapPane.add(jspMap, BorderLayout.CENTER);
        tabPane.addTab("  Map  ", mapIcon, mapPane);
       
       
       JPanel photoPane = new JPanel(new BorderLayout());
       
        JToolBar photoControlPanel = new JToolBar();
        photoControlPanel.setFloatable(false);
        JButton addPhoto = new JButton(addIcon);
        addPhoto.addMouseListener(new MouseAdapter() {
              public void mousePressed(MouseEvent me) {
                    BaseRow row = (BaseRow)lastSelectedNode.getUserObject();
                    //System.out.println("button clicked");
                    if (row.getType() == BaseRow.CO_TYPE)
                    {
                          int coId = ((CoRow)row).getCoId().intValue();
                          String coName = ((CoRow)row).getCoEngName();
                          
                          String startDir = "";
                          if (homeDir.length() == 0)
                          {
                                startDir = (String)System.getProperty("user.dir", "c:\\");
                          }
                          else
                          {
                                startDir = homeDir;
                          }
                          
                          JFileChooser fc = new JFileChooser(startDir);
                          fc.addChoosableFileFilter(new PictExtentionFilter());
                          fc.setDialogTitle("UpLoad picture into DB");
                          fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                          fc.setMultiSelectionEnabled(false);
                          fc.setApproveButtonText("Load");
                          if (fc.showDialog(frame, "Load") == JFileChooser.APPROVE_OPTION )
                          {
                                File file = fc.getSelectedFile();
                                String name = file.getName();
                                String path = file.getPath();
                                String ext = "";
                                if (name.indexOf(".") > 0)
                                {
                                      ext = name.substring(name.indexOf(".") + 1);
                                }
                                
                                String data = readPhotoFromFile(path);
                                //int aid = insertPhoto(data, name, path, ext, coId);
                                int aid = insertPhoto(data, name, path, ext, coId);
                                
                                if (aid != -1)
                                {
                                      thnPanel.addElement(aid, name, coId, coName, data);
                                      thnPanel.recountOnResize(jspPhoto.getViewport().getWidth());
                                      thnPanel.repaint();
                                      homeDir = path;
                                }
                          }      
                    }
              }
        });
        photoControlPanel.add(addPhoto);
       
       
        JButton delPhoto = new JButton(delIcon);
        delPhoto.addMouseListener(new MouseAdapter() {
              public void mousePressed(MouseEvent me) {
                    int si = thnPanel.getSelectedIndex();
                    if (si != -1) {
                          int aid = thnPanel.getSelectedId();
                          deletePhotoFromDB(aid);
                          thnPanel.removeElement(si);
                    }
              }
        });
        photoControlPanel.add(delPhoto);
        photoPane.add(photoControlPanel, BorderLayout.NORTH);
       
        thnPanel = new ThumbnailPanel(this);
       
        jspPhoto = new JScrollPane(thnPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        jspPhoto.addComponentListener(new ComponentAdapter() {
                  public void componentResized(ComponentEvent ce) {
                    thnPanel.recountOnResize(jspPhoto.getViewport().getWidth());
                  }
            });
        photoPane.add(jspPhoto, BorderLayout.CENTER);
       
        tabPane.addTab("  Photo  ", photoIcon, photoPane);
       
        rightCardPanel.add(tabPane, CITY_CO_DSLAM_PANEL);
       
        //JPanel coDetaledPanel = createCoDetaledPanel();
        //System.out.println("AFTER"+co.getCoId().toString()+" "+co.getCoEngName());
       
        coDetaledPanel = createTerminalPanel(createButtons(buttonNo,cov,vc,null,null),0);
        rightCardPanel.add(coDetaledPanel, CO_DETALED_PANEL);
        rightCardPanel.revalidate();
        rightCardPanel.repaint();

        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jsp,  rightCardPanel);
        splitPane.setDividerLocation(160);

        cp.add(splitPane, BorderLayout.CENTER);
       
       
        addInternalFrameListener(new InternalFrameAdapter() {
              public void internalFrameClosing(InternalFrameEvent ife) {
                    frame.setInnerFrameNull();  
              }
        });
 
    }//end of constr
   
    /*public void run()
      {
          System.out.println("Hello from zzzzzz thread!");
          while(true)
          {
            // wait for the signal from the GUI
               try{synchronized(this){wait();}}
               catch (InterruptedException e){}
            // simulate some long-running process like parsing a large file
               buttonPanel = createTerminalButtonsPanel(pk);
       }

      }  */  
   
    public JLabel getImage(int fkey)
      {
            ImageIcon iIcon = DBImage.dbImage(fkey);
            JLabel label = new JLabel(iIcon);
            return label;
      }
   
    public ImageIcon getIm(int fkey)
      {
            ImageIcon iIcon = DBImage.dbImage(fkey);
            
            return iIcon;
      }
   
    public void updateMapPanel(int fk)
    {
          label = getImage(fk);
          jspMap = new JScrollPane(label,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
          mapPane.add(jspMap, BorderLayout.CENTER);
          tabPane.addTab("  Map  ", mapIcon, mapPane);
       
        //rightCardPanel.add(tabPane, CITY_CO_DSLAM_PANEL);
    }
   
    private void changeCard(JPanel panel, String cardName)
    {
          //System.out.println("inside changeCard CLCIKED     "+cardName);
          
          ((CardLayout)panel.getLayout()).show(panel, cardName);
    }
   
   
    public JPanel createTerminalButtonsPanel(int pk)
    {          
          JPanel panel = new JPanel();
          JButton[] buttons = new JButton[200];
          int num_port =0;
          //JButton butt = new JButton();
          try
          {
                String dslamLinecard= "SELECT     dbo.Bookht_Terminals.TERMINAL_ID, dbo.Bookht_Terminal_Brands.NUM_PORT "+
                "FROM dbo.Bookht_Terminals INNER JOIN "+
                      "dbo.Bookht_Terminal_Brands ON dbo.Bookht_Terminals.TERMINAL_B_ID = dbo.Bookht_Terminal_Brands.TERMINAL_B_ID WHERE     (dbo.Bookht_Terminals.TERMINAL_ID =  '"+pk+"')";
           
            //System.out.println("Query    "+dslamLinecard);
            Connection connect = PictMenuFrameDemo.getDBConnection();
              Statement s = connect.createStatement();           
              
              ResultSet r = s.executeQuery(dslamLinecard);
              
              while(r.next())
              {
                    num_port = r.getInt("NUM_PORT");
              }
          }
          catch (SQLException sqle)
          {
                System.err.println("Can't get Terminal collection from database : " + sqle.getMessage());
          }  
 
          int i=0;
        final int pklinecard = pk;
          //panel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        panel.setBorder(new EmptyBorder(15, 15, 15, 15));
       
        //System.out.println("num_port    "+num_port);
       
        if(num_port > 54 && num_port <= 100)
        {
              //System.out.println("num_port  1  "+num_port);
              panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
              panel.setLayout(new GridLayout(10, 10, 15, 15));
              panel.setPreferredSize(new Dimension(1500,700));
        }
        else if(num_port > 100 && num_port <= 200)
        {
              //System.out.println("num_port  2  "+num_port);
              panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
              panel.setLayout(new GridLayout(20, 10, 15, 15));
              panel.setPreferredSize(new Dimension(1500,1400));
              //System.out.println(panel.getLayout());
        }
        else if(num_port > 0 && num_port <= 54)
        {
              //System.out.println("num_port   3 "+num_port);
              panel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
              panel.setLayout(new GridLayout(9, 6, 15, 15));
              panel.setPreferredSize(new Dimension(1000,600));
        }
       

        int block = 0;
        int row = 0;
        int slot = 0;
        int dportno = 0;
        int tport_no = 0;
        int terminal_port_id = 0;
        int portal_state_id = 0;
        int co_id = 0;
        ActionListener actionListener = null;
        String ip = null;
        String str2 = null;
        ResultSet rs;
        ResultSet rs1=null;
       
        //String dslamLinecard= "Select t.co_id,tp.portal_state_id,tp.terminal_id,tp.terminal_port_id,lc.slot,ds.ip,dsl.dport_no,tp.tport_no,t.terminalblock,t.terminalrow From bookht_terminal_ports tp,bookht_DSLPorts dsl,bookht_linecards lc,dslams ds,bookht_terminals t Where tp.terminal_id = '"+pk+"' "+" and t.terminal_id = tp.terminal_id and tp.dslport_id = dsl.dslport_id and dsl.linecard_id = lc.linecard_id and lc.dslam_id = ds.id order by tp.tport_no";
       
        String dslamLinecard= "SELECT t.CO_ID, tp.PORTAL_STATE_ID,tp.PhoneNumber, tp.TERMINAL_ID, tp.TERMINAL_PORT_ID, lc.SLOT, ds.IP, dsl.DPORT_NO, tp.TPORT_NO, t.TERMINALBLOCK,t.TERMINALROW FROM dbo.Bookht_LineCards AS lc INNER JOIN dbo.Bookht_DSLPorts AS dsl ON lc.LINECARD_ID = dsl.LINECARD_ID INNER JOIN dbo.DSLAMS AS ds ON lc.DSLAM_ID = ds.ID RIGHT OUTER JOIN dbo.Bookht_Terminal_Ports AS tp INNER JOIN dbo.Bookht_Terminals AS t ON tp.TERMINAL_ID = t.TERMINAL_ID ON dsl.DSLPORT_ID = tp.DSLPORT_ID WHERE (tp.TERMINAL_ID = '"+pk+"') ORDER BY tp.TPORT_NO";
       
        //System.out.println("Query    "+dslamLinecard);
        Connection connect = PictMenuFrameDemo.getDBConnection();
       
       
       
        try
          {
              Statement st = connect.createStatement();           
              Statement st1 = connect.createStatement();
              rs = st.executeQuery(dslamLinecard);
              
              while(rs.next())
              {
                    co_id = rs.getInt("co_id");
              }
              
              //String customerName = SimpleJdbc.getCustomerName(co_id);
              //System.out.println(customerName);
              
              rs1 = st.executeQuery(dslamLinecard);
              if(ip == null || slot==0 || dportno == 0 )
                {
                      str2 = " ";
                }
                else
                {
                      str2 = ip+" - "+slot+" - "+dportno;
                }               
                
              while(rs1.next())
              {
                    portal_state_id = rs1.getInt("portal_state_id");
                    slot = rs1.getInt("SLOT");
                    //System.out.println(slot);
                    ip = rs1.getString("IP");
                    dportno = rs1.getInt("dport_no");
                    block = rs1.getInt("terminalblock");
                    row = rs1.getInt("terminalrow");
                    tport_no = rs1.getInt("tport_no");
                    //terminal_id = rs1.getInt("terminal_port_id");
                    terminal_port_id = rs1.getInt("terminal_port_id");
                    
                    //String customerName = SimpleJdbc.getCustomerName(block,row,tport_no,co_id);
                    String customerName = rs1.getString("PhoneNumber");
                    
                    
                    //customerName = "2222222222";
                    /*if(((portal_state_id == 1) || (portal_state_id == 2)) && customerName != null )
                    {
                          String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '4' WHERE terminal_id ='"+pk+"' AND tport_no ='"+tport_no +"'";
                            //System.out.println(terminaPortQuery);
                            st1.executeUpdate(terminaPortQuery);
                    }*/
                    int flag = 0;
                    String label = null;
                    if(ip == null || slot==0 || dportno == 0 )
                      {
                            str2 = " ";
                          //str2 = ip+" - "+slot+" - "+dportno;
                            flag = 1;
                      }
                      else
                      {
                            str2 = ip+" - "+slot+" - "+dportno;
                            flag = 1;
                      }
                    
                    String str = block+" - "+row+" - "+tport_no;
                    
                    if(flag == 0)
                    {
                          ////label = "<html><center>"+str+"<center></html>";
                          if(customerName == null)
                          {
                                label = "<html><center>"+str+"<br>"+str2+"<br>"+" "+"<center></html>";
                          }
                          else
                          {
                                label = "<html><center>"+str+"<br>"+str2+"<br>"+customerName+"<center></html>";      
                          }      
                    }
                    else
                    {
                          if(customerName == null)
                          {
                                label = "<html><center>"+str+"<br>"+str2+"<br>"+" "+"<center></html>";
                          }
                          else
                          {
                                label = "<html><center>"+str+"<br>"+str2+"<br>"+customerName+"<center></html>";      
                          }                          
                    }
                    /*if(((portal_state_id == 1) || (portal_state_id == 2)) && customerName != null )
                    {
                          String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '4' WHERE terminal_id ='"+pk+"' AND tport_no ='"+tport_no +"'";
                            System.out.println(terminaPortQuery);
                            st.executeUpdate(terminaPortQuery);
                    }*/
                    buttons[i] = new JButton();
                  final JPopupMenu menu = new JPopupMenu();
                  
                  // Create and add a menu item
                  JMenuItem portMap = new JMenuItem("Define Port Mapping");
                  JMenuItem portState = new JMenuItem("Set Port State");
                  JMenuItem portHistory = new JMenuItem("Port History");
                  JMenuItem assignBucht  = new JMenuItem("Assign Bucht");
                  JMenuItem freeBucht  = new JMenuItem("Free Bucht");
                  
                  menu.add(portMap);
                  portMap.addActionListener(actionListener);
                  portState.addActionListener(actionListener);
                  portHistory.addActionListener(actionListener);
                  assignBucht.addActionListener(actionListener);
                  freeBucht.addActionListener(actionListener);
                  
                  menu.add(portState);
                  menu.add(new JSeparator());
                  menu.add(portHistory);
                  menu.add(new JSeparator());
                  menu.add(assignBucht);
                  menu.add(freeBucht);
                  
                  ActionListener list = new ButtonData(terminal_port_id,pklinecard,tport_no,customerName);
                  
                  
                  portMap.addActionListener(list);
                  portState.addActionListener(list);
                  portHistory.addActionListener(list);
                  assignBucht.addActionListener(list);
                  freeBucht.addActionListener(list);
                  //Integer tPortNo = new Integer(terminal_port_id);
                  //System.out.println(tPortNo.toString());
                  //portMap.setActionCommand(tPortNo.toString());
                  buttons[i].setMargin(new Insets(0,0,0,0));
                  buttons[i].setFont(new Font("Arial", Font.PLAIN, 12));
                  buttons[i].setBorder(null);
                  buttons[i].setVerticalAlignment(SwingConstants.TOP);
                  buttons[i].setHorizontalAlignment(SwingConstants.CENTER);
                  //buttons[i].setBorderPainted(false);
                  buttons[i].setFocusPainted(false);
                  buttons[i].setText(label);
                  
                  if(((portal_state_id == 1) || (portal_state_id == 2)) && customerName != null )
                  //if(customerName != null && portal_state_id == 2)
                  {//In TCI
                        Connection connects = PictMenuFrameDemo.getDBConnection();
                        Statement ste = connects.createStatement();
                        String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '8' WHERE terminal_port_id ='"+terminal_port_id +"'";
                            //System.out.println(terminaPortQuery);
                            //System.exit(0);
                            ste.executeUpdate(terminaPortQuery);
                        buttons[i].setBackground(new Color(235, 199, 158));
                  }
                  else if((ip != null && customerName == null) && (portal_state_id == 4 || portal_state_id == 7 || portal_state_id == 9))
                  {
                        Connection connects = PictMenuFrameDemo.getDBConnection();
                        Statement ste = connects.createStatement();
                        String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '11' WHERE terminal_port_id ='"+terminal_port_id +"'";
                            //System.out.println(terminaPortQuery);
                            //System.exit(0);
                            ste.executeUpdate(terminaPortQuery);
                        buttons[i].setBackground(new Color(173, 234, 234));
                  }
                  else if((ip != null && customerName == null) && (portal_state_id == 10 ))
                  {
                        Connection connects = PictMenuFrameDemo.getDBConnection();
                        Statement ste = connects.createStatement();
                        String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '2' WHERE terminal_port_id ='"+terminal_port_id +"'";
                            //System.out.println(terminaPortQuery);
                            //System.exit(0);
                            ste.executeUpdate(terminaPortQuery);
                            buttons[i].setBackground(Color.WHITE);
                  }
                  else if((ip != null && customerName != null) && (portal_state_id == 11 ))
                  {
                        Connection connects = PictMenuFrameDemo.getDBConnection();
                        Statement ste = connects.createStatement();
                        String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '4' WHERE terminal_port_id ='"+terminal_port_id +"'";
                            //System.out.println(terminaPortQuery);
                            //System.exit(0);
                            ste.executeUpdate(terminaPortQuery);
                            buttons[i].setBackground(Color.WHITE);
                  }
                  /*else if((ip != null && customerName != null) && (portal_state_id == 8 ))
                  {
                        Connection connects = PictMenuFrameDemo.getDBConnection();
                        Statement ste = connects.createStatement();
                        String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '4' WHERE terminal_port_id ='"+terminal_port_id +"'";
                            //System.out.println(terminaPortQuery);
                            //System.exit(0);
                            ste.executeUpdate(terminaPortQuery);
                            buttons[i].setBackground(Color.WHITE);
                  }*/
                  else
                  {
                        if(portal_state_id == 1)
                        {//no mapping
                              buttons[i].setBackground(Color.GRAY);
                        }
                        else if(portal_state_id == 2)
                        {//ready to use
                              buttons[i].setBackground(Color.WHITE);
                        }
                        else if(portal_state_id == 3)
                        {//problem
                              buttons[i].setBackground(new Color(153, 102, 0));
                        }
                        else if(portal_state_id == 4)
                        {//Active User - Used
                              buttons[i].setBackground(Color.GREEN);
                        }
                        else if(portal_state_id == 5)
                        {//Reserved
                              buttons[i].setBackground(Color.BLUE);
                        }
                        else if(portal_state_id == 6)
                        {//Out of Service
                              buttons[i].setBackground(Color.RED);
                        }
                        else if(portal_state_id == 7)
                        {//Approved Krone
                              buttons[i].setBackground(Color.ORANGE);
                        }
                        else if(portal_state_id == 8)
                        {//Under Constr
                              buttons[i].setBackground(new Color(235, 199, 158));
                        }
                        else if(portal_state_id == 9)
                        {//Installed not used
                              buttons[i].setBackground(Color.PINK);
                        }
                        else if(portal_state_id == 10)
                        {//PCM/PGS
                              buttons[i].setBackground(Color.LIGHT_GRAY);
                        }
                        else if(portal_state_id == 11)
                        {//Questionable Bookht label.setBackground(new Color(255, 0, 0));
                              buttons[i].setBackground(new Color(173, 234, 234));
                        }
                  }
                  panel.add(buttons[i]);
                  
//                Set the component to show the popup menu
                  buttons[i].addMouseListener(new MouseAdapter() {
                      public void mousePressed(MouseEvent evt) {
                          if (evt.isPopupTrigger()) {
                              menu.show(evt.getComponent(), evt.getX(), evt.getY());
                          }
                      }
                      public void mouseReleased(MouseEvent evt) {
                          if (evt.isPopupTrigger()) {
                              menu.show(evt.getComponent(), evt.getX(), evt.getY());
                          }
                      }
                  });
                  i++;
              }//while
                  
              
          }
          catch (SQLException sqle)
          {
                System.err.println("Can't get Terminal collection from database : " + sqle.getMessage());
          }  
          /*catch (ClassNotFoundException csqle)
          {
                System.err.println("Can't get Ports collection from database : " + csqle.getMessage());
          } */
          return panel;
    }
     
     
    private JPanel createTerminalPanel(JButton[] buttons,int dirc)
    {  
          //System.out.println(buttons.length);
          GridBagLayout layout = new GridBagLayout();
          JPanel p = new JPanel(layout);
          innerCardPanel = new JPanel(new CardLayout());
          GridBagConstraints constraints = new GridBagConstraints();
          JPanel panel = new JPanel(new BorderLayout(0, 20));
          
          constraints.anchor=GridBagConstraints.NORTH;
          constraints.ipadx=0;
          constraints.ipady=0;
          constraints.fill=GridBagConstraints.BOTH;
          constraints.insets=new Insets(5,5,5,5);
          int direction = dirc;
          
          // Add first row of components
          constraints.gridx=0;
          constraints.gridy=0;
          
          for(int i = 0;i < buttons.length;i++)
          {
               if (direction == 0)
               {
                    // horizontal
                     constraints.gridx = i % 5;
                     constraints.gridy = i / 5;
               }
               else
               {
                    // vertical
                     constraints.gridx = i / 5;
                     constraints.gridy = i % 5;
               }
              
               layout.setConstraints(buttons[i],constraints);
                 p.add(buttons[i]);
          }
            
          innerCardPanel.add(p, MDF_PANEL);
          /*JPanel buttonPanel = createButtonsPanel();
          innerCardPanel.add(buttonPanel, BUTTON_PANEL);*/
          //panel.add(label);
          panel.add(BorderLayout.CENTER,innerCardPanel);
          
        return panel;
    }

    class NodeExpander implements ActionListener
    {
         private DefaultMutableTreeNode node = null;
         private DefaultMutableTreeNode select= null;
         TreePath treePath = null;
         
             public NodeExpander(DefaultMutableTreeNode node)
             {
                this.node = node;
             }
             
             public NodeExpander()
             {
               
             }

             public void actionPerformed(ActionEvent e)
            {
                   String str = e.getActionCommand();
                   String [] splitStr = str.split("-");
                   select = new DefaultMutableTreeNode(str);
                   tree.addTreeSelectionListener(new OidSelectionListener());
                   ResultSet rs;
                   int terminalID = 0;
                   TreeNode [] tn = node.getPath();
                   //System.out.println("TreeNode  City "+tn[1]+" CO "+tn[2]+" Block "+splitStr[0]+" Row "+splitStr[1]);      
                 //String terminalQuery = "select terminalrow,terminalblock from terminals WHERE terminal_id= '"+pk+"'";
                   String terminalQuery = " select t.terminal_id from bookht_terminals t, bookht_TelCenter co, city ci where co.CITYID = ci.pkid and co.NAME = '"+tn[2]+"'"+ "and ci.CITY = '"+tn[1]+"'"+ " and t.terminalblock = '"+splitStr[0]+"'"+ " and t.terminalrow ='"+splitStr[1]+"'"+ "";
                 //System.out.println(terminalQuery);  
                 //System.exit(0);
                 Connection connect = PictMenuFrameDemo.getDBConnection();
                 
                 try
                   {
                       Statement st = connect.createStatement();
                       rs = st.executeQuery(terminalQuery);
                       rs.next();
                      
                      terminalID = rs.getInt("terminal_id");                       
                                 
                   }
                   catch (SQLException sqle)
                   {
                         System.err.println("Can't get Terminal collection from database 1: " + sqle.getMessage());
                   }
                   
                   JPanel buttonPanel = createTerminalButtonsPanel(terminalID);
                   JScrollPane jspMap = new JScrollPane(buttonPanel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                      JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                   innerCardPanel.add(jspMap, BUTTON_PANEL);                 
                   //JPanel buttonPanel = createButtonsPanel(str);
                   //innerCardPanel.add(buttonPanel, BUTTON_PANEL);
                  // System.out.println("Path  "+Arrays.asList(node.getPath()));
                  
                   //System.out.println("Leaf Node  "+node);      
                   //System.out.println("Parent Node  "+node.getParent());
                   //System.out.println("Child Count  "+node.getChildCount());
                   //tree.expandPath(new TreePath(((DefaultMutableTreeNode)(node.getParent())).getPath()));
                   if (node.getChildCount() >= 0)
                   {
                         //System.out.println("INSIDE IF  "+node.getChildCount());
                        for (Enumeration en = node.children(); en.hasMoreElements(); )
                        {
                               DefaultMutableTreeNode n = (DefaultMutableTreeNode)en.nextElement();
                              //System.out.println("Leaf Count  "+n);
                             //System.out.println("Path  "+Arrays.asList(n.getPath()));
                               if (!n.isLeaf())
                                   continue;
                               if (n.toString().equals(str))
                               {
                                     tree.expandPath(new TreePath(n.getPath()));
                                     tree.setSelectionPath(new TreePath(n.getPath()));
                                   break;
                               }
                        }
                        
                   }
                   //changeCard(rightCardPanel, CO_DETALED_PANEL);
                     //changeCard(innerCardPanel, BUTTON_PANEL);
                     
                   //tree.expandPath(new TreePath(node.getPath()));
                   //System.out.println("Path  "+Arrays.asList(node.getPath()));
                 //tree.setSelectionPath(new TreePath(select.getPath()));
                 //System.out.println("Path  "+select.getParent());
                   //paths.pathByAddingChild(select);
            }        
    }

Author

Commented:


 case BaseRow.MDF_TYPE : {
------
is part of the node is used mostly.i mean it is expanded and creates Jbuttons onthe right side.
Zolf, -Xmx512m is just a limit; you can set it without much risk.
If your application really needs 256 then set -Xmx256m.

;JOOP!

Commented:
why do you define a thread inside ? however this thread will terminate but its object will remain in heap, because innerCardPanel is refering to them in heap.



buttonPanel = createTerminalButtonsPanel(pk);
                                                             JScrollPane jspMap = new JScrollPane(buttonPanel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                                             innerCardPanel.add(jspMap, BUTTON_PANEL);
                                                             changeCard(rightCardPanel, CO_DETALED_PANEL);
                                                             changeCard(innerCardPanel, BUTTON_PANEL);


Author

Commented:

sciuriware:
how do i know how much memory my application requires.

mnrz:
please tell me what shouild i do now.appreciate your help.should i get rid of that thread

Author

Commented:

mnrz:
that thread i use to show a progrss bar while it finishes displaying the Jbutton with data from db.

Commented:
try to see if it works fine with no progress bar and no thread and then post  the result here

Author

Commented:


i removed the progress bar and the thread.but i get that heap error.the exception is below along with the code i changed.
case BaseRow.MDF_TYPE : {
                                           changeCard(rightCardPanel, CO_DETALED_PANEL);
                                           changeCard(innerCardPanel, BUTTON_PANEL);
                                           //System.out.println("INSIDE MDF");
                                           DefaultMutableTreeNode pselect = (DefaultMutableTreeNode)select.getParent().getParent();
                                             CoRow co = (CoRow)pselect.getUserObject();
                                   
                                           Vector cov = getNodesThisLevel(mdfCollect, select);
                                           
                                           int selIndex = Collections.binarySearch(cov, select, new PrimaryKeyComparator());
                                           
                                           /*final Progress p = new Progress();
                                           try
                                     {
                                          p.runProgress();
                                          
                                     }
                                     catch(Exception e)
                                     {
                                           e.printStackTrace ();
                                     }
                                           Thread t = new Thread(new Runnable(){
                                                 public void run()
                                                 {
                                                       
                                                       try
                                                       {*/
                                                             System.out.println("INSIDE TRY");
                                                             buttonPanel = createTerminalButtonsPanel(pk);
                                                             JScrollPane jspMap = new JScrollPane(buttonPanel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                                             innerCardPanel.add(jspMap, BUTTON_PANEL);
                                                             changeCard(rightCardPanel, CO_DETALED_PANEL);
                                                             changeCard(innerCardPanel, BUTTON_PANEL);
                                                             //p.hide();
                                                       /*}
                                                       catch(Exception e)
                                                       {
                                                             e.printStackTrace ();
                                                       }                        
                                                 }
                                           });*/
                                  
                                              
                               // th.start();                                      
                                //////////////////////////////////t.start();                              
                               // th.destroy();
                                      
                                             
                                           if (!isSameBranch(select, lastSelectedNode))
                                           {
                                                 
                                           }
                                                                                    
                                           break;
                                     }


Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
      at java.util.Arrays.copyOfRange(Unknown Source)
      at java.lang.String.<init>(Unknown Source)
      at java.lang.StringBuilder.toString(Unknown Source)
      at javax.swing.plaf.basic.BasicMenuItemUI.installDefaults(Unknown Source)
      at javax.swing.plaf.basic.BasicMenuItemUI.installUI(Unknown Source)
      at javax.swing.JComponent.setUI(Unknown Source)
      at javax.swing.AbstractButton.setUI(Unknown Source)
      at javax.swing.JMenuItem.setUI(Unknown Source)
      at javax.swing.JMenuItem.updateUI(Unknown Source)
      at javax.swing.JMenuItem.init(Unknown Source)
      at javax.swing.JMenuItem.<init>(Unknown Source)
      at javax.swing.JMenuItem.<init>(Unknown Source)
      at src.com.victa.TreeTableInternalFrame.createTerminalButtonsPanel(TreeTableInternalFrame.java:1036)
      at src.com.victa.TreeTableInternalFrame$1.mousePressed(TreeTableInternalFrame.java:458)
      at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
      at java.awt.Component.processMouseEvent(Unknown Source)
      at javax.swing.JComponent.processMouseEvent(Unknown Source)
      at java.awt.Component.processEvent(Unknown Source)
      at java.awt.Container.processEvent(Unknown Source)
      at java.awt.Component.dispatchEventImpl(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Window.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

Author

Commented:


also my createTerminalButtonsPanel(int pk) is called every time i click on a node.this method connects to the db and gets the data.could you please have a look at that method and tell me if i am closing the jdbc after use.please help.

Commented:
what is in this line:

src.com.victa.TreeTableInternalFrame.createTerminalButtonsPanel(TreeTableInternalFrame.java:1036)

>>TreeTableInternalFrame.java:1036

Author

Commented:

this line is in that createTerminalButtonsPanel(int pk) method and the line 1036 is

JMenuItem assignBucht  = new JMenuItem("Assign Bucht");

you can see the code for that method in my first comment

Commented:
first, you didn't close you connections at all, before getting new connection from the PictMenuFrameDemo.getDBConnection(); you should close your last connection

second, the createTerminalButtonsPanel() method returns a JPanel that contains lots of objects before calling this method for second time you should remove the last returned JPanel or aligible it to be GCed by the JVM, you can set it to null or release all objects inside
 

Commented:
take a look here:

JPanel buttonPanel = createTerminalButtonsPanel(terminalID);
JScrollPane jspMap = new JScrollPane(buttonPanel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                      JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
innerCardPanel.add(jspMap, BUTTON_PANEL);      

each time user clicks on a node you create a JPanel and a JScrollPane and add it to innserCardPanel, next time that user click on another node and you add another JScrollPane to innerCardPanel !!!!
you must somehow release the last one

Author

Commented:

mnrz
can you please help me to close the connection and get rid of previous objects.can you guide me more in my code.please

cheers
zolf

Author

Commented:

i added a finally clause which closes the jdbc objects.but when i add the connect.close i get error saying connection is closed.then when i comment the two connect.close it works but i again get that heap space error.my code is below showing that finally clause

    public JPanel createTerminalButtonsPanel(int pk)
    {          
          JPanel panel = new JPanel();
          JButton[] buttons = new JButton[200];
          int num_port =0;
          //JButton butt = new JButton();
          Connection connect = null;
          Statement s  = null;
          ResultSet r = null;
          try
          {
                String dslamLinecard= "SELECT     dbo.Bookht_Terminals.TERMINAL_ID, dbo.Bookht_Terminal_Brands.NUM_PORT "+
                "FROM dbo.Bookht_Terminals INNER JOIN "+
                      "dbo.Bookht_Terminal_Brands ON dbo.Bookht_Terminals.TERMINAL_B_ID = dbo.Bookht_Terminal_Brands.TERMINAL_B_ID WHERE     (dbo.Bookht_Terminals.TERMINAL_ID =  '"+pk+"')";
           
            //System.out.println("Query    "+dslamLinecard);
            connect = PictMenuFrameDemo.getDBConnection();
              s = connect.createStatement();           
              
              r = s.executeQuery(dslamLinecard);
              
              while(r.next())
              {
                    num_port = r.getInt("NUM_PORT");
              }
          }
          catch (SQLException sqle)
          {
                System.err.println("Can't get Terminal collection from database : " + sqle.getMessage());
          }
          finally
        {
            try
            {
                if (r != null)
                    r.close();
            }
            catch (Exception e)
            {
                // it's a good idea to log it!
                  System.err.println("Cannot close ResultSet "+ e);
            }
            try
            {
                if (s != null)
                    s.close();
            }
            catch (Exception e)
            {
                // it's a good idea to log it!
                  System.err.println("Cannot close Statement "+ e);
            }
            /*try
            {
                if (connect  != null)
                      connect.close();
            }
            catch (SQLException e)
            {
                // it's a good idea to log it!
                  System.err.println("Cannot close Connection "+ e);
            }*/
        }

 
          int i=0;
        final int pklinecard = pk;
          //panel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        panel.setBorder(new EmptyBorder(15, 15, 15, 15));
       
        //System.out.println("num_port    "+num_port);
       
        if(num_port > 54 && num_port <= 100)
        {
              //System.out.println("num_port  1  "+num_port);
              panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
              panel.setLayout(new GridLayout(10, 10, 15, 15));
              panel.setPreferredSize(new Dimension(1500,700));
        }
        else if(num_port > 100 && num_port <= 200)
        {
              //System.out.println("num_port  2  "+num_port);
              panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
              panel.setLayout(new GridLayout(20, 10, 15, 15));
              panel.setPreferredSize(new Dimension(1500,1400));
              //System.out.println(panel.getLayout());
        }
        else if(num_port > 0 && num_port <= 54)
        {
              //System.out.println("num_port   3 "+num_port);
              panel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
              panel.setLayout(new GridLayout(9, 6, 15, 15));
              panel.setPreferredSize(new Dimension(1000,600));
        }
       

        int block = 0;
        int row = 0;
        int slot = 0;
        int dportno = 0;
        int tport_no = 0;
        int terminal_port_id = 0;
        int portal_state_id = 0;
        int co_id = 0;
        ActionListener actionListener = null;
        String ip = null;
        String str2 = null;
        ResultSet rs = null;
        ResultSet rs1=null;
       
        //String dslamLinecard= "Select t.co_id,tp.portal_state_id,tp.terminal_id,tp.terminal_port_id,lc.slot,ds.ip,dsl.dport_no,tp.tport_no,t.terminalblock,t.terminalrow From bookht_terminal_ports tp,bookht_DSLPorts dsl,bookht_linecards lc,dslams ds,bookht_terminals t Where tp.terminal_id = '"+pk+"' "+" and t.terminal_id = tp.terminal_id and tp.dslport_id = dsl.dslport_id and dsl.linecard_id = lc.linecard_id and lc.dslam_id = ds.id order by tp.tport_no";
       
        String dslamLinecard= "SELECT t.CO_ID, tp.PORTAL_STATE_ID,tp.PhoneNumber, tp.TERMINAL_ID, tp.TERMINAL_PORT_ID, lc.SLOT, ds.IP, dsl.DPORT_NO, tp.TPORT_NO, t.TERMINALBLOCK,t.TERMINALROW FROM dbo.Bookht_LineCards AS lc INNER JOIN dbo.Bookht_DSLPorts AS dsl ON lc.LINECARD_ID = dsl.LINECARD_ID INNER JOIN dbo.DSLAMS AS ds ON lc.DSLAM_ID = ds.ID RIGHT OUTER JOIN dbo.Bookht_Terminal_Ports AS tp INNER JOIN dbo.Bookht_Terminals AS t ON tp.TERMINAL_ID = t.TERMINAL_ID ON dsl.DSLPORT_ID = tp.DSLPORT_ID WHERE (tp.TERMINAL_ID = '"+pk+"') ORDER BY tp.TPORT_NO";
       
        //System.out.println("Query    "+dslamLinecard);
        connect = PictMenuFrameDemo.getDBConnection();
        Statement st = null;
       
       
        try
          {
              st = connect.createStatement();           
             // Statement st1 = connect.createStatement();
              rs = st.executeQuery(dslamLinecard);
              
              while(rs.next())
              {
                    co_id = rs.getInt("co_id");
              }
              
              //String customerName = SimpleJdbc.getCustomerName(co_id);
              //System.out.println(customerName);
              
              rs1 = st.executeQuery(dslamLinecard);
              if(ip == null || slot==0 || dportno == 0 )
                {
                      str2 = " ";
                }
                else
                {
                      str2 = ip+" - "+slot+" - "+dportno;
                }               
                
              while(rs1.next())
              {
                    portal_state_id = rs1.getInt("portal_state_id");
                    slot = rs1.getInt("SLOT");
                    //System.out.println(slot);
                    ip = rs1.getString("IP");
                    dportno = rs1.getInt("dport_no");
                    block = rs1.getInt("terminalblock");
                    row = rs1.getInt("terminalrow");
                    tport_no = rs1.getInt("tport_no");
                    //terminal_id = rs1.getInt("terminal_port_id");
                    terminal_port_id = rs1.getInt("terminal_port_id");
                    
                    //String customerName = SimpleJdbc.getCustomerName(block,row,tport_no,co_id);
                    String customerName = rs1.getString("PhoneNumber");
                    
                    
                    //customerName = "2222222222";
                    /*if(((portal_state_id == 1) || (portal_state_id == 2)) && customerName != null )
                    {
                          String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '4' WHERE terminal_id ='"+pk+"' AND tport_no ='"+tport_no +"'";
                            //System.out.println(terminaPortQuery);
                            st1.executeUpdate(terminaPortQuery);
                    }*/
                    int flag = 0;
                    String label = null;
                    if(ip == null || slot==0 || dportno == 0 )
                      {
                            str2 = " ";
                          //str2 = ip+" - "+slot+" - "+dportno;
                            flag = 1;
                      }
                      else
                      {
                            str2 = ip+" - "+slot+" - "+dportno;
                            flag = 1;
                      }
                    
                    String str = block+" - "+row+" - "+tport_no;
                    
                    if(flag == 0)
                    {
                          ////label = "<html><center>"+str+"<center></html>";
                          if(customerName == null)
                          {
                                label = "<html><center>"+str+"<br>"+str2+"<br>"+" "+"<center></html>";
                          }
                          else
                          {
                                label = "<html><center>"+str+"<br>"+str2+"<br>"+customerName+"<center></html>";      
                          }      
                    }
                    else
                    {
                          if(customerName == null)
                          {
                                label = "<html><center>"+str+"<br>"+str2+"<br>"+" "+"<center></html>";
                          }
                          else
                          {
                                label = "<html><center>"+str+"<br>"+str2+"<br>"+customerName+"<center></html>";      
                          }                          
                    }
                    /*if(((portal_state_id == 1) || (portal_state_id == 2)) && customerName != null )
                    {
                          String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '4' WHERE terminal_id ='"+pk+"' AND tport_no ='"+tport_no +"'";
                            System.out.println(terminaPortQuery);
                            st.executeUpdate(terminaPortQuery);
                    }*/
                    buttons[i] = new JButton();
                  final JPopupMenu menu = new JPopupMenu();
                  
                  // Create and add a menu item
                  JMenuItem portMap = new JMenuItem("Define Port Mapping");
                  JMenuItem portState = new JMenuItem("Set Port State");
                  JMenuItem portHistory = new JMenuItem("Port History");
                  JMenuItem assignBucht  = new JMenuItem("Assign Bucht");
                  JMenuItem freeBucht  = new JMenuItem("Free Bucht");
                  
                  menu.add(portMap);
                  portMap.addActionListener(actionListener);
                  portState.addActionListener(actionListener);
                  portHistory.addActionListener(actionListener);
                  assignBucht.addActionListener(actionListener);
                  freeBucht.addActionListener(actionListener);
                  
                  menu.add(portState);
                  menu.add(new JSeparator());
                  menu.add(portHistory);
                  menu.add(new JSeparator());
                  menu.add(assignBucht);
                  menu.add(freeBucht);
                  
                  ActionListener list = new ButtonData(terminal_port_id,pklinecard,tport_no,customerName);
                  
                  
                  portMap.addActionListener(list);
                  portState.addActionListener(list);
                  portHistory.addActionListener(list);
                  assignBucht.addActionListener(list);
                  freeBucht.addActionListener(list);
                  //Integer tPortNo = new Integer(terminal_port_id);
                  //System.out.println(tPortNo.toString());
                  //portMap.setActionCommand(tPortNo.toString());
                  buttons[i].setMargin(new Insets(0,0,0,0));
                  buttons[i].setFont(new Font("Arial", Font.PLAIN, 12));
                  buttons[i].setBorder(null);
                  buttons[i].setVerticalAlignment(SwingConstants.TOP);
                  buttons[i].setHorizontalAlignment(SwingConstants.CENTER);
                  //buttons[i].setBorderPainted(false);
                  buttons[i].setFocusPainted(false);
                  buttons[i].setText(label);
                  
                  if(((portal_state_id == 1) || (portal_state_id == 2)) && customerName != null )
                  //if(customerName != null && portal_state_id == 2)
                  {//In TCI
                        Connection connects = PictMenuFrameDemo.getDBConnection();
                        Statement ste = connects.createStatement();
                        String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '8' WHERE terminal_port_id ='"+terminal_port_id +"'";
                            //System.out.println(terminaPortQuery);
                            //System.exit(0);
                            ste.executeUpdate(terminaPortQuery);
                        buttons[i].setBackground(new Color(235, 199, 158));
                  }
                  else if((ip != null && customerName == null) && (portal_state_id == 4 || portal_state_id == 7 || portal_state_id == 9))
                  {
                        Connection connects = PictMenuFrameDemo.getDBConnection();
                        Statement ste = connects.createStatement();
                        String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '11' WHERE terminal_port_id ='"+terminal_port_id +"'";
                            //System.out.println(terminaPortQuery);
                            //System.exit(0);
                            ste.executeUpdate(terminaPortQuery);
                        buttons[i].setBackground(new Color(173, 234, 234));
                  }
                  else if((ip != null && customerName == null) && (portal_state_id == 10 ))
                  {
                        Connection connects = PictMenuFrameDemo.getDBConnection();
                        Statement ste = connects.createStatement();
                        String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '2' WHERE terminal_port_id ='"+terminal_port_id +"'";
                            //System.out.println(terminaPortQuery);
                            //System.exit(0);
                            ste.executeUpdate(terminaPortQuery);
                            buttons[i].setBackground(Color.WHITE);
                  }
                  else if((ip != null && customerName != null) && (portal_state_id == 11 ))
                  {
                        Connection connects = PictMenuFrameDemo.getDBConnection();
                        Statement ste = connects.createStatement();
                        String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '4' WHERE terminal_port_id ='"+terminal_port_id +"'";
                            //System.out.println(terminaPortQuery);
                            //System.exit(0);
                            ste.executeUpdate(terminaPortQuery);
                            buttons[i].setBackground(Color.WHITE);
                  }
                  /*else if((ip != null && customerName != null) && (portal_state_id == 8 ))
                  {
                        Connection connects = PictMenuFrameDemo.getDBConnection();
                        Statement ste = connects.createStatement();
                        String terminaPortQuery = "UPDATE bookht_terminal_ports SET portal_state_id = '4' WHERE terminal_port_id ='"+terminal_port_id +"'";
                            //System.out.println(terminaPortQuery);
                            //System.exit(0);
                            ste.executeUpdate(terminaPortQuery);
                            buttons[i].setBackground(Color.WHITE);
                  }*/
                  else
                  {
                        if(portal_state_id == 1)
                        {//no mapping
                              buttons[i].setBackground(Color.GRAY);
                        }
                        else if(portal_state_id == 2)
                        {//ready to use
                              buttons[i].setBackground(Color.WHITE);
                        }
                        else if(portal_state_id == 3)
                        {//problem
                              buttons[i].setBackground(new Color(153, 102, 0));
                        }
                        else if(portal_state_id == 4)
                        {//Active User - Used
                              buttons[i].setBackground(Color.GREEN);
                        }
                        else if(portal_state_id == 5)
                        {//Reserved
                              buttons[i].setBackground(Color.BLUE);
                        }
                        else if(portal_state_id == 6)
                        {//Out of Service
                              buttons[i].setBackground(Color.RED);
                        }
                        else if(portal_state_id == 7)
                        {//Approved Krone
                              buttons[i].setBackground(Color.ORANGE);
                        }
                        else if(portal_state_id == 8)
                        {//Under Constr
                              buttons[i].setBackground(new Color(235, 199, 158));
                        }
                        else if(portal_state_id == 9)
                        {//Installed not used
                              buttons[i].setBackground(Color.PINK);
                        }
                        else if(portal_state_id == 10)
                        {//PCM/PGS
                              buttons[i].setBackground(Color.LIGHT_GRAY);
                        }
                        else if(portal_state_id == 11)
                        {//Questionable Bookht label.setBackground(new Color(255, 0, 0));
                              buttons[i].setBackground(new Color(173, 234, 234));
                        }
                  }
                  panel.add(buttons[i]);
                  
//                Set the component to show the popup menu
                  buttons[i].addMouseListener(new MouseAdapter() {
                      public void mousePressed(MouseEvent evt) {
                          if (evt.isPopupTrigger()) {
                              menu.show(evt.getComponent(), evt.getX(), evt.getY());
                          }
                      }
                      public void mouseReleased(MouseEvent evt) {
                          if (evt.isPopupTrigger()) {
                              menu.show(evt.getComponent(), evt.getX(), evt.getY());
                          }
                      }
                  });
                  i++;
              }//while
                  
              
          }
          catch (SQLException sqle)
          {
                System.err.println("Can't get Terminal collection from database : " + sqle.getMessage());
          }
          finally
        {
            try
            {
                if (rs != null)
                    rs.close();
            }
            catch (Exception e)
            {
                // it's a good idea to log it!
                  System.err.println("Cannot close ResultSet "+ e);
            }
            try
            {
                if (rs1 != null)
                    rs1.close();
            }
            catch (Exception e)
            {
                // it's a good idea to log it!
                  System.err.println("Cannot close ResultSet "+ e);
            }
            try
            {
                if (st != null)
                    st.close();
            }
            catch (Exception e)
            {
                // it's a good idea to log it!
                  System.err.println("Cannot close Statement "+ e);
            }
            /*try
            {
                if (connect  != null)
                      connect.close();
            }
            catch (SQLException e)
            {
                // it's a good idea to log it!
                  System.err.println("Cannot close Connection "+ e);
            }*/
        }
          /*catch (ClassNotFoundException csqle)
          {
                System.err.println("Can't get Ports collection from database : " + csqle.getMessage());
          } */
          return panel;
    }

Author

Commented:

for that second comment of yours regarding that JPanel and scrollpane.i changed my code like this below but i still get that error.can you please correct me.
>>second, the createTerminalButtonsPanel() method returns a JPanel that contains lots of objects >>before calling this method for second time you should remove the last returned JPanel or aligible it to >>be GCed by the JVM, you can set it to null or release all objects inside


case BaseRow.MDF_TYPE : {
                                           changeCard(rightCardPanel, CO_DETALED_PANEL);
                                           changeCard(innerCardPanel, BUTTON_PANEL);
                                           //System.out.println("INSIDE MDF");
                                           DefaultMutableTreeNode pselect = (DefaultMutableTreeNode)select.getParent().getParent();
                                             CoRow co = (CoRow)pselect.getUserObject();
                                   
                                           Vector cov = getNodesThisLevel(mdfCollect, select);
                                           
                                           int selIndex = Collections.binarySearch(cov, select, new PrimaryKeyComparator());
                                           JScrollPane jspMap = null;
                                           
                                                             System.out.println("INSIDE TRY");
                                                             buttonPanel = null;
                                                             buttonPanel = createTerminalButtonsPanel(pk);
                                                             jspMap = new JScrollPane(buttonPanel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                                             innerCardPanel.add(jspMap, BUTTON_PANEL);
                                                             changeCard(rightCardPanel, CO_DETALED_PANEL);
                                                             changeCard(innerCardPanel, BUTTON_PANEL);
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:

thanks mnrz for your time and help.
that innerCardPanel.removeAll(); which you mentioned i added it before innerCardPanel.add(jspMap, BUTTON_PANEL);
 but then it only displays the compoents for the first node and then nothing happens when i click on other jtree nodes.
i will close this question and open another question.

Commented:
but you could request a refund for your question instead of accepting solution

and please try this one

in your code you have:
JScrollPane jspMap = ....

define this as an instance variable in your class

private JScrollPane jspMap;

and each time you click on a node first you set the jspMap to null

jspMap = null;
jspMap = new JScrollPane(buttonPanel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

hope this work

Author

Commented:


thanks for that comment i did that.but still no luck.i think your previous comment to remove the old panel should solve the problem.but i dont know where to start from since i have finished the application and it is being used by users.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.