Cant make JDialogBox of jfoenix library using scene builder - javafx

Can somebody explain how to use Dialogue box from above library through XML. Without coding the dialog box using java, Can't I just design it from scene builder by dragging and dropping component.
I have already tried it but when I run the program dialog box is not visible.
Would be really helpful if someone can share a working example or even a link
without using this method.
How to create a dialog using JFXDialog of JFoenix in JavaFX

Double height = posCenterAnchor.getHeight();
Double width = posCenterAnchor.getWidth();
StackPane stackPane = new StackPane();
AnchorPane.setTopAnchor(stackPane, 20.0); // adding anchor pane margins
AnchorPane.setLeftAnchor(stackPane, 20.0);
AnchorPane.setRightAnchor(stackPane, 20.0);
AnchorPane.setBottomAnchor(stackPane, 20.0);
posCenterAnchor.getChildren().add(stackPane);
JFXDialogLayout jfxDialogLayout = new JFXDialogLayout();
Parent parent;
try {
parent = FXMLLoader.load(getClass().getResource("/Views/SelectCustomer.fxml"));
jfxDialogLayout.getChildren().add(parent);
JFXDialog jfxDialog = new JFXDialog(stackPane, jfxDialogLayout, JFXDialog.DialogTransition.CENTER, true);
jfxDialog.show();
} catch (Exception e) {
e.printStackTrace();
}
just figured it out..all i had to do is ,just crate the content of the dialog box in a separate layout file and through code by creating a new dialog object then adding that layout to a dialog box...simple...wonder where went wrong..

Related

Gluon AppBar keep in the view

I'm trying to build a message window with App Bar on the top
This screen consist of Gluon App Bar on the top and VBox in bottom which has rest of the element shown in the screen.
Issue is when i click on the text area to enter text the App Bar goes out of scope.
Is there a way I can set App Bar to be always on top?
If you are deploying your app on Android, the TextField and TextArea controls include a built-in check: when those input controls get focused, if required the scene is moved up to prevent the software keyboard from hiding the control.
These translation affects the whole scene, so all the nodes in it (View, VBox, TextField, TextArea, AppBar, ...), will be translated as well.
So if you want to keep the AppBar node always visible and in the same top position, a possible fix could be counteracting that translation whenever it happens.
If you have a BasicView for instance (Gluon IDE plugin -> single view project), with a TextField control at the bottom of the view:
public BasicView() {
Label label = new Label("Hello JavaFX World!");
Button button = new Button("Change the World!");
button.setGraphic(new Icon(MaterialDesignIcon.LANGUAGE));
button.setOnAction(e -> label.setText("Hello JavaFX Universe!"));
VBox controls = new VBox(15.0, label, button, new TextField());
controls.setAlignment(Pos.BOTTOM_CENTER);
controls.setPadding(new Insets(20));
setCenter(controls);
}
you can modify it like this:
public BasicView() {
...
setOnShown(e -> {
MobileApplication.getInstance().getAppBar().translateYProperty()
.bind(controls.getScene().getRoot().translateYProperty().multiply(-1));
});
}
Make sure that the view is already added to the scene when you add this binding (to prevent a NPE).
Now when the textfield gets the focus, the whole scene will be moved up, and the appBar will be moved down the same amount:

JavaFX - Combobox Expands Downward Off Screen (Post 8u60)

