Jerry Waterman

Greenhorn
+ Follow
since Jan 09, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jerry Waterman

Getting this error   Can not set java.lang.String field application.SelectFile.tstDate1a to javafx.scene.control.DatePicker on line   "tstDate1a = tstDate1.toString();"

   @FXML
   TextField tfFileName;
   String vapprovalStringFileName;
   TextField display;
   @FXML
   DatePicker dp = new DatePicker();//localDate
   @FXML
   Date localDate;
   String firstRecord = null;
   int fID = 0;
   String fFileName = "";
   @FXML
   DatePicker tstDate1;
   @FXML
   String tstDate1a;
   @FXML
   TextArea vapprovalReason;
   String vapprovalReason1;
private void populateForm() {
int vapprovalReviewerID = 0;
TextArea vFileName = new TextArea();
//vFileName.setText(vapprovalFileName);// = "";
DBConnection dc;
dc = new DBConnection();
Connection conn = dc.Connect();
ResultSet rs = null;
try {
rs = conn.createStatement()
.executeQuery("Select approvalreviewerid,approvalfilename,approvaldatereceived,approvalreason "
    + "from approvalfiles where approvalreviewerid = "+MainWindowController.tID+" order by idapprovalfilesid");
} catch (SQLException e) {
e.printStackTrace();
}
try {
final DatePicker localDate = new DatePicker();
while (rs.next()) {
vapprovalReviewerID = rs.getInt(1);
vapprovalStringFileName   = rs.getString(2);
vFileName.appendText(vapprovalStringFileName);//.setText(vapprovalStringFileName);
//java.sql.Date sdatePicker = rs.getDate(3);//.getString(3);//.getString(3);//.getString(3);//tfFileName.setText(vapprovalStringFileName);//.getText()(vapprovalStringFileName);
String tstDate1 = rs.getString(3);
dataFN.addAll(new RequestFile(rs.getString(2)));
if (firstRecord == null) {
firstRecord = "fRecord";
fID = vapprovalReviewerID;
fFileName = vapprovalStringFileName;
tstDate1a = tstDate1.toString();
System.out.println("Selected date: " + tstDate1+"\tID="+fID+"\t\ttstDate1a="+tstDate1a+"\tfirstRecond="+firstRecord);
}
if (tstDate1 == null && tstDate1a == null) {
tstDate1 = " ";
//tstDate1a= " ";
}
//String tstDate1a = tstDate1.toString();
System.out.println("L#630, fID="+fID+"\t"+fFileName+"\t\ttstDate1a="+tstDate1a.toString());
vapprovalReason1 = rs.getString(4);
System.out.println("L#632, vapprovalReason1="+vapprovalReason1);
if(vapprovalReason1 != null) {
  vapprovalReason.appendText(vapprovalReason1);
} else {
vapprovalReason1 = "";
}
}
fileTable.setItems(dataFN);
rs.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("L#645, vapprovalID="+vapprovalReviewerID+"\tvFileName="+vFileName.getText()+"\t\ttf="+tfFileName+"\tDate="+datePicker);
String txtArea = vFileName.getText();
System.out.println("L#647, txtArea="+txtArea);
}
3 weeks ago
        Here is part of my code. Cannot drag and drop a "Word" doc into a JavaFX application
       (ListView using Scene Builder).

   package application;
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
   import java.io.FileOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.OutputStream;
   import java.net.URL;
   import java.nio.file.Files;
   import java.nio.file.Path;
   import java.nio.file.Paths;
   import java.nio.file.StandardCopyOption;
   import java.text.SimpleDateFormat;
   import java.util.Date;
   import java.util.List;
   import java.util.ResourceBundle;
   import java.util.Scanner;
   import java.util.logging.Level;
   import java.util.logging.Logger;
   import javafx.application.Application;
   import javafx.event.ActionEvent;
   import javafx.event.Event;
   import javafx.event.EventHandler;
   import javafx.fxml.FXML;
   import javafx.fxml.Initializable;
   import javafx.geometry.Insets;
   import javafx.geometry.Pos;
   import javafx.stage.FileChooser;
   import javafx.stage.FileChooser.ExtensionFilter;
   import javafx.stage.Stage;
   import javafx.scene.Scene;
   import javafx.scene.control.Button;
   import javafx.scene.control.ListView;
   import javafx.scene.control.SelectionMode;
   import javafx.scene.input.Clipboard;
   import javafx.scene.input.ClipboardContent;
   import javafx.scene.input.DataFormat;
   import javafx.scene.input.DragEvent;
   import javafx.scene.input.Dragboard;
   import javafx.scene.input.MouseEvent;
   import javafx.scene.input.TransferMode;
   import javafx.scene.layout.BorderPane;
   import javafx.scene.layout.HBox;
   import javafx.scene.layout.StackPane;
   import javafx.scene.layout.VBox;
   import javafx.scene.text.Text;
   public class SelectFile extends Application  implements Initializable  {
private static final String srcFile1 = null;
Date today = new Date();
public String modifiedDate = new SimpleDateFormat("MM-dd-yyyy").format(today);
   public static String version = "  Version 1.0A-Beta";
   Button btnExit = new Button("Exit");
   Button logIn   = new Button("Login");
   File srcFile, destFile;
   DBConnection dc;
@FXML
ListView listView;
   @FXML
public void handleDragDropped(DragEvent event){
   Dragboard db = event.getDragboard();
   File file = db.getFiles().get(0);
   System.out.println("L#101, file="+file.getName());
   //Dragboard db = event.getDragboard();
       boolean success = false;
       if (db.hasString()) {
           System.out.println("Dropped: " + db.getString());
           success = true;
       }
       event.setDropCompleted(success);
       event.consume();
}
   @FXML
   private void handleDragOver(DragEvent event) {
//if (event.getDragboard().hasFiles()) {
System.out.println("L#115, in DragOver");
event.acceptTransferModes(TransferMode.ANY);
//}
final Text source = new Text(950, 1100, "DRAG ME");
source.setOnDragDetected(new EventHandler <MouseEvent>() {
       public void handle(MouseEvent event) {
           /* drag was detected, start drag-and-drop gesture*/
           System.out.println("L#122, onDragDetected");
           /* allow any transfer mode */
           Dragboard db = source.startDragAndDrop(TransferMode.ANY);
           /* put a string on dragboard */
           ClipboardContent content = new ClipboardContent();
           content.putString(source.getText());
           db.setContent(content);
           event.consume();
       }
   });
   }
   @FXML
   private void handleDragEntered(Event event) {
   Dragboard db = ((DragEvent) event).getDragboard();
   System.out.println("L#137, handleDragEntered\tdb="+db.getString()+"
           \tClipboard="+db.getSystemClipboard().getString());
   if (db.hasString()) {
           ((DragEvent) event).acceptTransferModes(TransferMode.COPY_OR_MOVE);
       }
       //event.consume();
       //Dragboard db = event.getDragboard();
       boolean success = false;
       if (db.hasString()) {
           System.out.println("Dropped: " + db.getString());
           success = true;
       } else {
        System.out.println("L#148, db="+db.getString());
       }
       ((DragEvent) event).setDropCompleted(success);
       event.consume();
   }
   @FXML
   private void handleDrop(DragEvent event) throws FileNotFoundException {
List<File> files = event.getDragboard().getFiles();
System.out.println("L#156, handleDrop\t"+files.toString());
//File file = new File(new FileInputStream(files.get(0)));
//Object fileView;
listView.getItems();//(files);//setFile(files);
   }
   @FXML
   private void handleDragDetected(DragEvent event) {
System.out.println("L#163, handleDragDetected");
Dragboard db = listView.startDragAndDrop(TransferMode.ANY);
ClipboardContent cb = new ClipboardContent();
//*****************************************
cb.putFiles(listView.getItems());//.getText());
   }
   @FXML
   private void handleMouseDragReleased(DragEvent event) {
System.out.println("L#172, handleMouseDragReleased");
   }
       @FXML
       private void handleMouseDragOver(DragEvent event) {
    System.out.println("L#176, MouseDragOver");
       }
       @FXML
       private void handleDragDone(DragEvent event) {
    System.out.println("L#180, DragDone");
       }
       @FXML
       private void handleDragEntered() {
    System.out.println("L#184, DragEntered");
       }
   //@FXML
   public void bntExit1() {
System.exit(0);
    }
   @FXML
   public void ChooseFile() throws IOException {
   System.out.println("L#192, in ChooseFile");
   //FileChooser fileChooser = new FileChooser();
       Button button = new Button("Select File");
       String
        nPath = "";//button.setOnAction((e) -> {
        FileChooser fc = new FileChooser();
    fc.setTitle("test for selected files");
        fc.getExtensionFilters().add(new ExtensionFilter("Type of
        files","*.docx","*.doc","*.txt"));
    File selectedFile = fc.showOpenDialog(null);
    System.out.println("L#201, file="+selectedFile);
    String fileName = selectedFile.getAbsolutePath();
//System.out.println("L#64, fileName="+fileName+"\tselectedFile="+selectedFile);
if (selectedFile != null) {
    int j = fileName.lastIndexOf('\\');
    nPath = fileName.substring(0,j+1);
    String file = selectedFile.getName();
    srcFile = new File(nPath);
    srcFile = new File(file); //s.readString(nPath);//readString(nPath);                  
    System.out.println("L#210, Directory="+nPath+srcFile);//"\tsrcfile="+srcFile);me());
    destFile = new File(nPath+"a"+srcFile);
    String srcFile1 = srcFile.getName();
    //s.close();
    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putString(fileName);
    System.out.println("L#217,
               clipboard="+clipboard.getFiles()+"\tcontent="+content.getString()+"
               \t"+content.put(DataFormat.PLAIN_TEXT, " "));
} else {
System.out.println("L#219, selectedFile="+selectedFile);
}
srcFile = new File(nPath+srcFile);
System.out.println("L#222, srcFile="+srcFile.toPath()+"\tdest="+destFile+"
           \tsrcFile1="+selectedFile);
if (srcFile != null && destFile != null) {
File dest_a = new File("C:\\Users\\Jerry.000\\Temp\\"+selectedFile.getName());
Files.copy(srcFile.toPath(), dest_a.toPath(), StandardCopyOption.COPY_ATTRIBUTES);
System.out.println("L#226, srcFile="+srcFile.toPath()+"\tdest="+dest_a.toPath());
//copyFile(srcFile,dest);
}
        //});
   }
   private void copyFile(File src, File dest) {
       InputStream inputStream = null;
       OutputStream outputStream = null;
       int len;
       byte buffer[] = new byte[512];
       try {
           inputStream = new FileInputStream(src);
           outputStream = new FileOutputStream(dest);
           while ((len = inputStream.read(buffer)) != -1) {
               outputStream.write(buffer, 0, len);
           }
       } catch (FileNotFoundException ex) {
           Logger.getLogger(SelectFile.class.getName())
                   .log(Level.SEVERE, null, ex);
       } catch (IOException ex) {
           Logger.getLogger(SelectFile.class.getName())
                   .log(Level.SEVERE, null, ex);
       } finally {
           try {
               if(inputStream != null){
                   inputStream.close();
               }
               if(outputStream != null){
                   outputStream.close();
               }
           } catch (IOException ex) {
               Logger.getLogger(SelectFile.class.getName())
                       .log(Level.SEVERE, null, ex);
           }
       }
   }
   public static void main(String[] args) {
launch(args);
   }
   @Override
   public void initialize(URL arg0, ResourceBundle arg1) {
//System.out.println("L#122, in initialize");
   }
   @Override
   public void start(Stage arg0) throws Exception {
// TODO Auto-generated method stub
    }
    }
6 months ago