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>
...
Related
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.)
How do I make changes to generated items using FXML?
When creating a JavaFX ToolBar, a nested HBox (or VBox) is generated automatically. For example, I would like to set the spacing of this generated HBox to 0.
<ToolBar fx:id="welcomeToolBar" prefHeight="50">
<items>
<Button fx:id="closeButton" prefHeight="50" prefWidth="100" onAction="#closeWindow" text="Close" />
<Button text="New Image" prefHeight="50" prefWidth="100" onAction="#newImage" styleClass="button-accent"/>
<Pane HBox.hgrow="ALWAYS"/>
<CheckBox text="Hide this window on application start"
fx:id="hideOnLoadCheckBox" onAction="#setVisibilityOnApplicationLoad"/>
</items>
</ToolBar>
Use the CSS property -fx-spacing (uses the <size> type). You can do this in a separate CSS file and link the file or do this directly in the FXML file using the style attribute.
Example FXML:
<ToolBar fx:id="welcomeToolBar" prefHeight="50" style="-fx-spacing: 0px;">
<!-- items -->
</ToolBar>
Example CSS:
.tool-bar {
-fx-spacing: 0px;
}
The reason this works is that the default skin of the ToolBar class exposes a StyleableProperty for spacing1. I found it in the "CSS Analyzer" of Scene Builder and the JavaFX 9 (and 8)2 source code (for some reason can't get Scenic View to run). I couldn't find any documentation on this property, however; even in the JavaFX CSS Reference Guide.
1. Another undocumented styleable property exposed by the default skin (at least in JavaFX 13) is -fx-alignment which accepts a javafx.geometry.Pos. These properties are applied to the HBox or VBox depending on if the toolbar's orientation is horizontal or vertical, respectively.
2. Still present in the JavaFX 13 source code.
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.
I have a plain CheckBox in an FXML file on the same line as some other controls and labels in a HBox.
The checkBox label text-base is about 6px units lower than ALL the other text and labels on the same line (HBox).
I can manually line things up in SceneBuilder by specifying a padding-bottom value of: 6. I wanted to put that into the CSS so all checkbox labels would be "lined-up", but everthing I've tried is ignored and doesn't show in the CSS Analyzer (too).
I looked through the Checbox default styling as pointed out here:
Styling a checkbox and also:
Checkbox in the UI controls
I had similar issues with ListBox where the control is constructed from a number of components. You have to know which 'thing' is relevant. However, looking through: com/sun/javafx/scene/control/skin/
caspian/caspian.css
I can't pick the component that makes the text label lower than other text on the same line/row. Add to that, the fact that specifying the padding in the SceneBuilder designer layout, will fix the issue on a one-by-one (manual) basis, it just seems strange that it won't work for:
.check-box {
padding-bottom: 6px; /* or just 6 */
}
Does not work on the following FXML mark-up.
<HBox alignment="CENTER_LEFT" >
<children>
<CheckBox fx:id="acknowledged" alignment="TOP_LEFT" styleClass="normal" text="00">
<padding>
<Insets bottom="6.0" left="4.0" right="8.0" />
</padding>
</CheckBox>
<Button fx:id="detailButton" text="%alarm.detail.label" />
<Label fx:id="alarmType" styleClass="normal" text="%alarm.type.value">
<padding>
<Insets left="8.0" right="8.0" />
</padding>
</Label>
</children>
</HBox>
The objective is to define the padding-bottom via CSS rather than have to do it manually in the FXML:
<padding>
<Insets bottom="6.0" left="4.0" right="8.0" />
</padding>
Any ideas?
To be clear, the visual result for this row is that the checkbox itself has a base-line smaller/lower than the other elements (button, label). The CheckBox label is also subsequently "below" the other elements. If we can pad using CSS, then we don't need to manually maintain the layouts.
As a general rule, alignment problems should be solved by the layout (vs. tweaking paddings or such). So first stop to a solution could be the doc of the parent pane, here HBox:
The alignment of the content is controlled by the alignment property,
which defaults to Pos.TOP_LEFT.
That might be consistent with what you are be seeing (can't be 100% certain, though, as you forgot to include a runnable example ;-) If all other components on the line are accidentally being same height or filling the box with the checkbox smaller, it will positioned at the top of the pane.
Assumed solution is to change the pane's alignment to BASELINE_XX, quick check in code works fine for me:
private Parent getContent() {
HBox box = new HBox(new TextField("something"),
new CheckBox("soso"), new Button("hello"));
box.setAlignment(Pos.BASELINE_CENTER);
return box;
}
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.