Editable ComboBox cleared when i pressed space or arrow buttons - JavaFX - javafx

I am making a Editable ComboBox which show any values contain the input and it works fine.
But the problem is in the input field, whenever i typed Space or arrow buttons the input field keep reseting.
I tried setonKeyPressed and setonKeyTyped too but it isn't solve the problem.
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
ObservableList<String> fruit = FXCollections.observableArrayList();
fruit.add("apple");
fruit.add("orange");
fruit.add("banana");
ComboBox myComboBox = new ComboBox();
myComboBox.setEditable(true);
myComboBox.setOnKeyReleased(new EventHandler<KeyEvent>() {
#Override
public void handle(KeyEvent keyEvent) {
myComboBox.getItems().clear();
myComboBox.show();
String input = myComboBox.getEditor().getText();
for ( int i = 0 ; i < fruit.size(); i++) {
if(fruit.get(i).contains(input)) { //Check if the list contains the input
myComboBox.getItems().add(fruit.get(i));
}
}
}
});
HBox hbox = new HBox(myComboBox);
primaryStage.setScene(new Scene(hbox, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}

Related

is there any way to add button into dropdown list with textfields using controlfx jar

i have a textfield with autocomplete and i want to show button near each item appeared into that list
this is my code
List<String> s = ms.getUsernames(ms.getUser(7).getListamis());
TextFields.bindAutoCompletion(txtsearch, s);
this is the method getusernames
public List<String> getUsernames(String list_amis) {
List<String> ls = new ArrayList<>();
String [] idmember = list_amis.split("/");
for (String i : idmember) {
ls.add(getUser(Integer.parseInt(i)).getUsername());
}
return ls;
}
this is my output
i want to add a button near testing as a result i can get its ID
This is the solution I came up with. There certainly is a better way that is more elegant and works better, but I guess this would work for many situations. You would have to do something about the size of the ListView, though, and I didn't test this in an environment in which the appearing ListView might change something about the design of the rest of the UI. I suggest putting the whole thing into a PopOver or something.
import java.util.function.Predicate;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class NewFXMain extends Application {
#Override
public void start(Stage primaryStage) {
ObservableList<String> list = FXCollections.observableArrayList("one","two","three");
FilteredList<String> filteredList = new FilteredList<>(list);
VBox box = new VBox();
TextField textField = new TextField();
textField.textProperty().addListener(new ChangeListener<String>() {
#Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
filteredList.setPredicate(new Predicate<String>() {
#Override
public boolean test(String s){
return s.toLowerCase().contains(newValue.toLowerCase());
}
});
}
});
ListView listView = new ListView();
listView.setItems(filteredList);
listView.visibleProperty().bind(textField.textProperty().isNotEmpty());
listView.setCellFactory(new Callback() {
#Override
public Object call(Object param) {
ListCell cell = new ListCell(){
#Override
public void updateItem(Object item, boolean empty){
if(item != null && !empty){
super.updateItem(item, empty);
HBox contentBox = new HBox();
Label label = new Label(item.toString());
Button button = new Button("delete");
HBox separator = new HBox();
HBox.setHgrow(separator, Priority.ALWAYS);
button.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println(item);
}
});
contentBox.getChildren().addAll(label, separator, button);
setGraphic(contentBox);
}else{
setText(null);
setGraphic(null);
}
}
};
return cell;
}
});
box.getChildren().addAll(textField,listView);
StackPane root = new StackPane();
root.getChildren().add(box);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Autocomplete");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}

JavaFX Stage not fully loaded

