Wednesday 28 August 2013

How to make a table cell be edited on KeyPressed in JavaFx2.2



public void startEdit() {
super.startEdit();
createTextField();
setText(null);
setGraphic(textField);

/**
* put focus on the textfield so user can directly typed on it
*/
Runnable r = new Runnable() {
@Override
public void run() {
getGraphic().requestFocus();
}
};
Platform.runLater(r);

}

How to insert dynamic Image Path in Mysql using Javafxml

Hiii Here i have taken two text Field and one ImageView .now i have taken dynamic image from Filechooser and then store it into MySql database.




 s1=t1.getText();
             s2=t2.getText();
             s3=l1.getText();
            // img1.getProperties();
           
        {
            try{

            Class.forName("com.mysql.jdbc.Driver").newInstance();

        }catch(ClassNotFoundException cnfe){

            System.err.println("Error: "+cnfe.getMessage());

        }catch(InstantiationException ie){

            System.err.println("Error: "+ie.getMessage());

        }catch(IllegalAccessException iae){

            System.err.println("Error: "+iae.getMessage());

        }
           try
           {
            Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/farhan","root","root" );
              String query="insert into Product_Detail(Prod_No,Prod_Name,Picture)values(?,?,?)";
         
           System.out.println("hiiiiiii man54");
           PreparedStatement ps=conn.prepareStatement(query);
           System.out.println("hiiiiiii man32");
           ps.setString(1,s1);
        ps.setString(2, s2);
        ps.setString(3,s3);
       int i = ps.executeUpdate();
         
           }
           catch(Exception e)
           {
             
                 e.printStackTrace();
           }
         
           System.out.println("database");
           if(i==1)
           {
               System.out.println("database count 1");
             
               System.out.println("Successfully inserted");
           }
           else
           {
               System.out.println("Incorrect Syntac");
           }

Monday 26 August 2013

How to Load dynamic image in JavaFx

Use Filechooser for the dialog box and specify the extension which u want to take and load it on to your requirement.      

  FileChooser fileChooser = new FileChooser();
         
          System.out.print("in browse button handle action event,mouse clicked");
            FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG");
           FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG");
           fileChooser.getExtensionFilters().addAll(extFilterJPG, extFilterPNG);
             File file = fileChooser.showOpenDialog(null);
         
           
                BufferedImage bufferedImage = ImageIO.read(file);
                WritableImage image = SwingFXUtils.toFXImage(bufferedImage,null);
                 img1.setImage(image);

javafx.stage.Popup as JOptionPane

It is easy to create JoptionPane equivalent in Javafx2.0.
Here is a custom Component:

import javafx.stage.*; 
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.control.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;

public class ModalDialog {
    Button Button b1,b2;
    public ModalDialog(final Stage stg) {

            final Stage dialog = new Stage();
            dialog.setTitle("Confirm Before Exit");
            dialog.setResizable(false);
          // dialog.initOwner(Demoslide.getPrimaryStage());
            dialog.initModality(Modality.APPLICATION_MODAL);

            FlowPane buttons = new FlowPane(10,10);
            buttons.setAlignment(Pos.CENTER);
            Button yes = new Button("Yes");
           Button no = new Button("No");
            buttons.getChildren().addAll(yes, no);
            VBox box = new VBox();
            box.setAlignment(Pos.CENTER);
            box.setSpacing(10);
            box.getChildren().addAll(new Label("Successfully login "), buttons);
             Scene s = new Scene(box);
            dialog.setScene(s);
            dialog.show();
         }
      
      
    }

How to popup message below Taskbar right-corner



// when message is received
JDialog d = new JDialog();
d.setSize(200,200);
d.setLocation(theXLocation, theYLocation);
d.add(new JLabel(message);
d.setVisible(true);
where the x and y location match the right corner

to get these locations, see the toolkit class, that will allow you to get the dimension of the screen