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.
Related
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 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>
I have tabbox with several vertical tabs. I need to add labels between some tabs(or just make disabled tabs with this labels).
How can I do that?
Thanks to Konstantin V. Salikhov. This is solution
<tab label="Hello there!" disabled="true" />