Posts

Showing posts from February, 2016

JavaFX 8 Tutorial 55 - Centering Image Using StackPane

Image
package tutorial.pkg55.centering.image; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.shape.Ellipse; import javafx.stage.Stage; /**  *  * @author Ram  */ public class Tutorial55CenteringImage extends Application {         @Override     public void start(Stage primaryStage) {         primaryStage.setTitle("JavaFX 8 Tutorial 55 - Centering Image Using StackPane");                 StackPane root = new StackPane();         Scene scene = new Scene(root, 400, 200);                 Image img = new Image("file:Javafx.jpg", 100, 150, true, true);         ImageView iv = new ImageView(img);                 Ellipse ellipse = new Ellipse();         ellipse.setFill(Color.MEDIUMSLATEBLUE);                 ellipse.radiusXProperty().bind(scene.widthProperty().divide(2));  

JavaFX 8 Tutorial 54 - Centering Text In Scene

Image
package tutorial.pkg54.centering.text; import javafx.application.Application; import javafx.geometry.VPos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.stage.Stage; /**  *  * @author Ram  */ public class Tutorial54CenteringText extends Application {         @Override     public void start(Stage primaryStage) {         primaryStage.setTitle("JavaFX 8 Tutorial 54 - Centering Text In Scene");         Group root = new Group();         Scene scene = new Scene(root, 400, 200);                 Text text = new Text("JavaFX 8 Tutorial 54 - Centering Text In Scene");         text.setTextOrigin(VPos.TOP);         text.setFont(Font.font(null, FontWeight.BOLD, 15));                 text.layoutXProperty().bind(scene.widthProperty().subtract(text.prefWidth(-1)).divide(2));         text.layoutYProperty().bind(scene.heightProperty(

JavaFX 8 Tutorial 53 - JavaFX Application Deployment

Image
Steps for JavaFX Application Deployment: 1.    Install Inno Setup (for exe installer) Link: http://www.jrsoftware.org/download.php/is.exe 2.    Install WIX Setup (for msi installer) Link: http://wixtoolset.org/releases/v3.10/stable 3.    Set Environment variables for Inno setup Path: C:\Program Files (x86)\Inno Setup 5 4.    Set Environment variables for WIX setup Path: C:\Program Files (x86)\WiX Toolset v3.10\bin 5.    Add Icon to application     primaryStage.setTitle("User Info App ");     primaryStage.getIcons().add(new Image("file:user-icon.png")); 6.    Open build.xml and Add Following code in it at last <target name="-post-jfx-deploy">     <fx:deploy verbose="true" nativeBundles="exe" outdir="${basedir}/${dist.dir}" outfile="${application.title}">         <fx:application name="${application.title}" mainClass="${javafx.main.class}"/>         <fx:resource

JavaFX 8 Tutorial 52 - Import Excel to Database

Image
The code written in this tutorial is : private Button importXLToDB; importXLToDB = new Button("Import XL TO DB");         importXLToDB.setFont(Font.font("Sanserif", 15));         importXLToDB.setOnAction(e -> {             try {                 String query = "Insert into UserDatabase(ID, FirstName, LastName, Email) values (?,?,?,?)";                 pst = conn.prepareStatement(query);                                 FileInputStream fileIn = new FileInputStream(new File("UserInfo.xlsx"));                                 XSSFWorkbook wb = new XSSFWorkbook(fileIn);                 XSSFSheet sheet = wb.getSheetAt(0);                 Row row;                 for(int i=1; i<=sheet.getLastRowNum(); i++){                     row = sheet.getRow(i);                     pst.setInt(1, (int) row.getCell(0).getNumericCellValue());                     pst.setString(2, row.getCell(1).getStringCellValue());                     pst.set

JavaFX 8 Tutorial 51 - Export Database to Excel

Image
The code written in this tutorial is : private Button exportToXL; exportToXL = new Button("Export To Excel");         exportToXL.setFont(Font.font("Sanserif", 15));         exportToXL.setOnAction( e->{             try {                 String query = "Select * from UserDatabase";                 pst = conn.prepareStatement(query);                 rs = pst.executeQuery();                                 //Apache POI Jar Link-                 //http://a.mbbsindia.com/poi/release/bin/poi-bin-3.13-20150929.zip                 XSSFWorkbook wb = new XSSFWorkbook();//for earlier version use HSSF                 XSSFSheet sheet = wb.createSheet("User Details");                 XSSFRow header = sheet.createRow(0);                 header.createCell(0).setCellValue("ID");                 header.createCell(1).setCellValue("First Name");                 header.createCell(2).setCellValue("Last Name");      

JavaFX 8 Tutorial 50 - Retrive Image from Database

Image
The code written in this tutorial is:  table.setOnMouseClicked(e ->{             try {                 User user = (User)table.getSelectionModel().getSelectedItem();                                 String query = "select * from UserDatabase where ID = ?";                 pst = conn.prepareStatement(query);                 pst.setString(1, user.getID());                 rs = pst.executeQuery();                                 while(rs.next()){                     InputStream is = rs.getBinaryStream("Image");                     OutputStream os = new FileOutputStream( new File("photo.jpg"));                     byte[] content = new byte[1024];                     int size = 0;                     while((size = is.read(content)) != -1){                         os.write(content, 0, size);                     }                     os.close();                     is.close();                                     image = new Image("f

JavaFX 8 Tutorial 49 - Image and Database

Image
The code written in this tutorial is : private FileInputStream fis;         Button button = new Button("Save");         button.setFont(Font.font("SanSerif", 15));         button.setOnAction(e ->{             try{                 String query = "INSERT INTO UserDatabase ( Image) VALUES(?)";                 pst = conn.prepareStatement(query);                 fis = new FileInputStream(file);// file is selected using filechooser which is in last tutorial                 pst.setBinaryStream(11, (InputStream)fis, (int)file.length());                 pst.execute();                                 pst.close();                 clearFields();             }catch(Exception e1){                 label.setText("SQL Error");                 System.err.println(e1);             } });

JavaFX 8 Tutorial 48 - ImageView

Image
The code written in this tutorial is : private ImageView imageView; private Image image; browse.setOnAction(e ->{             //Single File Selection             file = fileChooser.showOpenDialog(primaryStage);             if(file != null){                 textArea.setText(file.getAbsolutePath());                 image = new Image(file.toURI().toString(), 100, 150, true, true);//path, PrefWidth, PrefHeight, PreserveRatio, Smooth                               imageView = new ImageView(image);                 imageView.setFitWidth(100);                 imageView.setFitHeight(150);                 imageView.setPreserveRatio(true);                               layout.setCenter(imageView);                 BorderPane.setAlignment(imageView, Pos.TOP_LEFT);                           }                       //Multiple File Selection             /*List<File> fileList = fileChooser.showOpenMultipleDialog(primaryStage);             if(

JavaFX 8 Tutorial 47 - Get Selected Filepath Into TextArea

Image
The code written in this tutorial is: private TextArea textArea; browse.setOnAction(e ->{ //Single File Selection             file = fileChooser.showOpenDialog(primaryStage);             if(file != null){                 textArea.setText(file.getAbsolutePath());                           } //Multiple File Selection             /*List<File> fileList = fileChooser.showOpenMultipleDialog(primaryStage);             if(fileList != null){                 fileList.stream().forEach(selectedFiles ->{                     textArea.setText(fileList.toString());                 });             }*/ } fields.getChildren().addAll(searchField, label1, id, fn, ln, em, mobile, un, pw, date, male, female, checkBox1, checkBox2, checkBox3, browse, textArea, button);