how to position a button in HBox - JAVAFx - javafx

I am new to JAVAfx, i trying to code a web browser. The problem i am facing is :- i want to place the button present on the Bottom left of the screen to the bottom right.
I am trying this code but it is not working. Somebody please help
Button Developer = new Button();
Developer.setAlignment(Pos.BOTTOM_RIGHT);
here is the screenshot: http://i.stack.imgur.com/4RTpr.png
Thanks

You should be able to set the alignment on the HBox instead of the Button itself.
Button developer = new Button();
HBox hbox = new HBox();
hbox.setAlignment(Pos.BOTTOM_RIGHT);
hbox.getChildren().add(developer);

Related

Cant make JDialogBox of jfoenix library using scene builder

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..

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 TitledPane click event only for Title

Is there any way I can have an event that only triggers if I click the Title of a TitledPane?
I have several Nodes in a Graph Editor and currently they are draggable.
But I want them only to drag when i drag the Title not if I click anywhere on the pane.
the mouseClick event seems not to work for me.
Does anyone have suggestions?
Don't set the text on the titled pane, but instead create a label and set it as the graphic for the titled pane. Then you can register a mouse handler with the label:
private TitledPane createClickableTitledPane(String text) {
Label label = new Label(text);
label.setOnMouseClicked(e -> System.out.println("Click on "+text));
TitledPane titledPane = new TitledPane();
titledPane.setGraphic(label);
return titledPane ;
}
StackPane titleRegion = (StackPane) titledPane.lookup(".title");
titleRegion.setOnMouseClicked(System.out::println);
EDIT:
Sometimes titledPane.lookup(".title") returns null which means CSS is not applied to the node. To resolve this issue, you need to use applyCss() and layout() on the pane that contains the TitledPane.
See:
JavaFX TitledPane lookup(.title) returns null

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