I thought this bug was supposed to be fixed a long time ago... but when I place a ComboBox near the bottom of a window it expands downward and off the screen. I think the reason it does this is because there are other controls above it, so rather than "bump" into those it just expands downward instead. Why doesn't the combo box expand over the the rest of the layout? All I know is that when I add some padding above it, it will expand upward instead of downward.
Example:
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
ObservableList<String> choiceList = FXCollections.observableArrayList();
choiceList.addAll("Choice1", "Choice2", "Choice3", "Choice4");
ComboBox<String> choices = new ComboBox<>(choiceList);
choices.setMinWidth(100);
Button button1 = new Button("First Button");
button1.setMinWidth(150);
Button button2 = new Button("Second Button");
button2.setMinWidth(150);
VBox layout = new VBox(10);
layout.setPadding(new Insets(10, 10, 10, 10));
layout.getChildren().addAll(button1, button2, choices);
Scene scene = new Scene(layout);
primaryStage.setScene(scene);
primaryStage.setTitle("Example");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Image of window displayed by the above code
Anybody got a fix for this?
Note, if in your case, you are moving your main application window to the bottom of the screen and the combo box is still dropping down and being cut off so that some contents of the popup are not visible, then it may well be a bug. But my guess is, that if that is what is happing, that it is a system specific issue as I cannot replicate such an issue on OS X. If that is the case, try a Java 9 early access release and see if the issue still replicates, and if it does you could file a bug report.
This is not bug, it is by design.
The ComboBox popup is internally implemented as a PopupControl. A PopupControl is a new window, which isn't constrained to lie within the bounds of its parent window (your main stage). JavaFX has logic to ensure that popups such as the ContextMenus and ComboBox popups are shown within the visible screen area, not the owning stage area.
If you move your main application towards the top of the screen, then open the combo box popup, the popup will drop down because there is room on the screen to display it. But if you move the main application towards the bottom of the screen, then the open the combo box popup, the popup will drop up (I don't know a better way to explain that concept ;-) because there is no room to display the popup if it were to drop down.
Drop up sample. Created by running your example code on OS X, moving the main application window near the bottom of the screen and opening the combo box popup.

JavaFx add context menu from controller

I am trying my way through JavaFX and still have many - probably silly - beginner questions.
My problem of the day is the following:
I am creating, in Scene builder and Controller, a FlowPane to which I want to add a right-click option, that opens a Context Menu.
Through the scene builder I have added the function OnContextMenuRequested and defined it in the Controller.
To check, I have added a print commend and a Dialog Box to the function, which work well.
Yet, the Context Menu does not work..
Anybody could help and tell me what am I missing???
Thanks in advance...
public void contextMenu(ContextMenuEvent contextMenuEvent) {
// working fine ..
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Information");
alert.setHeaderText("Look");
alert.setContentText("Message");
alert.showAndWait();
// working fine
System.out.println("Hello");
// Context Menu ......... not working
ContextMenu contextMenu = new ContextMenu();
MenuItem quit = new MenuItem("quit");
MenuItem hello = new MenuItem("hello");
contextMenu.getItems().addAll(quit, hello);
contextMenu.setX(10.0);
contextMenu.setY(10.0);
contextMenu.show();
????.setContextMenu(????)
}
Unless you have a control, you need to show the ContextMenu "manually" using one of the methods defined in ContextMenu:
// contextMenu.setX(10.0);
// contextMenu.setY(10.0);
contextMenu.show((Node) contextMenuEvent.getSource(), contextMenuEvent.getScreenX(), contextMenuEvent.getScreenY());

How customize the chart from another window in JavaFX

I'm new at Stackoverflow and Javafx (and Java at all), so my question can be stupid.
I have a .fxml file with main window (it's include LineChart) and Controller.java, binded to it. And I need make new window with chart options (color and thickness of line). I'm making window with options by event, binded on menuItem in main window.
So, how I can change properties of chart in main window from options window?
I don't understand at all how to get access to LineChart in main window!
This is how I open options window:
void showSettings(ActionEvent event)
throws IOException {
Group root = new Group();
Stage stage = new Stage();
AnchorPane frame = FXMLLoader.load(getClass().getResource("options.fxml"));
root.getChildren().add(frame);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
Can anybody help me?
P.S. Sorry for my bad English level :c
Edit1: I need pass params from new window(options) to already existing (main)!

How to creat a button programmatically with JavaFX?

I want to make a button on an AnchorPane without drag it from the library in the FXML file I want to do it progammatically: if the search button clicked, should show a new button not existed in the AnchorPane before I did this code but I don't know what is wrong with it:
private void searchButton(ActionEvent evt) {
Button tab = new Button();
tab.setLayoutX(147);
tab.setLayoutY(102);
tab.setText("Tab1");
tab.setPrefHeight(27);
tab.setPrefWidth(69);
WebView wb = new WebView();
wb.setLayoutX(-1);
wb.setLayoutY(128);
wb.setPrefWidth(1604);
wb.setPrefWidth(700);
}
I am assuming that you searchButton method is in controller attached to some FXML. Then all you need to do is this:
yourAnchorPane.getChildren().add(tab);
If you don't have already published reference to anchorPane in your controller, then add this into your controller
#FXML
AnchorPane yourAnchorPane;
And in SceneBuilder select your anchorPane, go to code tab and enter "yourAnchorPane" as fx:id.
Further info on working with anchorpane is javadoc.
You probably also want to set some constraints on the tab to locate it at a position within the AnchorPane. For instance, the following code will locate your button tab relative to the top left corner of the AnchorPane: Ten pixels down and fifteen pixels to the right.
AnchorPane.setTopAnchor(tab, 10.0);
AnchorPane.setLeftAnchor(tab, 15.0);

Resources