Monday, September 22, 2014

JavaFX 8 ColorPicker to fill Background

JavaFX 8 example to implement ColorPicker and set background color on Action EventHandler.


package javafxcolorpicker;

import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.ColorPicker;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Paint;
import javafx.stage.Stage;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaFXColorPicker extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        StackPane root = new StackPane();
        
        ColorPicker colorPicker = new ColorPicker();
        
        colorPicker.setOnAction(new EventHandler(){

            @Override
            public void handle(Event event) {
                Paint fill = colorPicker.getValue();
                BackgroundFill backgroundFill = 
                    new BackgroundFill(fill, 
                            CornerRadii.EMPTY, 
                            Insets.EMPTY);
                Background background = new Background(backgroundFill);
                root.setBackground(background);
            }
        });

        root.getChildren().add(colorPicker);
        
        Scene scene = new Scene(root, 300, 250);
        
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
    
}

Friday, September 19, 2014

JavaFX Rich Client Programming on the NetBeans Platform

JavaFX Rich Client Programming on the NetBeans Platform

JavaFX is a state-of-the-art graphics toolkit that is now built into Java and can be easily integrated with the NetBeans Platform. With JavaFX, you can create advanced user interfaces, manipulate media, generate graphical effects and animations, and much more. The NetBeans Platform provides a framework for building robust, modular applications with long life expectancies. Together, JavaFX and the NetBeans Platform provide the basis for creating visually appealing, industrial-strength applications.

Focusing on JavaFX as the front end for rich client applications, this guide’s examples cover JavaFX 8 with the NetBeans Platform, NetBeans IDE, and Java 8. Gail and Paul Anderson fully explain JavaFX and its relationship with the NetBeans Platform architecture, and systematically show Java developers how to use them together effectively. Each concept and technique is supported by clearly written code examples, proven through extensive classroom teaching.

Coverage includes
  • Background basics with Java, JavaFX, and UI events
  • Building loosely coupled applications
  • NetBeans Platform Modules and Lookup
  • NetBeans Platform Nodes, Explorer Views, and Actions
  • Building CRUD-based applications
  • Integrating JavaFX with a Swing-based framework
  • Using JavaFX Charts with the NetBeans Platform
  • Using the NetBeans Platform File System and Data System
  • Keeping the UI responsive

Tuesday, September 16, 2014

Example of getSimpleName()

The getSimpleName() method returns the simple name of the underlying class as given in the source code. Returns an empty string if the underlying class is anonymous.

This example modify from last post to list superclasses with simple name.


package javagetsuperclass;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaGetSuperClass {

    public static void main(String[] args) {

        JavaGetSuperClass me = new JavaGetSuperClass();
        me.doSomething();
        
        SubJavaGetSuperClass subMe = new SubJavaGetSuperClass();
        subMe.doSomething();
        
        Class testClass = javafx.scene.chart.AreaChart.class;
        printClassInfo(testClass);
    }

    public void doSomething(){
        printClassInfo(this.getClass());
    }
    
    static private void printClassInfo(Class someClass){

        StringBuilder info = new StringBuilder();
        
        info.append("someClass: ").append(someClass).append("\n");
        
        do{
            someClass = someClass.getSuperclass();
            if(someClass!=null){
                info.append("superClass: ").append(someClass.getSimpleName()).append("\n");
            }else{
                info.append("superClass: ").append("null").append("\n");
            }
            
        }while(someClass != null);
        
        info.append("=====").append("\n");
        System.out.println(info);
    }

}

class SubJavaGetSuperClass extends JavaGetSuperClass{
        
}