How to remove multiple click event of javafx button - java

I have created a sample fx application with fxml using the scene buidler.
I have mapped an action handler on scene builder and write it on the java controller class. By clicking proceed button the screen will change to another screen. But sometime screen will get stuck at that time user will click proceed button multiple time, so the system will crash.
I have added disable property of button at the beginning of action controller, but it is not happening. How to block multiple event click event or just disable button at once clicked?
#FXML
public void onBtnProceedClick() {
btnProceed.setDisable(true);
// other part of method.
}
FXML
<Button fx:id="btnProceed" maxWidth="1.7976931348623157E308" mnemonicParsing="false"
onAction="#onBtnProceedClick" prefHeight="40.0" prefWidth="-1.0"
styleClass="btnProceed" text="" GridPane.columnIndex="1"
GridPane.rowIndex="0"
/>

The event has a getClickCount(). You can add a check to say if getClickCount() > 1 then do nothing and return.

Related

Loading multiple fxml in javafx

I've been searching for a while and I haven't been able to get what I wanted to do. I've been using the javafx framework to switch fxml in javafx in this thread 'Loading new fxml in the same scene' with some success. I mean, I have a main window, and this window have two different areas, the MAIN area, and the CONTENT area.
The MAIN area will remain the same in the whole application, but the CONTENT area, will be changing constantly. My MAIN area has just a toolbar, and depending which button in the toolbar you click, the fxml (and the behavior) in the CONTENT area will change.
I already have that behavior and it works like a charm using that said framework.
The thing is, that I want that all my CONTENT areas could have their own MAIN areas too, and an own CONTENT areas too. And depending on what you do in that second MAIN areas, the fxml and the behavior in that second CONTENT areas changes too.
I don't know if the framework I'm using is enough and if I will be able to get what I want to do using it.
Do you know another different framework that could help me to get that functionality?
Thanks a lot in advance!
Every .fxml that you load can have its own controller. Every controller can have custom action and loading code just like your main one does.
Basically, JavaFX is modular. If something is possible in your main pane, then it's possible in all its children too.
Generally, in UI-based frameworks, it is a wise idea to keep a hierarchy of controllers that mirrors the hierarchy of their respective components. If you want to get the child controller for the child element (for example, in order to pass the reference to the parent controller), then you can't rely on the FXML.load() shortcut, you have to use the longer syntax of:
FXMLLoader loader = new FXMLLoader(getClass().getResource("your.fxml"));
YourPaneType pane = loader.load();
YourControllerType controller = loader.getController();
You can load all of your content using fx:include and make them visible based on your needs.
<AnchorPane fx:id="root">
<children>
<!-- initial content -->
<fx:include fx:id="content1" source="content1.fxml" />
<!-- other content we want to pre-load -->
<StackPane visible="false" managed="false">
<children>
<fx:include fx:id="content2" source="content2.fxml" />
<fx:include fx:id="content3" source="content3.fxml" />
</children>
</StackPane>
</children>
</AnchorPane>
and in the controller
#FXML
Pane root;
#FXML
Pane content1;
#FXML
Pane content2;
#FXML
Pane content3;
#FXML
NestedContentController content1Controller;
#FXML
NestedContentController content2Controller;
#FXML
NestedContentController content3Controller;
public void showContent1() {
root.getChildren().setAll(content1);
}
public void showContent2() {
root.getChildren().setAll(content2);
}
public void showContent3() {
root.getChildren().setAll(content3);
}
(The initially hidden content could also be defined outside the object hierarchy in an <fx:define> element, but then SceneBuilder doesn't provide an option to reveal the included file.)

JavaFX - StackPane component jumping

i recently explored JavaFX and came across a simple login form executing the login via php script.
Based on the result the login form indicates an error label or redirects to a new scene.
During the actual login progress i want to show an progress bar which i exchange (visibility toggle) with an error label whenever the login did not succeed.
For some reason the progress bar jumps to a new position after the label appeared once.
Video showing the bug behavior:
Video of the issue
Minimal example to reproduce this behavior (JDK8, Language level=8):
Code sample
Well the component is jumping because when your are applying text to the Label, the width of the StackPane is getting increased and the ProgressBar gets shifted to the CENTER.
For future references, you can check similar phenomenon by applying a style to the StackPane or any other Layout
<StackPane style=" -fx-border-color:black;
-fx-border-width: 1; -fx-border-style: solid;">
To avoid this, you will have to wrap the ProgressBar in a HBox and set the alignment of the HBox
...
<Label id="login-status-label" fx:id="loginStatusLabel" />
<HBox alignment="CENTER_RIGHT">
<ProgressIndicator id="login-status-progress-indicator"
fx:id="loginStatusProgressIndicator" prefHeight="15.0"
prefWidth="15.0" visible="false"/>
</HBox>
...

Can I Layer JavaFX Controls?

I just had a problem with an invisible, disabled list and a text field(visible) underneath it. I wasn't able to access the text field because I was still clicking on the list. Is there any way to have an invisible control and still be able to use the control underneath it?
Yes, use the StackPane control. This is easiest to do using the JavaFX scenebuilder.
This webpage has a topic on StackPanes.
I am assuming that you just have to fiddle with the StackPane.alignment to change which controls are usable etc. Hope this helps;
FXML:
<StackPane id="StackPane" HBox.hgrow="ALWAYS">
<children>
<ProgressBar fx:id="" disable="false" prefWidth="294.0" progress="0.0" StackPane.alignment="CENTER" />
<Slider fx:id="" prefWidth="294.0" style="" StackPane.alignment="CENTER" />
</children>
</StackPane>

How to make a window visible="false" when window mode="modal"

<window title="My First Window" border="normal" width="200px" visible="false" mode="modal">
Hello, World!
</window>
When running this example i expect that there is no popUp window shown as visible="false" ....
But i do get a popUp ... what am i missing ?
When i remove mode="modal" it runs fine. So how do we control visible property on window with mode = "model"
Zk fiddle example
Why i want to do the above described;
I am following the mvvm model so when something happens in app i want to show a popup by just making the popup window visible that is why i want to create a modal window that is immediately dismissed and show it later
Gut feeling is that what you're asking doesn't make sense. A modal window must have focus and must be dismissed before you can move on. So if it's there, how can it not be visible?
I think rather than showing a Modal Window I will suggest use Notification
Clients.showNotification(msg); // display a global notification box
Clients.showNotification(msg, component); // display a notification box pointing to a component
And in your code use code like this and see what will happen
<window title="My First Window" border="normal" width="200px" mode="modal" visible="false">
Hello, World!
</window>
<window id="win" visible="false">
</window>
when u need your window to be visible just do:
win.doModal();

Tab sequencing with JRadioButton

I am developing GUI in an application (which is based on Spring framework) using Swing. In one of the screens, we have several JButtons, JLabels, JFormattedtextFields and JRadioButtons in a panel.
The question is:
1). When I press the tab button from the keyboard, the control does not goe to the JRadioButton field (though it goes to other components before and after it). It does not appear on these radio buttons (a serious issue with the application). How to fix this.
2).Also to set the text(label) for each radio buton, i have to do in separate labels:
<label text="Raiding" constraints="21,1" font="Arial-PLAIN-12" />
<buttongroup>
<radiobutton id="raidingYesID" font="Arial-PLAIN-12"
opaque="false" constraints="22,1" label="Yes"/>
<label text="Yes" constraints="23,1" font="Arial-PLAIN-12" />
<radiobutton id="raidingNOID" font="Arial-PLAIN-12"
selected="true" opaque="true" constraints="24,1"/>
<label text="No" constraints="25,1" font="Arial-PLAIN-12" />
</buttongroup>
I tried to do it in java, but the labels did not appear:
raidingYesID.setLabel("Yes");
raidingYesID.setName("Yes");
raidingNOID.setText("No");
none of them made any difference, but i could get the label on console by using:
System.out.println(raidingYesID.getLabel());
do suggest any solutions...
For your second question: use setText() to set the JRadioButton text and use getText() to get it back. The button text can also be set in the constructor.

Categories

Resources