I have this whole mess of Controls and Transitions in the Scene, and whenever an error or message is made, I call FormBuilder.say(String x).
The sample included doesn't error as much, because it's empty. But when all the stuff are active, the pop up from FormBuilder.say(String x) comes out as a mess.
If I wait long enough, attempt to interact, or if I minimize then restore the Stage, it loads properly. But many times, it's just blank.
My laptop runs Ubuntu 15.10, with approx 2GB RAM. No Video Card.
Included is a screen cap of the messy picture.
Included is the code that's affected during the bug. I've striped out some of the less suspected parts. (EDITED)
package solo;
import javafx.animation.Animation;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
import javafx.util.Duration;
public class FormBuilder extends Application{
Stage ps;
public FormBuilder(){
}
public void begin(String[] args){
launch(args);
}
public void start(Stage primaryStage) {
ps = primaryStage;
ps.setTitle("E-VIL v0.0");
ps.setScene(new Scene(scene(), 800, 600));
ps.show();
}
public void say(String things){
Stage stage = new Stage(StageStyle.UTILITY);
stage.initOwner(ps);
Text text = new Text(things);
Button btn = new Button("Okay");
btn.setOnAction(e -> {stage.close();});
VBox pane = new VBox(text,btn);
pane.setAlignment(Pos.TOP_CENTER);
text.setLayoutY(12);
pane.autosize();
stage.setScene(new Scene(pane));
stage.sizeToScene();
stage.setOnShown(e -> {stage.requestFocus();});
stage.showAndWait();
}
public Pane scene(){
Pane pn = new Pane();
Button btn = new Button("Say Something");
btn.setOnAction(e->{FormBuilder.this.say("Something");});
btn.setLayoutX(0);
btn.setLayoutY(10);
pn.getChildren().add(btn);
pn.sceneProperty().addListener(new ChangeListener<Scene>(){
#Override
public void changed(ObservableValue<? extends Scene> arg0, Scene arg1, Scene arg2) {
System.out.println("new Scene");
if(arg2 != null)
arg2.windowProperty().addListener(new ChangeListener<Window>(){
#Override
public void changed(ObservableValue<? extends Window> observable, Window oldValue,
Window newValue) {
System.out.println("new window");
if(newValue != null){
Rectangle rect = new Rectangle(0,30,300,300);
rect.setFill(Color.RED);
pn.getChildren().add(rect);
Rectangle box = new Rectangle(30,60,50,50);
TranslateTransition tt = new TranslateTransition(Duration.seconds(1), box);
tt.setByX(160);
tt.setByY(160);
tt.setAutoReverse(true);
tt.setCycleCount(Animation.INDEFINITE);
pn.getChildren().add(box);
tt.play();
}
}
});
}
});
return pn;
}
}
package solo;
public class Main {
public static void main(String args[]){
FormBuilder fb = new FormBuilder();
fb.begin(args);
}
}

JavaFX application won't compile in NetBeans IDE 8.1

I am trying to run this application in which I used event-handling and it won't compile and won't show anything. I am currently using NetBeans 8.1. What is that I did wrong. Also it is not showing any errors.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class event extends Application {
public void start(Stage primaryStage)
{
HBox pane = new HBox();
pane.setAlignment(Pos.CENTER);
Button btOk = new Button("OK");
Button btCancel = new Button("Cancel");
OkHandlerClass handler1 = new OkHandlerClass();
btOk.setOnAction(handler1);
CancelHandlerClass handler2 = new CancelHandlerClass();
pane.getChildren().addAll(btOk, btCancel);
Scene scene = new Scene(pane);
primaryStage.setTitle("Handle the fucking event");
primaryStage.setScene(scene);
primaryStage.show();
}
class OkHandlerClass implements EventHandler<ActionEvent>{
public void handle(ActionEvent e) {
System.out.println("OK button clicked");
}
}
class CancelHandlerClass implements EventHandler<ActionEvent>{
public void handle(ActionEvent event) {
System.out.println("Cancel button clicked");
}
}
public static void main(String[] args) {
launch(args);
}
}

Show breakpoint at line number in RichTextFx CodeArea

