Posts

Showing posts from 2016

Some Terminology you should know before start working on javafx

All components to be displayed inside a JavaFX application must be located inside a scene. The names for "stage" and "scene" are inspired by a theater. A stage can display multiple scenes, just like in a theater play. Stage Represents windows, top level container Many setter methods: setTitle (), setWidth () You can create multiple stages and use one or another. Scene Each stage has a scene Scene holds controls (buttons, labels, etc ) Pane You can put controls in Scenes directly, but we usually Panesfor better layout Examples: StackPane , BorderPane , HBox , VBox

Filter In Javafx

package com.ibadmin.control.tablefilter; import java.util.Optional; import java.util.function.BiPredicate; import java.util.stream.Collectors; import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import javafx.collections.transformation.SortedList; import javafx.scene.control.CheckBox; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; /**  * Applies a filtering control to a provided {@link TableView} instance. The filter will be applied immediately on construction, and can be  * made visible by right-clicking the desired column to filter on. <br>  * <br>  * <b>Features</b><br>  * -Convenient filter control holds a checklist of distinct items to include/exclude, much like an Excel filter.<br>  * -New/removed records wi

Filter In Javafx

package com.ibadmin.control.tablefilter; import java.util.Optional; import java.util.function.BiPredicate; import java.util.stream.Collectors; import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import javafx.collections.transformation.SortedList; import javafx.scene.control.CheckBox; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; /**  * Applies a filtering control to a provided {@link TableView} instance. The filter will be applied immediately on construction, and can be  * made visible by right-clicking the desired column to filter on. <br>  * <br>  * <b>Features</b><br>  * -Convenient filter control holds a checklist of distinct items to include/exclude, much like an Excel filter.<br>  * -New/removed records wi

Mapping controller class with its FXML file

Suppose your controller class is : class SettingController implemets Initializable{ @FXML Vbox settingsFXML; @Override   public void initialize(URL location, ResourceBundle resources) { } } And Here is your fxml : Setting.fxml : <VBox id="settingsFXML" fx:id="settingsFXML" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ibadmin.settings.SettingsController "> </VBox> Note that : In fxml we write one attribute " fx:controller " to map contrller with fxml file. pass class path to this attribute. also Note that we assign id to this fxml as :"setitngsFXML" :we use this id as object in controller to use fxml components(not necessary ).

About Java-FX Controller

public class SettingsController implements  Initializable{  @Override   public void initialize(URL location, ResourceBundle resources) {     } } This is the way to write controller class in javafx But  remember some point about controller class in javafx - It is not necessary to extends Initialization interface to create controller class - But if you implements initialization interface then it is necessary to override initialize method as shown second way : public class SettingsController {   public void initialize() {     } } this is also a correct way to create controller class in jaavfx Note - method name should be initialize it is starting point of your controller class ex : public class SettingController { init(){ This is not a valid controller class } }

When to set UI Component private / public in Javafx :

- If you write  UI component in private controller class then it is mandetory to write annotation for Example - @FXML                        Private TextFiled textFiled; If you declare UI component as public then there is no need to write annotation for Example : public TextFiled textFiled; Better practice is to Write annotation and keep all UI component private in Controller class. 

Java: Best way to iterate through an Collection

Some times there is possibility to get concurrent modification exception while retrieving element from collection. Example : On any collection object say Array List , you are adding and removing data sententiously for refesh ui  purpose , then in this case if you are iterating collection object by simple for loop or foreach loop then there is possibility to get  ConcurrentModificationException So use iterator to fetch element from collection. For more details please read internal working of  iterator.

JAVAFX - UI-UNRESPONSIVE FOR LONG RUNNING PROCESS

Scene is not a thread safe and can only be accessed and modified from the UI thread also known as the JavaFX Application thread. Long-running tasks on the JavaFX Application thread makes an application UI unresponsive. The Java platform provides a complete set of concurrency libraries available through the java.util.concurrent package. . The javafx.concurrent package consists of the Worker interface and two basic classes, Task and Service, both of which implement the Worker interface . . Solution :  Create task and write logic in it .   Task<Void> task = new Task<Void>() {             public Void call() { // write your logic here               return null;             }           };           task.setOnSucceeded(event -> {           });

How to update war content without extracting /unpacking

private static void updateIBPublicationBuilderWar(String installationPath) throws IOException {     String warFilePath = "orignal war file"; // ex test.war     String tempWarFilePath = "temp war file name" ; // temp.war     File warFile = new File(warFilePath);     File tempWarFile = new File(tempWarFilePath);     ZipFile zipFile = new ZipFile(warFile);     FileOutputStream fos = new FileOutputStream(tempWarFile);     ZipOutputStream zipOutputStream = new ZipOutputStream(fos);     for (Enumeration enumeration = zipFile.entries(); enumeration.hasMoreElements();) {       ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();       if (!zipEntry.getName().equalsIgnoreCase("WEB-INF/classes/ibserver.properties")) {         zipOutputStream.putNextEntry(zipEntry);         InputStream inputStream = zipFile.getInputStream(zipEntry);         byte[] buf = new byte[1024];         int len;         while ((len = inputStream.read(buf)) > 0) {