0 Replies Latest reply: Apr 21, 2014 1:47 PM by Gowtham US RSS

    In JPanel, Revalidate follows repaint method is not Working.

    Gowtham US


      Hi,

      I have been working for Drag and Drop Functionality. I just brief about my Problem :

      1. Drag element from File System and Drop into JPanel A [Componets are visible ]

      2. Again Dragging Element from JPanel A and Drop into another JPanel B. [Componets are visible ]

      3. At last, Dragging Element from JPanel B and Drop into another JPanel A [Componets are not visible]

       

      Now, I used revalidate and repaint method to refresh the Jpanel A. But no result still not visible and updating the newly added component. But invisible component is able to drag and Drop

       

      I tested Component visibilty by,

       

      isVisible(), isShowing(), isOpaque(). These methods are returning true,but not visible in JPanel A.

       

       

       

      Refer my code :


      public class LiquiDirFile extends JPanel implements MouseListener,PanelElements {
      /**
      *
      */
      private static final long serialVersionUID = 1L;

       

       

      private File file;
      private boolean isValid;
      private String taggedType = "";
      public LiquiDirFile(File file) {
      this.file = file;
      setName(file.getName());
      BoxLayout dragDropElementLayout = new BoxLayout(this,BoxLayout.Y_AXIS);
      setLayout(dragDropElementLayout);
      Dimension dimension = new Dimension(128, 125);
      setPreferredSize(dimension);
      setMinimumSize(dimension);
      setMaximumSize(dimension);
      setAutoscrolls(Boolean.FALSE);
      addMouseListener(this);
      }
      public void addElementContent(){
      JLabel imageLabel = null;
      ThumbnailIcon thumbNailIcon = null;
      Image img = null;
      if(file.isFile()){
      img = Images.DND_XML_FILE_ICON.getImage();
      }else if(file.isDirectory()){
      img = Images.DND_FOLDER_ICON.getImage();
      }
      thumbNailIcon = new ThumbnailIcon(img);
      imageLabel = new JLabel(thumbNailIcon);
      thumbNailIcon.setThumbWidth(180);
      thumbNailIcon.setThumbHeight(100);
      add(imageLabel);
      BorderLayout borderLayout = new BorderLayout();
      JPanel filePanel = new JPanel();
      filePanel.setLayout(borderLayout);
      filePanel.setPreferredSize(new Dimension(128, 22));
      filePanel.setBackground(Color.GRAY.brighter());
      JLabel fileLabel = new JLabel(file.getName());
      fileLabel.setToolTipText(file.getName());
      fileLabel.setPreferredSize(new Dimension(125, 22));
      fileLabel.setHorizontalAlignment(SwingConstants.CENTER);
      fileLabel.setFont(new Font("Calibri", Font.BOLD, 14));
      filePanel.add(fileLabel,BorderLayout.CENTER);
      JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
      separator.setBackground(Color.BLACK);
      add(separator);
      add(filePanel);
      //setBorder(BorderFactory.createLineBorder(Color.BLACK));
      int eleIndex = dropPanel.getComponentCount();
      System.out.println("\n\nBefore Element count :"+dropPanel.getComponentCount()+"\n\n");
      System.out.println("--------------------------------");
      System.out.println(this);
      System.out.println("--------------------------------");
      dropPanel.add(this,eleIndex);
      System.out.println("\n\nAfter Element Count :"+dropPanel.getComponentCount()+"\n\n");
      dropPanel.revalidate();
      dropPanel.repaint();
      System.out.println("Opaque : "+this.isOpaque());//Returns true
      System.out.println("Visible : "+this.isVisible());//Returns true
      System.out.println("Showing : "+this.isShowing());//Returns true
      DragSource dragSource  = new DragSource();
      dragSource.createDefaultDragGestureRecognizer(this,DnDConstants.ACTION_MOVE, new DropToPanelListener(dropPanel));
      }