I'm working with RichTextFx's CodeArea to highlight custom mini language code.
Now while executing this code I want to show a small arrow in front of current executed line. I know the specific line number but can't get anything to happen with the line number label.
Since github project claims showing line numbers or breakpoint toggles as a feature this can't be very difficult. But can't get anything to work...
Thanks in advance
To show any graphic in front of the line, you need to set the "paragraph graphic factory" of the CodeArea. This graphic factory is just a function int -> Node: given the line number, it returns a Node that will be displayed in front of the line.
Here is a graphic factory that produces a green triangle pointing at the line. It will only be shown when the line is equal to the given integer property shownLine.
class ArrowFactory implements IntFunction<Node> {
private final ObservableValue<Integer> shownLine;
ArrowFactory(ObservableValue<Integer> shownLine) {
this.shownLine = shownLine;
}
#Override
public Node apply(int lineNumber) {
Polygon triangle = new Polygon(0.0, 0.0, 10.0, 5.0, 0.0, 10.0);
triangle.setFill(Color.GREEN);
ObservableValue<Boolean> visible = Val.map(
shownLine,
sl -> sl == lineNumber);
triangle.visibleProperty().bind(visible.conditionOnShowing(t‌​riangle));
return triangle;
}
}
Each graphic (i.e. little green triangle) you create will be observing the given shownLine property to decide whether it should be visible. As lines, and therefore line graphics, come and go, it is important to remove the listener of shownLine when the graphic is no longer used. visible.conditionOnShowing(t‌​riangle) is a new property that will stop observing the visible property (and automatically also the shownLine property, thanks to ReactFX's lazy binding semantics) and reset to constant false whenever the triangle is not part of a showing window. So we don't cause memory or CPU leaks due to uncleaned listeners.
Here is a complete runnable demo that uses this ArrowFactory combined with the LineNumberFactory provided by RichTextFX to show both line numbers and a little triangle. This demo uses the CodeArea's current line as the shownLine property. You will want to substitute it for a property that contains the current line of execution.
import java.util.function.IntFunction;
import javafx.application.Application;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.stage.Stage;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.reactfx.value.Val;
public class CodeAreaWithLineIndicator extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
CodeArea codeArea = new CodeArea();
IntFunction<Node> numberFactory = LineNumberFactory.get(codeArea);
IntFunction<Node> arrowFactory = new ArrowFactory(codeArea.currentParagraphProperty());
IntFunction<Node> graphicFactory = line -> {
HBox hbox = new HBox(
numberFactory.apply(line),
arrowFactory.apply(line));
hbox.setAlignment(Pos.CENTER_LEFT);
return hbox;
};
codeArea.setParagraphGraphicFactory(graphicFactory);
primaryStage.setScene(new Scene(new StackPane(codeArea), 600, 400));
primaryStage.show();
}
}
class ArrowFactory implements IntFunction<Node> {
private final ObservableValue<Integer> shownLine;
ArrowFactory(ObservableValue<Integer> shownLine) {
this.shownLine = shownLine;
}
#Override
public Node apply(int lineNumber) {
Polygon triangle = new Polygon(0.0, 0.0, 10.0, 5.0, 0.0, 10.0);
triangle.setFill(Color.GREEN);
ObservableValue<Boolean> visible = Val.map(
shownLine,
sl -> sl == lineNumber);
triangle.visibleProperty().bind(visible.conditionOnShowing(t‌​riangle));
return triangle;
}
}
And this is the result:
Working example
import javafx.application.Application;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.stage.Stage;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.reactfx.value.Val;
import java.util.function.IntFunction;
public class CodeAreaWithLineIndicator extends Application {
CodeArea codeArea;
TextField textField;
public static final IntegerProperty lineValue = new SimpleIntegerProperty(-1) ;
/* public final int getValue() {
return value.get();
}*/
/* public final void setValue(int value) {
this.value.set(value);
}*/
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
codeArea = new CodeArea();
codeArea.replaceText(0,0,"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
codeArea.setPrefHeight(400);
IntFunction<Node> numberFactory = LineNumberFactory.get(codeArea);
IntFunction<Node> arrowFactory = new ManualArrowFactory(lineValue);
IntFunction<Node> graphicFactory = line -> {
HBox hbox = new HBox(
numberFactory.apply(line),
arrowFactory.apply(line));
hbox.setAlignment(Pos.CENTER_LEFT);
return hbox;
};
codeArea.setParagraphGraphicFactory(graphicFactory);
VBox vbox = new VBox();
textField = new TextField();
textField.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
try {
lineValue.setValue(Integer.parseInt(textField.getText()));
} catch (NumberFormatException e) {
}
}
});
Button button = new Button("MoveIt");
button.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
try {
lineValue.setValue(Integer.parseInt(textField.getText()));
} catch (NumberFormatException e) {
}
}
});
vbox.getChildren().addAll(textField, button, codeArea);
Scene scene = new Scene(vbox, 600, 600);
primaryStage.setScene(scene);
primaryStage.show();
}
class ManualArrowFactory implements IntFunction<Node> {
private final IntegerProperty shownLine;
public ManualArrowFactory(IntegerProperty shownLine) {
this.shownLine = shownLine;
}
#Override
public Node apply(int lineNumber) {
Polygon triangle = new Polygon(0.0, 0.0, 10.0, 5.0, 0.0, 10.0);
triangle.setFill(Color.GREEN);
ObservableValue<Boolean> visible = Val.map(shownLine, sl -> sl.intValue()-1 == lineNumber);
triangle.visibleProperty().bind(
Val.flatMap(triangle.sceneProperty(), scene -> {
return scene != null ? visible : Val.constant(false);
}));
return triangle;
}
}
}
For multiline implementation:
import javafx.application.Application;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.reactfx.value.Val;
import java.util.function.IntFunction;
public class CodeAreaWithLineIndicator extends Application {
CodeArea codeArea;
TextField textField;
public static final IntegerProperty lineValue = new SimpleIntegerProperty(-1) ;
public static final ObservableList<Integer> olistValue = FXCollections.observableArrayList();
public static final ListProperty<Integer> listValue = new SimpleListProperty<Integer>(olistValue);
/* public final int getValue() {
return value.get();
}*/
/* public final void setValue(int value) {
this.value.set(value);
}*/
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
codeArea = new CodeArea();
codeArea.replaceText(0,0,"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
codeArea.setPrefHeight(400);
IntFunction<Node> numberFactory = LineNumberFactory.get(codeArea);
IntFunction<Node> arrowFactory = new MultiBreakPointFactory(listValue);
IntFunction<Node> graphicFactory = line -> {
HBox hbox = new HBox(
numberFactory.apply(line),
arrowFactory.apply(line));
hbox.setAlignment(Pos.CENTER_LEFT);
return hbox;
};
codeArea.setParagraphGraphicFactory(graphicFactory);
VBox vbox = new VBox();
textField = new TextField();
textField.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
int newValue = Integer.parseInt(textField.getText());
olistValue.add(newValue);
}
});
Button button = new Button("Clear");
button.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
olistValue.clear();
}
});
vbox.getChildren().addAll(textField, button, codeArea);
Scene scene = new Scene(vbox, 600, 600);
primaryStage.setScene(scene);
primaryStage.show();
}
class MultiBreakPointFactory implements IntFunction<Node> {
private final ListProperty<Integer> shownLines;
public MultiBreakPointFactory(ListProperty<Integer> shownLine) {
this.shownLines = shownLine;
}
#Override
public Node apply(int lineIndex) {
StackPane stackPane = new StackPane();
Circle circle = new Circle(10.0, 10.0, 6.0, Color.RED);
Rectangle rectangle = new Rectangle(20,20);
rectangle.setFill(Color.TRANSPARENT);
rectangle.setCursor(Cursor.HAND);
rectangle.setOnMouseClicked(me->{
if (!olistValue.contains(lineIndex+1)){
olistValue.add(lineIndex+1);
}
});
stackPane.getChildren().addAll(rectangle, circle);
circle.setOnMouseClicked(me->{
int index = olistValue.indexOf(lineIndex+1);
if (index>-1)
olistValue.remove(index);
});
circle.setCursor(Cursor.HAND);
ObservableValue<Boolean> visible = Val.map(shownLines, sl -> sl.contains(lineIndex+1));
circle.visibleProperty().bind(
Val.flatMap(circle.sceneProperty(), scene -> {
return scene != null ? visible : Val.constant(false);
}));
return stackPane;
}
}
}
Enter a number to textfield and click enter. Now only changing oListValue will show breakpoint lines on the codearea.

