0

How can I do double click on JTree of my laptop to transfer files to server using FTP4j thank you

public void mouseClicked(MouseEvent e) {
    String s = arbre.getLastSelectedPathComponent().toString();
    File file = new File(s);
    if(file.isFile()) {
        System.out.println("c'est un fichier");
        if(e.getClickCount()==2){
      client.upload(file);
      }
}
DNA
  • 42,007
  • 12
  • 107
  • 146
  • Which part are you having issues with? Double clicking a `JTree` node or transferring the files with ftp4j? – MadProgrammer Mar 11 '14 at 22:34
  • part of using double click to transfer files: detect double click if it is file and transfer using upload the problem is how to do it I am not able to code it –  Mar 11 '14 at 23:04

1 Answers1

2

Using getClickCount(), you can detect double clicks in a MouseListener, as shown here. Start the transfer in your implementation of the doInBackground() method of SwingWorker. Use setProgress() to notify a listening progress indicator as the transfer proceeds, as shown here. You can show progress in a TreeCellRenderer, illustrated here. Beacuase nodes share the same renderer, you'll need to store progress elsewhere , typically in your implementation of TreeModel.

Addendum: A very simple way to display a JTree of files is shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Can You please give me an example of source code ? I don't understand You, I am just beginner in programming best regards –  Mar 11 '14 at 23:00
  • Something like [this](http://techdive.in/java/ftp4j-file-transfer-protocol-tutorial)? – trashgod Mar 12 '14 at 00:47
  • Can you please give me a program I'm just beginner –  Mar 12 '14 at 00:53
  • 1
    Essen unfortunely there is no an easy way. You have to learn by your own, not "do the job for me". Take a look to [tutorials](http://docs.oracle.com/javase/tutorial/uiswing/) – nachokk Mar 12 '14 at 01:09