Control insets in JavaFX 2.2

With JavaFX 8 the control has a property holding the padding. How can I retrieve the insets with JavaFX 2.2? I need them to calculate the content area. If I do not take them into account, they are ignored, which is not what I intend to do.

Only things that inherit from Region have a getInsets() and a getPadding() method. Except for that, the usage of the Insets class is limited.
It works in FX8 because they changed the inheritance tree of the controls.
i.e:
in JavaFX 2.2, controls did not inherit from Region:
java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.control.Control
javafx.scene.control.Labeled
javafx.scene.control.ButtonBase
javafx.scene.control.CheckBox
In JavaFX 8, they do inherit from Region:
java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.control.Control
javafx.scene.control.Labeled
javafx.scene.control.ButtonBase
javafx.scene.control.CheckBox

Similar Messages

  • Setting styleable properties & pseudo-class state to controls in JavaFX 2.2

    Hi All,
    Greetings!
    Can anyone please let me know how to create or set styleable and pseudo-class state properties for custom controls developed with JavaFX 2.2.
    I found a very nice wiki regarding this. (https://wikis.oracle.com/display/OpenJDK/CSS+API+to+support+custom+UI+Controls)
    But this seems to be with JavaFX 8 version. As i cannot find PseudoClass in the current version of JavaFX 2.2.
    Thanks & Regards,
    Sai Pradeep Dandem.

    There is no public API in 2.2 for adding adding styleable properties and pseudo-class state to controls in JavaFX 2.2.
    The implementation between 2.2 and 8.0 changed significantly in terms of API, class names, etc. The model is roughly the same, but if you implement something in 2.2 using the private implementation APIs, it will not work, and may not even compile, in 8.0.
    // A pseudo-class in 2.2
        private BooleanProperty foo = new BooleanPropertyBase() {
                    @Override
                    protected void invalidated() {
                        impl_pseudoClassStateChanged("foo");
                    @Override
                    public Object getBean() {
                        return MyControl.this;
                    @Override
                    public String getName() {
                        return "foo";
        public boolean isFoo() {
            return foo.get();
        public void setFoo(boolean newFoo) {
            foo.set(newFoo);
        private static final long FOO_PSEUDOCLASS_STATE = StyleManager.getInstance().getPseudoclassMask("foo");
        @Override
        public long impl_getPseudoClassState() {
            long mask = super.impl_getPseudoClassState();
            if(isFoo()) mask |= FOO_PSEUDOCLASS_STATE;
            return mask;
    // A styleable property in 2.2. import classes from com.sun.javafx.css
            public DoubleProperty bar = new StyleableDoubleProperty(0.0) {
                        @Override
                        public StyleableProperty getStyleableProperty() {
                            return BAR;
                        @Override
                        public Object getBean() {
                            return MyControl.this;
                        @Override
                        public String getName() {
                            return "bar";
    // API used by css in 2.2
            private static final StyleableProperty<MyControl,Number> BAR =
                new StyleableProperty<MyControl,Number>("-my-bar",
                    SizeConverter.getInstance(), 0.0) {
                    @Override
                    public boolean isSettable(MyControl ctl) {
                        return bar.isBound() == false;
                    @Override
                    public WritableValue<Number> getWritableValue(MyControl ctl) {
                        return ctl.bar;
             private static final List<StyleableProperty> STYLEABLES;
             static {
                 final List<StyleableProperty> styleables = new ArrayList<StyleableProperty>();
                 Collections.addAll(styleables,
                     BAR
                 STYLEABLES = Collections.unmodifiableList(styleables);
         public static List<StyleableProperty> impl_CSS_STYLEABLES() {
             return STYLEABLES;
        public List<StyleableProperty> impl_getStyleableProperties() {
            return impl_CSS_STYLEABLES();
        }

  • How can I select multiple cells in tableview with javafx only by mouse?

    I have an application with a tableview in javafx and i want to select multiple cells only by mouse (something like the selection which exists in excel).I tried with setOnMouseDragged but i cant'n do something because the selection returns only the cell from where the selection started.Can someone help me?

    For mouse drag events to propagate to nodes other than the node in which the drag initiated, you need to activate a "full press-drag-release gesture" by calling startFullDrag(...) on the initial node. (See the Javadocs for MouseEvent and MouseDragEvent for details.) Then you can register for MouseDragEvents on the table cells in order to receive and process those events.
    Here's a simple example: the UI is not supposed to be ideal but it will give you the idea.
    import java.util.Arrays;
    import javafx.application.Application;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.SelectionMode;
    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.input.MouseDragEvent;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.VBox;
    import javafx.scene.text.Font;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    public class DragSelectionTable extends Application {
        private TableView<Person> table = new TableView<Person>();
        private final ObservableList<Person> data =
            FXCollections.observableArrayList(
                new Person("Jacob", "Smith", "[email protected]"),
                new Person("Isabella", "Johnson", "[email protected]"),
                new Person("Ethan", "Williams", "[email protected]"),
                new Person("Emma", "Jones", "[email protected]"),
                new Person("Michael", "Brown", "[email protected]")
        public static void main(String[] args) {
            launch(args);
        @Override
        public void start(Stage stage) {
            Scene scene = new Scene(new Group());
            stage.setTitle("Table View Sample");
            stage.setWidth(450);
            stage.setHeight(500);
            final Label label = new Label("Address Book");
            label.setFont(new Font("Arial", 20));
            table.setEditable(true);
            TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
            firstNameCol.setMinWidth(100);
            firstNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("firstName"));
            TableColumn<Person, String> lastNameCol = new TableColumn<>("Last Name");
            lastNameCol.setMinWidth(100);
            lastNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("lastName"));
            TableColumn<Person, String> emailCol = new TableColumn<>("Email");
            emailCol.setMinWidth(200);
            emailCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("email"));
            final Callback<TableColumn<Person, String>, TableCell<Person, String>> cellFactory = new DragSelectionCellFactory();
            firstNameCol.setCellFactory(cellFactory);
            lastNameCol.setCellFactory(cellFactory);
            emailCol.setCellFactory(cellFactory);
            table.setItems(data);
            table.getColumns().addAll(Arrays.asList(firstNameCol, lastNameCol, emailCol));
            table.getSelectionModel().setCellSelectionEnabled(true);
            table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
            final VBox vbox = new VBox();
            vbox.setSpacing(5);
            vbox.setPadding(new Insets(10, 0, 0, 10));
            vbox.getChildren().addAll(label, table);
            ((Group) scene.getRoot()).getChildren().addAll(vbox);
            stage.setScene(scene);
            stage.show();
        public static class DragSelectionCell extends TableCell<Person, String> {
            public DragSelectionCell() {
                setOnDragDetected(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        startFullDrag();
                        getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
                setOnMouseDragEntered(new EventHandler<MouseDragEvent>() {
                    @Override
                    public void handle(MouseDragEvent event) {
                        getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) {
                    setText(null);
                } else {
                    setText(item);
        public static class DragSelectionCellFactory implements Callback<TableColumn<Person, String>, TableCell<Person, String>> {
            @Override
            public TableCell<Person, String> call(final TableColumn<Person, String> col) {         
                return new DragSelectionCell();
        public static class Person {
            private final SimpleStringProperty firstName;
            private final SimpleStringProperty lastName;
            private final SimpleStringProperty email;
            private Person(String fName, String lName, String email) {
                this.firstName = new SimpleStringProperty(fName);
                this.lastName = new SimpleStringProperty(lName);
                this.email = new SimpleStringProperty(email);
            public String getFirstName() {
                return firstName.get();
            public void setFirstName(String fName) {
                firstName.set(fName);
            public String getLastName() {
                return lastName.get();
            public void setLastName(String fName) {
                lastName.set(fName);
            public String getEmail() {
                return email.get();
            public void setEmail(String fName) {
                email.set(fName);

  • JavaFX: TableView's cellvalue is not enough to display in columns, I want..

    javaFX: TableView's cellvalue is not enough to display in columns, it will be clipped end of '...', how to show a tip on such cell?
    I need a tip because sometimes i can't drag the colunm's head. So i can't see the whole content of the cell.

    Create a custom cell and overwrite the updateItem method. Add a tooltip:
                       Tooltip tip = new Tooltip(getString());
                       Tooltip.install(this, tip);
                  Here is an example ( a tooltip for the email column) :
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    import javafx.application.Application;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableColumn.CellEditEvent;
    import javafx.scene.control.TableView;
    import javafx.scene.control.TextField;
    import javafx.scene.control.Tooltip;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.layout.HBox;
    import javafx.scene.layout.VBox;
    import javafx.scene.text.Font;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    public class TableViewToolTipSample extends Application {
        private TableView<Person> table = new TableView<Person>();
        private final ObservableList<Person> data =
                FXCollections.observableArrayList(
                new Person("Jacob", "Smith", "[email protected]"),
                new Person("Isabella", "Johnson", "[email protected]"),
                new Person("Ethan", "Williams", "[email protected]"),
                new Person("Emma", "Jones", "[email protected]"),
                new Person("Michael", "Brown", "[email protected]"));
        final HBox hb = new HBox();
        public static void main(String[] args) {
            launch(args);
        @Override
        public void start(Stage stage) {
            Scene scene = new Scene(new Group());
            stage.setTitle("Table View Sample");
            stage.setWidth(450);
            stage.setHeight(550);
            final Label label = new Label("Address Book");
            label.setFont(new Font("Arial", 20));
            table.setEditable(true);
            Callback<TableColumn, TableCell> cellFactory =
                    new Callback<TableColumn, TableCell>() {
                        public TableCell call(TableColumn p) {
                            return new CustomCell();
            TableColumn firstNameCol = new TableColumn("First Name");
            firstNameCol.setMinWidth(100);
            firstNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("firstName"));
           // firstNameCol.setCellFactory(cellFactory);
            TableColumn lastNameCol = new TableColumn("Last Name");
            lastNameCol.setMinWidth(100);
            lastNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("lastName"));
          //  lastNameCol.setCellFactory(cellFactory);
            TableColumn emailCol = new TableColumn("Email");
            emailCol.setMinWidth(200);
            emailCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("email"));
            emailCol.setCellFactory(cellFactory);
            table.setItems(data);
            table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
            final VBox vbox = new VBox();
            vbox.setSpacing(5);
            vbox.setPadding(new Insets(10, 0, 0, 10));
            vbox.getChildren().addAll(label, table, hb);
            ((Group) scene.getRoot()).getChildren().addAll(vbox);
            stage.setScene(scene);
            stage.show();
        public static class Person {
            private final SimpleStringProperty firstName;
            private final SimpleStringProperty lastName;
            private final SimpleStringProperty email;
            private Person(String fName, String lName, String email) {
                this.firstName = new SimpleStringProperty(fName);
                this.lastName = new SimpleStringProperty(lName);
                this.email = new SimpleStringProperty(email);
            public String getFirstName() {
                return firstName.get();
            public void setFirstName(String fName) {
                firstName.set(fName);
            public String getLastName() {
                return lastName.get();
            public void setLastName(String fName) {
                lastName.set(fName);
            public String getEmail() {
                return email.get();
            public void setEmail(String fName) {
                email.set(fName);
        class CustomCell extends TableCell<Person, String> {
            private TextField textField;
            public CustomCell() {
            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) {
                    setText(null);
                    setGraphic(null);
                } else {
                    if (isEditing()) {
                        if (textField != null) {
                            textField.setText(getString());
                        setText(null);
                        setGraphic(textField);
                    } else {
                        setText(getString());
                        setGraphic(null);
                        Tooltip tip = new Tooltip(getString());
                        Tooltip.install(this, tip);
            private String getString() {
                return getItem() == null ? "" : getItem().toString();
    }If you need a tooltip for a column header:
            TableColumn emailCol = new TableColumn();
            Label emailHeaderLabel = new Label("Email header label");
            emailCol.setGraphic(emailHeaderLabel);    
            Tooltip tip = new Tooltip("Email header label");
            Tooltip.install(emailHeaderLabel, tip);Edited: added a tooltip for a column header

  • JavaFX table view headers bug?

    Hi,
    I created simple application with table view and I have problem with the way that table view headers are displaying.
    When table view is not focused headers are improper width but when table get focus then headers width is changing and everything is working as expected.
    Before table view get focus:
    http://imageshack.us/a/img841/6853/j9u9.png
    After table view get focus:
    http://imageshack.us/a/img43/922/169f.png
    Best regards,
    Lukas

    You should run this app without problems becouse it is embeded SQLLite databse. Look into SqlLiteDB class. You can even delete database.db file becouse sqllite driver will automatically create database.
    I check your example and is perfect becouse is showing my issue You should only make small change that you skipped: ( table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); )
    import javafx.application.Application;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.TextField;
    import javafx.scene.control.cell.MapValueFactory;
    import javafx.scene.layout.AnchorPane;
    import javafx.scene.layout.HBox;
    import javafx.stage.Stage;
    import java.util.*;
    public class Main extends Application {
        @Override
        public void start(Stage primaryStage) {
            final AnchorPane root = new AnchorPane();
            root.setPadding(new Insets(10));
            final HBox controls = new HBox(5);
            final Button getDataButton = new Button("load data");
            final TextField textField = new TextField();
            final TableView<Map> table = new TableView<>();
            table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
            getDataButton.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent event) {
                    DataSource dataSource = new DataSource();
                    table.getColumns().clear();
                    table.getColumns().addAll(dataSource.getTableColumns());
                    table.setItems(dataSource.getQueryResult());
            controls.getChildren().addAll(getDataButton, textField);
            AnchorPane.setTopAnchor(controls, 10.0);
            AnchorPane.setLeftAnchor(controls, 10.0);
            AnchorPane.setRightAnchor(controls, 10.0);
            AnchorPane.setTopAnchor(table, 45.0);
            AnchorPane.setRightAnchor(table, 10.0);
            AnchorPane.setLeftAnchor(table, 10.0);
            AnchorPane.setBottomAnchor(table, 10.0);
            root.getChildren().addAll(controls, table);
            primaryStage.setScene(new Scene(root, 1000, 1000));
            primaryStage.show();
        public static class DataSource {
            public List<TableColumn<Map, Object>> getTableColumns() {
                TableColumn<Map, Object> idColumn = new TableColumn<>("ID");
                idColumn.setCellValueFactory(new MapValueFactory<Object>("ID"));
                TableColumn<Map, Object> nameColumn = new TableColumn<>("NAME");
                nameColumn.setCellValueFactory(new MapValueFactory<Object>("NAME"));
                return Arrays.asList(idColumn, nameColumn);
            public ObservableList<Map> getQueryResult() {
                List<Map> result = new ArrayList<>();
                for (int i = 0; i < 200; i++) {
                    Map<String, Object> row = new HashMap<>();
                    row.put("ID", i);
                    row.put("NAME", "Name " + i);
                    result.add(row);
                return FXCollections.observableArrayList(result);
        public static void main(String[] args) {
            launch(args);

  • JAVAFX 1.3 combobox shows bad graphics

    Hello when i 've coded these stuffs :
    It shows amazing graphics. May be it's not supporting colors:
    package javafx13;
    * @author WEBNEP
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.control.*;
    import javafx.scene.layout.VBox;
    import javafx.geometry.Insets;
    var list = ["apples", "bananas", "oranges", "pears", "cabbage"];
    var sc = ScrollView {
      width: 250
      height: 250
      managed: false
      node: VBox {
        padding: Insets {top: 10, left: 10, bottom: 10, right: 10}
        spacing: 10
        content: [
          PasswordBox {promptText: "enter password"}
          Separator {}
          ChoiceBox {
            items: list
          ListView {
            vertical: false
            items: list
    Stage {
        title: "Application title"
        scene: Scene {
            width: 400
            height: 400
            content: [
                sc
    }When i clicked on combobox
    The output show like this :
    [Error on Output|http://javacoder.co.nr/error.jpg]
    Please help is it showing only on my computer?
    Edited by: narayan_gop_mah on Apr 23, 2010 5:38 AM
    Edited by: narayan_gop_mah on Apr 23, 2010 5:52 AM

    Thanks PhiLho
    Well ,after i configured my NVIDIA graphics card's CPanel
    I select "Let the 3d application decide" which had solved this problem.
    Actually i had selected "Use my preference emphasizing : Quality" before so i got bad graphic i think.
    Any way it's solved ..
    and one more confusion If you don't mind telling what's the use of Point3D in javafx 1.3?

  • Netbeans 7.2 - JavaFX Tutorial - problems with imports

    I am indeed a newbie. I installed Netbeans 7.2 and created a JavaFX Application project while following a tutorial. I inserted code (as instructed) for a GridPane with alignment and inset adjustments. After inserting the GridPane code from the tutorial, my build got errors (undefined for pos.Center and Insets
            GridPane grid = new GridPane();
            grid.setAlignment(Pos.CENTER);
            grid.setHgap(10);
            grid.setVgap(10);
            grid.setPadding(new Insets(25, 25, 25, 25));
            Scene scene = new Scene(grid, 300, 275);
            primaryStage.setScene(scene);
    {code}
    It took quite a long time for me to discover what includes to code in order to solve these build errors.  I eventually ended up with :
    {code}
    package login;
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    import javafx.scene.layout.GridPane;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.text.Text;
    import javafx.scene.text.Font;
    import javafx.geometry.Insets;
    import javafx.application.Application;
    import javafx.geometry.Pos;
    import javafx.scene.Scene;
    import javafx.scene.control.PasswordField;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.HBox;
    import javafx.scene.paint.Color;
    import javafx.scene.text.Font;
    import javafx.scene.text.FontWeight;
    import javafx.scene.text.Text;
    {code}
    The wizard produced these includes at the start:
    {code}
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    {code}
    My questions:
    Is there a way to specify the includes for javaFX  with
    {code}
    javafx.*;
    {code}
    Is there a simple way in Netbeans 7.2 to find out what include to use to solve the undefined build errors?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I am not a Netbeans user but I think this is what you are looking for.
    http://wiki.netbeans.org/Java_EditorUsersGuide#How_to_add_import_statements_for_one_or_more_classes

  • How to add 3 legends for a single series barchart?? JAVAFX

    Here is my code to generate 10 bars of different colors. I want to add legend respectively but it only one shows yellow legend
    1. I think it shows only 1 color because there is only 1 series. Is it possible to add more than 1 legend for a single series?
    or
    2. or can i display another image for legend in barchart??
    output :http://i.stack.imgur.com/fSNu7.png
    file i want to display in barchart:http://i.stack.imgur.com/cchch.png
    public class DynamicallyColoredBarChart extends Application {
        @Override
        public void start(Stage stage) {
            final CategoryAxis xAxis = new CategoryAxis();
            xAxis.setLabel("Bars");
            final NumberAxis yAxis = new NumberAxis();
            yAxis.setLabel("Value");
            final BarChart<String, Number> bc = new BarChart<>(xAxis, yAxis);
            bc.setLegendVisible(false);
            XYChart.Series series1 = new XYChart.Series();
            for (int i = 0; i < 10; i++) {
                // change color of bar if value of i is >5 than red if i>8 than blue
                final XYChart.Data<String, Number> data = new XYChart.Data("Value " + i, i);
                data.nodeProperty().addListener(new ChangeListener<Node>() {
                    @Override
                    public void changed(ObservableValue<? extends Node> ov, Node oldNode, Node newNode) {
                        if (newNode != null) {
                            if (data.getYValue().intValue() > 8) {
                                newNode.setStyle("-fx-bar-fill: navy;");
                            } else if (data.getYValue().intValue() > 5) {
                                newNode.setStyle("-fx-bar-fill: red;");
                series1.getData().add(data);
            bc.getData().add(series1);
            stage.setScene(new Scene(bc));
            stage.show();
        public static void main(String[] args) {
            launch(args);
    ...Edited by: 993431 on Mar 12, 2013 1:42 PM

    Either:
    1. Use a chart which displays multiple series, then you can allow the built-in legend to show OR
    2. Use a single dynamically colored series have you have done and create your own custom legend.
    import javafx.application.Application;
    import javafx.scene.*;
    import javafx.scene.chart.*;
    import javafx.stage.Stage;
    public class ThreeSeriesBarChart extends Application {
      @Override public void start(Stage stage) {
        final CategoryAxis xAxis = new CategoryAxis();
        xAxis.setLabel("Bars");
        final NumberAxis yAxis = new NumberAxis();
        yAxis.setLabel("Value");
        final BarChart<String, Number> bc = new BarChart<>(xAxis, yAxis);
        XYChart.Series lowSeries = new XYChart.Series();
        lowSeries.setName("Not Achieved");
        XYChart.Series medSeries = new XYChart.Series();
        medSeries.setName("Achieved");
        XYChart.Series hiSeries  = new XYChart.Series();
        hiSeries.setName("Exceeded");
        bc.setBarGap(0);
        bc.setCategoryGap(0);
        for (int i = 0; i < 10; i++) {
          final XYChart.Data<String, Number> data = new XYChart.Data("Value " + i, i);
          if (data.getYValue().intValue() > 8) {
            hiSeries.getData().add(data);
          } else if (data.getYValue().intValue() > 5) {
            medSeries.getData().add(data);
          } else {
            lowSeries.getData().add(data);
        bc.getData().setAll(lowSeries, medSeries, hiSeries);
        bc.getStylesheets().add(getClass().getResource("colored-chart.css").toExternalForm());
        stage.setScene(new Scene(bc));
        stage.show();
      public static void main(String[] args) {
        launch(args);
    import javafx.application.Application;
    import javafx.beans.value.*;
    import javafx.geometry.Pos;
    import javafx.scene.*;
    import javafx.scene.chart.*;
    import javafx.scene.control.Label;
    import javafx.scene.layout.*;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.*;
    import javafx.stage.Stage;
    public class DynamicallyColoredBarChart extends Application {
      @Override public void start(Stage stage) {
        final CategoryAxis xAxis = new CategoryAxis();
        xAxis.setLabel("Bars");
        final NumberAxis yAxis = new NumberAxis();
        yAxis.setLabel("Value");
        final BarChart<String, Number> bc = new BarChart<>(xAxis, yAxis);
        bc.setLegendVisible(false);
        XYChart.Series series1 = new XYChart.Series();
        for (int i = 0; i < 10; i++) {
          // change color of bar if value of i is >5 than red if i>8 than blue
          final XYChart.Data<String, Number> data = new XYChart.Data("Value " + i, i);
          data.nodeProperty().addListener(new ChangeListener<Node>() {
            @Override
            public void changed(ObservableValue<? extends Node> ov, Node oldNode, Node newNode) {
              if (newNode != null) {
                if (data.getYValue().intValue() > 8) {
                  newNode.setStyle("-fx-bar-fill: -fx-exceeded;");
                } else if (data.getYValue().intValue() > 5) {
                  newNode.setStyle("-fx-bar-fill: -fx-achieved;");
                } else {
                  newNode.setStyle("-fx-bar-fill: -fx-not-achieved;");
          series1.getData().add(data);
        bc.getData().add(series1);
        LevelLegend legend = new LevelLegend();
        legend.setAlignment(Pos.CENTER);
        VBox chartWithLegend = new VBox();
        chartWithLegend.getChildren().setAll(bc, legend);
        chartWithLegend.getStylesheets().add(getClass().getResource("colored-chart.css").toExternalForm());
        stage.setScene(new Scene(chartWithLegend));
        stage.show();
      class LevelLegend extends GridPane {
        LevelLegend() {
          setHgap(10);
          setVgap(10);
          addRow(0, createSymbol("-fx-exceeded"),     new Label("Exceeded"));
          addRow(1, createSymbol("-fx-achieved"),     new Label("Achieved"));
          addRow(2, createSymbol("-fx-not-achieved"), new Label("Not Achieved"));
          getStyleClass().add("level-legend");
        private Node createSymbol(String fillStyle) {
          Shape symbol = new Ellipse(10, 5, 10, 5);
          symbol.setStyle("-fx-fill: " + fillStyle);
          symbol.setStroke(Color.BLACK);
          symbol.setStrokeWidth(2);
          return symbol;
      public static void main(String[] args) { launch(args); }
    /** colored-chart.css: place in same directory as other bar chart application files and setup your build system to copy it to the output directory */
    .root {
      -fx-not-achieved: red;
      -fx-achieved:     green;
      -fx-exceeded:     blue;
    .default-color0.chart-bar { -fx-bar-fill: -fx-not-achieved; }
    .default-color1.chart-bar { -fx-bar-fill: -fx-achieved; }
    .default-color2.chart-bar { -fx-bar-fill: -fx-exceeded; }
    .level-legend {
      -fx-padding: 10;
      -fx-border-width: 2;
      -fx-background-color: rgba(211, 211, 211, 0.5);
      -fx-border-color: derive(rgba(211, 211, 211, 0.7), 10%);
    }

  • How can I implement a comfirmation window when closing javafx application?

    hi,guys
    I'd like to add a confirmation window when user is closing my javafx application,if user click yes, I will close the application,if no ,I wouldn't close it ,how can I implement this function?
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
                   @Override
                   public void handle(WindowEvent arg0) {
                        try
                             //todo
                        catch(Exception ex)
                             System.out.print(ex.getMessage()+"\r\n");
            });

    Hi. Here is an example:
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Pos;
    import javafx.stage.*;
    import javafx.scene.*;
    import javafx.scene.paint.Color;
    import javafx.scene.layout.*;
    import javafx.scene.control.*;
    public class ModalDialog {
        public ModalDialog(final Stage stg) {
         final Stage stage = new Stage();          
            //Initialize the Stage with type of modal
            stage.initModality(Modality.APPLICATION_MODAL);
            //Set the owner of the Stage
            stage.initOwner(stg);
            Group group =  new Group();
            HBox hb = new HBox();
             hb.setSpacing(20);
            hb.setAlignment(Pos.CENTER);
            Label label = new Label("You are about to close \n your application: ");
            Button no  = new Button("No");
            no.setOnAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                       stage.hide();
            Button yes  = new Button("Yes");
            yes.setOnAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                       stg.close();
             hb.getChildren().addAll(yes, no);
             VBox vb =  new VBox();
             vb.setSpacing(20);
             vb.setAlignment(Pos.CENTER);
             vb.getChildren().addAll(label,hb);
            stage.setTitle("Closing ...");
            stage.setScene(new Scene( vb, 260, 110, Color.LIGHTCYAN));       
            stage.show();
    }Test:
       import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    import javafx.stage.*;
    * @author Shakir
    public class ModalTest extends Application {
         * @param args the command line arguments
        public static void main(String[] args) {
            Application.launch(ModalTest.class, args);
        @Override
        public void start(final Stage primaryStage) {
            primaryStage.setTitle("Hello World");
            Group root = new Group();
            Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN);
           primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
                   @Override
                   public void handle(WindowEvent arg0) {
                                    arg0.consume();
                        try
                         ModalDialog md = new ModalDialog(primaryStage);
                        catch(Exception ex)
                             System.out.print(ex.getMessage()+"\r\n");
            primaryStage.setScene(scene);
            primaryStage.show();
    }

  • Drawing and some layout help for a simple control: thin lines and application start

    I am trying to create a new, simple control. The control should act as a grouping marker much like that found in the Mathematica notebook interface. It is designed to sit to the right of a node and draw a simple bracket. The look of the bracket changes depending on whether the node is logically marked open or closed.
    After looking at some blogs and searching, I tried setting the snapToPixels to true in the container holding the marker control as well as the strokewidth but I am still finding that the bracket line is too thick. I am trying to draw a thin line. Also, I am unable to get the layout to work when the test application is first opened. One of the outer brackets is cut-off. I hardcoded some numbers into the skin just to get something to work.
    Is there a better way to implement this control?
    How can I get the fine line drawn as well as the layout correct at application start?
    package org.notebook;
    import javafx.beans.property.BooleanProperty;
    import javafx.beans.property.IntegerProperty;
    import javafx.beans.property.SimpleBooleanProperty;
    import javafx.beans.property.SimpleIntegerProperty;
    import javafx.scene.control.Control;
    * Provide a simple and thin bracket that changes
    * it appearance based on whether its closed or open.
    public class GroupingMarker extends Control {
      private final static String DEFAULT_STYLE_CLASS = "grouping-marker";
      private BooleanProperty open;
      private IntegerProperty depth;
      public BooleanProperty openProperty() { return open; }
      public IntegerProperty depthProperty() { return depth; }
      public GroupingMarker(boolean open) {
      this();
      setOpen(open);
      public GroupingMarker() {
      open = new SimpleBooleanProperty(true);
      depth = new SimpleIntegerProperty(0);
      getStyleClass().add(DEFAULT_STYLE_CLASS);
      // TODO: Change to use CSS directly
      setSkin(new GroupingMarkerSkin(this));
      public boolean isOpen() {
      return open.get();
      public void setOpen(boolean flag) {
      open.set(flag);
      public int getDepth() {
      return depth.get();
      public void setDepth(int depth) {
      this.depth.set(depth);
    package org.notebook;
    import javafx.scene.Group;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.FillRule;
    import javafx.scene.shape.LineTo;
    import javafx.scene.shape.MoveTo;
    import javafx.scene.shape.Path;
    import com.sun.javafx.scene.control.skin.SkinBase;
    * The skin draws some simple lines on the right hand side of
    * the control. The lines reflect whether the control is considered
    * open or closed. Since there is no content, there is no
    * content handling code needed.
    public class GroupingMarkerSkin extends SkinBase<GroupingMarker, GroupingMarkerBehavior> {
      GroupingMarker control;
      Color lineColor;
      double shelfLength;
      double thickness;
      private Group lines;
      public GroupingMarkerSkin(GroupingMarker control) {
      super(control, new GroupingMarkerBehavior(control));
      this.control = control;
      lineColor = Color.BLUE;
      shelfLength = 5.0;
      thickness = 1.0;
      init();
      * Attached listeners to the properties in the control.
      protected void init() {
      registerChangeListener(control.openProperty(), "OPEN");
      registerChangeListener(control.depthProperty(), "DEPTH");
      lines = new Group();
      repaint();
      @Override
      protected void handleControlPropertyChanged(String arg0) {
      super.handleControlPropertyChanged(arg0);
        @Override public final GroupingMarker getSkinnable() {
            return control;
        @Override public final void dispose() {
        super.dispose();
            control = null;
        @Override
        protected double computePrefHeight(double arg0) {
        System.out.println("ph: " + arg0);
        return super.computePrefHeight(arg0);
        @Override
        protected double computePrefWidth(double arg0) {
        System.out.println("pw: " + arg0);
        return super.computePrefWidth(40.0);
         * Call this if a property changes that affects the visible
         * control.
        public void repaint() {
        requestLayout();
        @Override
        protected void layoutChildren() {
        if(control.getScene() != null) {
        drawLines();
        getChildren().setAll(lines);
        super.layoutChildren();
        protected void drawLines() {
        lines.getChildren().clear();
        System.out.println("bounds local: " + control.getBoundsInLocal());
        System.out.println("bounds parent: " + control.getBoundsInParent());
        System.out.println("bounds layout: " + control.getLayoutBounds());
        System.out.println("pref wxh: " + control.getPrefWidth() + "x" + control.getPrefHeight());
        double width = Math.max(0, 20.0 - 2 * 2.0);
        double height = control.getPrefHeight() - 4.0;
        height = Math.max(0, control.getBoundsInLocal().getHeight()-4.0);
        System.out.println("w: " + width + ", h: " + height);
        double margin = 4.0;
        final Path VERTICAL = new Path();
        VERTICAL.setFillRule(FillRule.EVEN_ODD);
        VERTICAL.getElements().add(new MoveTo(margin, margin)); // start
        VERTICAL.getElements().add(new LineTo(margin + shelfLength, margin)); // top horz line
        VERTICAL.getElements().add(new LineTo(margin + shelfLength, height - margin)); // vert line
        if(control.isOpen()) {
        VERTICAL.getElements().add(new LineTo(margin, height - margin)); // bottom horz line
        } else {
        VERTICAL.getElements().add(new LineTo(margin, height-margin-4.0));
        //VERTICAL.getElements().add(new ClosePath());
        VERTICAL.setStrokeWidth(thickness);
        VERTICAL.setStroke(lineColor);
        lines.getChildren().addAll(VERTICAL);
        lines.setCache(true);
    package org.notebook;
    import com.sun.javafx.scene.control.behavior.BehaviorBase;
    public class GroupingMarkerBehavior extends BehaviorBase<GroupingMarker> {
      public GroupingMarkerBehavior(final GroupingMarker control) {
      super(control);
    package org.notebook;
    import javafx.application.Application;
    import javafx.scene.Node;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextArea;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    public class TestGroupingMarker extends Application {
      public static void main(String args[]) {
      launch(TestGroupingMarker.class, args);
      @Override
      public void start(Stage stage) throws Exception {
      VBox vbox = new VBox();
      BorderPane p = new BorderPane();
      VBox first = new VBox();
      first.getChildren().add(makeEntry("In[1]=", "my label", 200.0, true));
      first.getChildren().add(makeEntry("Out[1]=", "the output!", 200.0, true));
      p.setCenter(first);
      p.setRight(new GroupingMarker(true));
      vbox.getChildren().add(p);
      vbox.getChildren().add(makeEntry("In[2]=", "my label 2", 100.0, false));
      Scene scene = new Scene(vbox,500,700);
      scene.getStylesheets().add(TestGroupingMarker.class.getResource("main.css").toExternalForm());
      stage.setScene(scene);
      stage.setTitle("GroupingMarker test");
      stage.show();
      protected Node makeEntry(String io, String text, double height, boolean open) {
      BorderPane pane2 = new BorderPane();
      pane2.setSnapToPixel(true);
      Label label2 = new Label(io);
      label2.getStyleClass().add("io-label");
      pane2.setLeft(label2);
      TextArea area2 = new TextArea(text);
      area2.getStyleClass().add("io-content");
      area2.setPrefHeight(height);
      pane2.setCenter(area2);
      GroupingMarker marker2 = new GroupingMarker();
      marker2.setOpen(open);
      pane2.setRight(marker2);
      return pane2;

    The test interfaces are already defined for you - the 3rd party session bean remote/local interfaces.
    It is pretty trivial to create implementations of those interfaces to return the test data from your XML files.
    There are a number of ways to handle the switching, if you have used the service locator pattern, then I would personally slot the logic in to the service locator, to either look up the 3rd party bean or return a POJO test implementation of the interface according to configuration.
    Without the service locator, you are forced to do a little more work, you will have to implement your own test session beans to the same interfaces as the 3rd party session beans.
    You can then either deploy them instead of the 3rd party beans or you can deploy both the test and the 3rd party beans under different JNDI names,and use ejb-ref tags and allow you to switch between test and real versions by changing the ejb-link value.
    Hope this helps.
    Bob B.

  • Problem with custom control and focus

    I've a problem with the focus in a custom control that contains a TextField and some custom nodes.
    If i create a form with some of these custom controls i'm not able to navigate through these fields by using the TAB key.
    I've implemented a KeyEvent listener on the custom control and was able to grab the focus and forward it to the embedded TextField by calling requestFocus() on the TextField but the problem is that the TextField won't get rid of the focus anymore. Means if i press TAB the first embedded TextField will get the focus, after pressing TAB again the embedded TextField in the next custom control will get the focus AND the former focused TextField still got the focus!?
    So i'm not able to remove the focus from an embeded TextField.
    Any idea how to do this ?

    Here you go, it contains the control, skin and behavior of the custom control, the css file and a test file that shows the problem...
    control:
    import javafx.scene.control.Control;
    import javafx.scene.control.TextField;
    public class TestInput extends Control {
        private static final String DEFAULT_STYLE_CLASS = "test-input";
        private TextField           textField;
        private int                 id;
        public TestInput(final int ID) {
            super();
            id = ID;
            textField = new TextField();
            init();
        private void init() {
            getStyleClass().add(DEFAULT_STYLE_CLASS);
        public TextField getTextField() {
            return textField;
        @Override protected String getUserAgentStylesheet() {
                return getClass().getResource("testinput.css").toExternalForm();
        @Override public String toString() {
            return "TestInput" + id + ": " + super.toString();
    }skin:
    import com.sun.javafx.scene.control.skin.SkinBase;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.event.EventHandler;
    import javafx.scene.control.TextField;
    import javafx.scene.input.KeyCode;
    import javafx.scene.input.KeyEvent;
    public class TestInputSkin extends SkinBase<TestInput, TestInputBehavior> {
        private TestInput control;
        private TextField textField;
        private boolean   initialized;
        public TestInputSkin(final TestInput CONTROL) {
            super(CONTROL, new TestInputBehavior(CONTROL));
            control     = CONTROL;
            textField   = control.getTextField();
            initialized = false;
            init();
        private void init() {
            initialized = true;
            paint();
        public final void paint() {
            if (!initialized) {
                init();
            getChildren().clear();
            getChildren().addAll(textField);
        @Override public final TestInput getSkinnable() {
            return control;
        @Override public final void dispose() {
            control = null;
    }behavior:
    import com.sun.javafx.scene.control.behavior.BehaviorBase;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.event.EventHandler;
    import javafx.scene.input.KeyCode;
    import javafx.scene.input.KeyEvent;
    public class TestInputBehavior extends BehaviorBase<TestInput> {
        private TestInput control;
        public TestInputBehavior(final TestInput CONTROL) {
            super(CONTROL);
            control = CONTROL;
            control.getTextField().addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
                @Override public void handle(final KeyEvent EVENT) {
                    if (KeyEvent.KEY_PRESSED.equals(EVENT.getEventType())) {
                        keyPressed(EVENT);
            control.focusedProperty().addListener(new ChangeListener<Boolean>() {
                @Override public void changed(ObservableValue<? extends Boolean> ov, Boolean wasFocused, Boolean isFocused) {
                    if (isFocused) { isFocused(); } else { lostFocus(); }
        public void isFocused() {
            System.out.println(control.toString() + " got focus");
            control.getTextField().requestFocus();
        public void lostFocus() {
            System.out.println(control.toString() + " lost focus");
        public void keyPressed(KeyEvent EVENT) {
            if (KeyCode.TAB.equals(EVENT.getCode())) {
                control.getScene().getFocusOwner().requestFocus();
    }the css file:
    .test-input {
        -fx-skin: "TestInputSkin";
    }and finally the test app:
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.GridPane;
    import javafx.stage.Stage;
    public class Test extends Application {
        TestInput input1;
        TestInput input2;
        TestInput input3;
        TextField input4;
        TextField input5;
        TextField input6;
        Scene     scene;
        @Override public void start(final Stage STAGE) {
            setupStage(STAGE, setupScene());
        private Scene setupScene() {
            input1 = new TestInput(1);
            input2 = new TestInput(2);
            input3 = new TestInput(3);
            input4 = new TextField();
            input5 = new TextField();
            input6 = new TextField();
            GridPane pane = new GridPane();
            pane.add(input1, 1, 1);
            pane.add(input2, 1, 2);
            pane.add(input3, 1, 3);
            pane.add(input4, 2, 1);
            pane.add(input5, 2, 2);
            pane.add(input6, 2, 3);
            scene = new Scene(pane);
            return scene;
        private void setupStage(final Stage STAGE, final Scene SCENE) {
            STAGE.setTitle("Test");
            STAGE.setScene(SCENE);
            STAGE.show();
        public static void main(String[] args) {
            launch(args);
    The test app shows three custom controls on the left column and three standard textfields on the right column. If you press TAB you will see what i mean...

  • Remaining questions while evaluating JavaFX for a new project

    Dear forum members:
    currently I am evaluating the possibilities of next-generation GUI technologies, such as JavaFX, Silverlight and Flash/Flex, for a new project. To get a basic understanding of JavaFX's concepts, I worked through the available online text and video tutorials, and all the treated topics seem quite obvious/comprehensible to me +as long as one is only confronted to relatively static GUI component hierarchies+. But, as a newbie, some questions concerning more dynamically defined GUIs (i.e. dynamic JFX scripting*) still remain.
    Application scenario (exemplary):
    Say I want to create a "Online Shopping Application" that supports "+ShopOwners+" in *dynamically* defining the "+Shop Model+" structure, e.g. accepted visitor (client) categories, product categories their products, pricing information, payment methods, etc.
    Then, based on the dynamically defined model, the shop owner should be able to design and layout the necessary forms, such as order forms, survey/feedback forms, etc. This should be done in "design mode", and there should also exist a possibility for him/her to preview the specification results in a "preview mode".
    Finally, the shop owner must be able to save the model and forms on the server side in a way that can requested and run be the shopping app end users (the shop clients) via (another (?)) JavaFX frontend.
    _The still remaining questions for this scenario are:_
    +1. Is JavaFX appropriate for creating such kind of applications, especially when it comes to dynamic JFX scripting (and compilation) on the client side??? (By now I'm not quite sure if this is really necessary for my plans!)+
    +2. Concerning the ShopOwner's GUI with its design and preview mode (and knowing that the latter mode will be the GUI version presented to the shop clients in another JFX module):+
    +Is it possible to *dynamically *build up a +Scene Graph+ in a way that lets me handle and *compile* the corresponding +JFX Script+ on the client side for previewing it? Or is a client-server roundtrip absolutely necessary?
    How could one persist this JFX Script on the server side? I.e., which intermediary format would be the most appropriate? => XML, JSON, JFX Script?
    3. Concerning the "Shop Model", would I optimally create JFX classes or even Java Beans to bind to?
    4. And finally: What would be your recommended way (software architecture) to fulfill this task in JavaFX?
    Do there already exist some JFX components (dynamic forms/survey authoring modules, etc.) that persue a similar task and that I didn't find yet?
    As the clarification of the above-mentioned issues are very important for me, I hope that you more experienced users can help me, pointing me to a practicable approach.
    Thank you very much for any help and constructive tips in advance.
    Best regards
    Martin Meyers

    Q1: Do I optimally need 2 different custom components for each treated concept, or do I have just 1 component with 2 internal modes (design & preview/usage)??
    E.g., (a) FormSpec widget composed of LabelSpec, TextBoxSpec, ChooseBoxSpec,... widgets each having their preview pendants
    Form, Label, TextBox, ChooseBox, etc.
    versus
    +(b) only Form widget composed of Label, TextBox, ChooseBox widgets, but all having a "design/preview execution mode".+
    Closer to (b), I think, though each widget doesn't need to be modified to have design and preview modes. Instead, each widget can be wrapped within a Group to provide the design/preview functions without modifying the widget itself.
    The technique is as follows. Given a sequence of widgets (Nodes, really), for each widget, wrap it in a Group that contains that widget but with an overlay Rectangle in front of it. The Rectangle can be semi-transparent, or fully transparent if you prefer. (In the example below I've made it a semitransparent color to make its location obvious as well as to provide a highlight that signals design mode.) The overlay Rectangle is set up so that its dimensions will exactly track the dimensions (bounds) of the widget behind it. I've set blocksMouse to true so that when it's present, the overlay traps events and prevents interaction with the widget. There is a boolean variable previewMode, controlled by a CheckBox, that controls the visibility of these overlay rectangles. I've also added a bit of code to track mouse events on the overlay rectangles so that you can move the widgets around when you're in design mode.
    Note that the visible variable differs from transparent, i.e. opacity == 0.0. If a node is visible but is transparent, it is still eligible to receive events; whereas if visible is false, it does not receive events.
    Here's some code that illustrates this technique. I'll answer your other questions in a subsequent post.
    import javafx.stage.Stage;
    import javafx.scene.*;
    import javafx.scene.control.*;
    import javafx.scene.input.*;
    import javafx.scene.layout.*;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    var previewMode = true;
    var lastX:Number;
    var lastY:Number;
    function wrap(n:Node):Node {
        Group {
            content: [
                n,
                Rectangle {
                    opacity: 0.2
                    fill: Color.web("#ffff00")
                    x: bind n.boundsInParent.minX
                    y: bind n.boundsInParent.minY
                    width: bind n.boundsInParent.width
                    height: bind n.boundsInParent.height
                    visible: bind previewMode
                    blocksMouse: true
                    onMousePressed: function(me:MouseEvent) {
                        lastX = me.x;
                        lastY = me.y;
                    onMouseDragged: function(me:MouseEvent) {
                        n.layoutX += me.x - lastX;
                        n.layoutY += me.y - lastY;
                        lastX = me.x;
                        lastY = me.y;
    var controlList:Node[] = [
        Button {
            layoutX: 140
            layoutY: 20
            text: "Button1"
            action: function() { println("Button1 clicked!"); }
        Slider {
            layoutX: 30
            layoutY: 60
            min: 0
            max: 100
            override var value on replace {
                println("Slider value is now {value}");
        Label {
            layoutX: 50
            layoutY: 100
            text: "Non-interactive label"
        CheckBox {
            layoutX: 40
            layoutY: 140
            text: "CheckBox"
            override var selected on replace {
                println("CheckBox is now {if (selected) "checked" else "unchecked"}");
    Stage {
        title: "Design vs Preview Mode"
        width: 400
        height: 250
        scene: Scene {
            content: [
                CheckBox {
                    layoutX: 10
                    layoutY: 10
                    text: "Preview Mode"
                    selected: bind previewMode with inverse
                Panel {
                    content: for (n in controlList) {
                        wrap(n)
    }

  • Java run time error while executing JavaFX code

    Hi
    I copied the code from [http://java.sun.com/javafx/1/tutorials/ui/overview/UIControls.fx|http://java.sun.com/javafx/1/tutorials/ui/overview/UIControls.fx] while
    reading in [http://java.sun.com/javafx/1/tutorials/ui/overview/#controls|http://java.sun.com/javafx/1/tutorials/ui/overview/#controls] tutorial and paste it to my
    netbeans editor but i got following error.
    init:
    deps-jar:
    compile:
    jar:
    standard-run:
    # An unexpected error has been detected by Java Runtime Environment:
    #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d94513f, pid=5152, tid=5996
    # Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)
    # Problematic frame:
    # V  [jvm.dll+0xd513f]
    # An error report file with more information is saved as hs_err_pid5152.log
    # If you would like to submit a bug report, please visit:
    #   http://java.sun.com/webapps/bugreport/crash.jsp
    BUILD FAILED (total time: 18 seconds)can anyone tell whether its netbeans fault or javaFX. I am using netbeans 6.5.1 on windows vista. I have added following plugin in netbeans for javaFX
    *JavaFX Kit
    *JavaFX SDK for Windows
    is anyone also getting this error for this code and have solution for this.

    You are correct the crash is causing due to ToggleButton and ProgessBar. the code is correct because i tried it on eclipse 3.4 and it worked fine.This is definitely netbeans error. because its giving error even if u try to execute javafx code with just one ToggleButton or ProgressBar. I tried the following simple code in netbeans 6.5
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.control.ToggleButton;
    import javafx.scene.control.ProgressBar;
    var toggle=ToggleButton {
                    translateX:50
                    translateY:50
                    text: "First"
                    width:100
                    height:20
    var progress= ProgressBar {
            progress: bind ProgressBar.computeProgress( 100, 30 )
    Stage {
        title : "Toggle Button Test"
        scene: Scene {
            width: 200
            height: 200
            content: [ toggle
    } When i just added toggle button to contents then button showed up in window but on clicking it window disappear and compiler gave crash error on the other hand when i added just progess bar it just throws the error.The same code is running fine on eclipse
    Is there any workaround in netbeans for this if its a bug and if not what should i do to correct it.

  • Displaying Open Office word doc in browser using JavaFX

    My requirement is to display open office doc in my application for modification

    Hi. The following works for Microsoft Word docs and Notepad.
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.stage.Stage;
    * @author gusaros
    public class OpenOffice extends Application {
         * @param args the command line arguments
        public static void main(String[] args) {
            Application.launch(args);
        @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("Hello World");
            Group root = new Group();
            Scene scene = new Scene(root, 300, 250);
            Button btn = new Button();
            btn.setLayoutX(100);
            btn.setLayoutY(80);
            btn.setText("Hello World");
            btn.setOnAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                    String[] cmdArray = {"cmd", "/c", "start", "c:\\fdres.doc"};
                    try {
                        java.lang.Runtime.getRuntime().exec(cmdArray);
                    } catch (Exception s) {
            root.getChildren().add(btn);
            primaryStage.setScene(scene);
            primaryStage.show();
    }

  • Variable binding with javafx.ext.swing.SwingSlider

    My first javafx program consists of a slider and a text box, the text box displays the current value of the slider. The problem is the text box does not display anything when the program just starts up, but only gets populated once I change the value of the slider. I am not sure what I am doing wrong. Here is the code:
    import javafx.scene.control.*;
    import javafx.scene.*;
    import javafx.stage.*;
    import  javafx.ext.swing.*;
    import javafx.scene.layout.*;
    var BPMSlider = SwingSlider {
        minimum: 10
        maximum: 250
        value: 60
    }; //BPMSlider
    var BPM = bind "{BPMSlider.value}";
    var BPMDisplay = TextBox {
         text: bind BPM
        columns: 3
    }; //BPMDisplay;
    Stage  {
        title: "Slider";
        width: 1000
        height: 500
        visible: true
       // Set the scene
       scene:
           Scene {
           content:       
               HBox{ spacing: 10 content:[ BPMSlider, BPMDisplay ] }
           } // Scene
    }Thanks!

    Hi,
    I don't know how to solve it with binding values, but I managed to solve it with temporary int value which contains Slider.value.
    If any one can help us with solving this binding value we are waiting for answer.
    Here is the code:
    package slider;
    import javafx.ext.swing.*;
    import javafx.scene.*;
    import javafx.scene.control.*;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.*;
    import javafx.stage.*;
    var tempSliderVal:Integer = 60; // temp BPMSlider value
    var BPMSlider = SwingSlider {
        minimum: 10;
        maximum: 250;
        value: bind tempSliderVal with inverse;
        onMouseDragged: function (e:MouseEvent) {
            BPMDisplay.text = tempSliderVal.toString();
        onMouseClicked: function (e:MouseEvent) {
            BPMDisplay.text = tempSliderVal.toString();
    }; //BPMSlider
    var BPMDisplay = TextBox {
         text: tempSliderVal.toString();
        columns: 3;
    }; //BPMDisplay;
    Stage  {
        title: "Slider";
        width: 1000;
        height: 500;
        visible: true;
        // Set the scene
        scene: Scene {
            content: HBox{
                spacing: 10;
                content:[ BPMSlider, BPMDisplay ];
        } // Scene
    }

Maybe you are looking for

  • How to reverse Mvtyp 321??

    Dear All Kindly help me out in the following scenario: I had confirmed production through CO11N in a wrong batch number subsequently QM also entered its UD and posted goods movement from quality to Unrestricted how could i nullify this QM transaction

  • What replication methods are available in Oracle 10g Standard Edition?

    Hi All, Our customer wants to have two identical servers at two different sites (Virginia and Utah). Server in Virginia will be the primary and the other one will be Standby. Application will run on the primary database and they would like to be able

  • SeLinux Checkpolicy install error ( /usr/bin/ld: cannot find -lfl)

    I am trying to setup selinux per the arch wiki, but I ran into an error when trying to install the checkpolicy package from the AUR. I keep getting the following error: ==> Starting build()...   cc -march=x86-64 -mtune=generic -O2 -pipe -fstack-prote

  • IWay vs XI or Both?

    We have choosen to evaluate XI to integrate data directly from DB2 AS400 to SAP R3. To pull the data from DB2 AS400 into SAP we are talking to iWay on adapter side - but here is the big confusion iWay introduced when we had call with them.      <b>-

  • Probleme de lecture avec itunes

    Bonsoi r alors cela fait deux jours que je n arrive plus a lire les musiques sur itunes ni meme les videos. J ai tester si cela été un probleme de son venant des hauts parleur mais non, youtube fonctionne parfaitement et puis lorsque je met lecture s