JavaFX PopOver From ControlFX

Can someone write a short JavaFX example of a Popover from ControlFX ? I haven't been able to get it to work. Any help is greatly appreciated!
This answer is a simple use of ControlsFX's PopOver.
When the mouse moves over the Label the PopOver appears. When the mouse exits the Label the PopOver disappears.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.controlsfx.control.PopOver;
/**
*
* #author Sedrick
*/
public class JavaFXApplication35 extends Application {
#Override
public void start(Stage primaryStage) {
//Build PopOver look and feel
Label lblName = new Label("John Doe");
Label lblStreet = new Label("123 Hello Street");
Label lblCityStateZip = new Label("MadeUpCity, XX 55555");
VBox vBox = new VBox(lblName, lblStreet, lblCityStateZip);
//Create PopOver and add look and feel
PopOver popOver = new PopOver(vBox);
Label label = new Label("Mouse mouse over me");
label.setOnMouseEntered(mouseEvent -> {
//Show PopOver when mouse enters label
popOver.show(label);
});
label.setOnMouseExited(mouseEvent -> {
//Hide PopOver when mouse exits label
popOver.hide();
});
StackPane root = new StackPane();
root.getChildren().add(label);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
you must google out for that
many sites are available nowadays
https://bitbucket.org/controlsfx/controlsfx/commits/dca9619e05de26d176aaafe785c3b94f022562ef
https://bitbucket.org/controlsfx/controlsfx/pull-request/158/initial-commit-of-popover-control/activity
and etc. just Google out.
Here we have program known as "HelloPopOver".
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ListView;
import javafx.scene.control.Slider;
import javafx.scene.control.TitledPane;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;
import org.controlsfx.ControlsFXSample;
import org.controlsfx.control.popover.PopOver;
import org.controlsfx.control.popover.PopOverController;
import org.controlsfx.control.popover.PopOverHeader;
import org.controlsfx.control.popover.PopOverTitledPane;
import org.controlsfx.samples.Utils;
public class HelloPopOver extends ControlsFXSample {
private PopOverController<PopOver, Button> controller = new MyController();
#Override
public Node getPanel(Stage stage) {
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setAlignment(Pos.CENTER);
grid.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent evt) {
controller.hidePopOver();
}
});
for (int i = 0; i < 10; i++) {
final Button button = new Button("Button " + i);
grid.add(button, i % 2, i / 2);
button.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent evt) {
controller.hidePopOver();
if (evt.getClickCount() == 2) {
controller.setupPopOver(button);
controller.showPopOver(button, evt.getScreenX(),
evt.getScreenY());
}
}
});
}
return grid;
}
class MyController extends PopOverController<PopOver, Button> {
#Override
protected PopOver createPopOver(final Button button) {
PopOver editor = new PopOver();
PopOverHeader<?> header = (PopOverHeader<?>) editor.getHeader();
header.setTitle(button.getText() + " (edit me)");
header.setSubtitle("Just some random controls (edit me)");
editor.setDetachedTitle(button.getText());
editor.getPanes().add(createTitledPane("Start Time & Duration"));
editor.getPanes().add(createTitledPane("Dependencies"));
editor.getPanes().add(createTitledPane("Priority"));
editor.getPanes().add(createTitledPane("Assignments / Resources"));
editor.setExpandedPane(editor.getPanes().get(0));
editor.setFooter(new Footer());
ColorPicker picker = (ColorPicker) header.getExtra();
picker.valueProperty().addListener(new ChangeListener<Color>() {
#Override
public void changed(ObservableValue<? extends Color> value,
Color oldColor, Color newColor) {
button.setBackground(new Background(new BackgroundFill(
newColor, CornerRadii.EMPTY, Insets.EMPTY)));
}
});
return editor;
}
}
private TitledPane createTitledPane(String title) {
VBox box = new VBox(5);
box.getChildren().add(new Button("Test"));
box.getChildren().add(new Slider());
ListView<String> view = new ListView<>();
view.setPrefHeight(100);
box.getChildren().add(view);
final TitledPane pane = new PopOverTitledPane(title, box);
pane.setTextAlignment(TextAlignment.LEFT);
Pane connectivityArrow = (Pane) pane.lookup(".arrow");
if (connectivityArrow != null) {
connectivityArrow.translateXProperty().bind(
pane.widthProperty().subtract(
connectivityArrow.widthProperty().multiply(2)));
}
return pane;
}
class Footer extends FlowPane {
public Footer() {
super(Orientation.HORIZONTAL);
setAlignment(Pos.CENTER_RIGHT);
Button delete = new Button("Delete");
getChildren().add(delete);
delete.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent evt) {
}
});
}
}
public static void main(String[] args) {
Application.launch(args);
}
#Override
public String getSampleName() {
return "PopOver";
}
#Override
public String getJavaDocURL() {
return Utils.JAVADOC_BASE
+ "org/controlsfx/control/popover/PopOver.html";
}
#Override
public String getSampleDescription() {
return "An implementation of a pop over control as used by Apple for its iCal application. A pop over allows"
+ "the user to see and edit an objects properties. The pop over gets displayed in its own popup window and"
+ "can be torn off in order to create several instances of it.";
}
}

Resources