When I'm trying to add new obj to scene.content, I get an exception:
init:
deps-jar:
compile:
jar:
standard-run:
sceneContent -> SwingTextFieldTextSwingButtonText
textObjSeq -> Text
Text with title'sgsdgf' has been added.
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at com.sun.embeddedswing.EmbeddedEventQueue.moveToVisibleAndOnScreen(EmbeddedEventQueue.java:155)
at com.sun.embeddedswing.EmbeddedEventQueue.beforeDispatch(EmbeddedEventQueue.java:376)
at com.sun.embeddedswing.EmbeddedEventQueue.dispatchEvent(EmbeddedEventQueue.java:439)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
The code:
package default;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.ext.swing.SwingTextField;
import javafx.ext.swing.SwingButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.Node;
var textObjSeq : Text[] = [];
var textBoxTitle : Text = Text{
layoutX: 20
layoutY: 20
content: "Enter title"
}
var textBox : SwingTextField = SwingTextField{
columns: 4
layoutX: 20
layoutY: 25
}
var button : SwingButton = SwingButton{
layoutX: 85
layoutY: 24
text: "create new Text-type object"
onMouseClicked:function(event : MouseEvent):Void{
var title = textBox.text;
if(title != null and title.trim().length() > 0){
addNewText(title);
}
}
}
function addNewText(title:String): Void{
var yPos:Integer = 80 + 30*textObjSeq.size();
var txt = Text{
content: title
layoutX: 20
layoutY: yPos;
onMouseClicked: function(event : MouseEvent){
println("textObjSeq before deleting element {textObjSeq}");
delete event.node as Text from textObjSeq;
delete event.node from sceneContent;
println("textObjSeq after deleting element {textObjSeq}");
}
}
insert txt into textObjSeq;
//insert txt into stage.scene.content; //the same thing happens
insert txt into sceneContent;
println("sceneContent -> {sceneContent}");
println("textObjSeq -> {textObjSeq}");
println("Text with title'{title}' has been added.");
}
var sceneContent : Node[] = [textBox, textBoxTitle, button];
var stage : Stage = Stage {
title: "Creating text"
width: 400
height: 400
scene: Scene {
content: bind sceneContent
}
}
init:
deps-jar:
compile:
jar:
standard-run:
sceneContent -> SwingTextFieldTextSwingButtonText
textObjSeq -> Text
Text with title'sgsdgf' has been added.
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at com.sun.embeddedswing.EmbeddedEventQueue.moveToVisibleAndOnScreen(EmbeddedEventQueue.java:155)
at com.sun.embeddedswing.EmbeddedEventQueue.beforeDispatch(EmbeddedEventQueue.java:376)
at com.sun.embeddedswing.EmbeddedEventQueue.dispatchEvent(EmbeddedEventQueue.java:439)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
The code:
package default;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.ext.swing.SwingTextField;
import javafx.ext.swing.SwingButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.Node;
var textObjSeq : Text[] = [];
var textBoxTitle : Text = Text{
layoutX: 20
layoutY: 20
content: "Enter title"
}
var textBox : SwingTextField = SwingTextField{
columns: 4
layoutX: 20
layoutY: 25
}
var button : SwingButton = SwingButton{
layoutX: 85
layoutY: 24
text: "create new Text-type object"
onMouseClicked:function(event : MouseEvent):Void{
var title = textBox.text;
if(title != null and title.trim().length() > 0){
addNewText(title);
}
}
}
function addNewText(title:String): Void{
var yPos:Integer = 80 + 30*textObjSeq.size();
var txt = Text{
content: title
layoutX: 20
layoutY: yPos;
onMouseClicked: function(event : MouseEvent){
println("textObjSeq before deleting element {textObjSeq}");
delete event.node as Text from textObjSeq;
delete event.node from sceneContent;
println("textObjSeq after deleting element {textObjSeq}");
}
}
insert txt into textObjSeq;
//insert txt into stage.scene.content; //the same thing happens
insert txt into sceneContent;
println("sceneContent -> {sceneContent}");
println("textObjSeq -> {textObjSeq}");
println("Text with title'{title}' has been added.");
}
var sceneContent : Node[] = [textBox, textBoxTitle, button];
var stage : Stage = Stage {
title: "Creating text"
width: 400
height: 400
scene: Scene {
content: bind sceneContent
}
}