How to implement ToggleGroup in fxml file, using Spring vs JavaFx
Have MainController:
public class MainController {
@FXML private RadioButton radioButton;
@FXML private RadioButton radioButton2;
@FXML
public void addContact() {
boolean b = radioButton.isSelected();
boolean b2 = radioButton.isSelected();
}
And mxin.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="350.0" prefWidth="755.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.habrahabr.ui.MainController">
<children>
<TableView fx:id="table" editable="true" prefHeight="200.0" prefWidth="405.0" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnResizePolicy><TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /></columnResizePolicy>
</TableView>
<HBox alignment="CENTER" layoutX="21.0" layoutY="207.0" prefHeight="50.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0">
<children>
<RadioButton fx:id="radioButton" text="Male">
<HBox.margin>
<Insets right="3.0"/>
</HBox.margin>
</RadioButton>
<RadioButton fx:id="radioButton2" text="Female">
<HBox.margin>
<Insets right="30.0"/>
<Insets bottom="10.0"/>
</HBox.margin>
</RadioButton>
<Button minWidth="-Infinity" mnemonicParsing="false" onAction="#addContact" text="Add" />
</children>
</HBox>
</children>
</AnchorPane>
All is fine, but I need to combine the both Radio Buttons in the one group and I can not find a solution to how to implement something like ToggleGroup inmain.fxml.
spring javafx
add a comment |
Have MainController:
public class MainController {
@FXML private RadioButton radioButton;
@FXML private RadioButton radioButton2;
@FXML
public void addContact() {
boolean b = radioButton.isSelected();
boolean b2 = radioButton.isSelected();
}
And mxin.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="350.0" prefWidth="755.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.habrahabr.ui.MainController">
<children>
<TableView fx:id="table" editable="true" prefHeight="200.0" prefWidth="405.0" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnResizePolicy><TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /></columnResizePolicy>
</TableView>
<HBox alignment="CENTER" layoutX="21.0" layoutY="207.0" prefHeight="50.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0">
<children>
<RadioButton fx:id="radioButton" text="Male">
<HBox.margin>
<Insets right="3.0"/>
</HBox.margin>
</RadioButton>
<RadioButton fx:id="radioButton2" text="Female">
<HBox.margin>
<Insets right="30.0"/>
<Insets bottom="10.0"/>
</HBox.margin>
</RadioButton>
<Button minWidth="-Infinity" mnemonicParsing="false" onAction="#addContact" text="Add" />
</children>
</HBox>
</children>
</AnchorPane>
All is fine, but I need to combine the both Radio Buttons in the one group and I can not find a solution to how to implement something like ToggleGroup inmain.fxml.
spring javafx
add a comment |
Have MainController:
public class MainController {
@FXML private RadioButton radioButton;
@FXML private RadioButton radioButton2;
@FXML
public void addContact() {
boolean b = radioButton.isSelected();
boolean b2 = radioButton.isSelected();
}
And mxin.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="350.0" prefWidth="755.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.habrahabr.ui.MainController">
<children>
<TableView fx:id="table" editable="true" prefHeight="200.0" prefWidth="405.0" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnResizePolicy><TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /></columnResizePolicy>
</TableView>
<HBox alignment="CENTER" layoutX="21.0" layoutY="207.0" prefHeight="50.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0">
<children>
<RadioButton fx:id="radioButton" text="Male">
<HBox.margin>
<Insets right="3.0"/>
</HBox.margin>
</RadioButton>
<RadioButton fx:id="radioButton2" text="Female">
<HBox.margin>
<Insets right="30.0"/>
<Insets bottom="10.0"/>
</HBox.margin>
</RadioButton>
<Button minWidth="-Infinity" mnemonicParsing="false" onAction="#addContact" text="Add" />
</children>
</HBox>
</children>
</AnchorPane>
All is fine, but I need to combine the both Radio Buttons in the one group and I can not find a solution to how to implement something like ToggleGroup inmain.fxml.
spring javafx
Have MainController:
public class MainController {
@FXML private RadioButton radioButton;
@FXML private RadioButton radioButton2;
@FXML
public void addContact() {
boolean b = radioButton.isSelected();
boolean b2 = radioButton.isSelected();
}
And mxin.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="350.0" prefWidth="755.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.habrahabr.ui.MainController">
<children>
<TableView fx:id="table" editable="true" prefHeight="200.0" prefWidth="405.0" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnResizePolicy><TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /></columnResizePolicy>
</TableView>
<HBox alignment="CENTER" layoutX="21.0" layoutY="207.0" prefHeight="50.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0">
<children>
<RadioButton fx:id="radioButton" text="Male">
<HBox.margin>
<Insets right="3.0"/>
</HBox.margin>
</RadioButton>
<RadioButton fx:id="radioButton2" text="Female">
<HBox.margin>
<Insets right="30.0"/>
<Insets bottom="10.0"/>
</HBox.margin>
</RadioButton>
<Button minWidth="-Infinity" mnemonicParsing="false" onAction="#addContact" text="Add" />
</children>
</HBox>
</children>
</AnchorPane>
All is fine, but I need to combine the both Radio Buttons in the one group and I can not find a solution to how to implement something like ToggleGroup inmain.fxml.
spring javafx
spring javafx
asked Nov 25 '18 at 12:48
Valentyn HruzytskyiValentyn Hruzytskyi
338114
338114
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Not only Nodes but also ToggleGroups can be created in the fxml. Using <fx:reference> you can use an existing object:
<?import javafx.scene.control.ToggleGroup?>
...
<RadioButton fx:id="radioButton" text="Male">
<HBox.margin>
<Insets right="3.0"/>
</HBox.margin>
<toggleGroup>
<ToggleGroup fx:id="group"/>
</toggleGroup>
</RadioButton>
<RadioButton fx:id="radioButton2" text="Female">
<HBox.margin>
<Insets right="30.0"/>
<Insets bottom="10.0"/>
</HBox.margin>
<toggleGroup>
<fx:reference source="group"/>
</toggleGroup>
</RadioButton>
...
Alternatively use the initialize method of the controller for this purpose:
@FXML
private void initialize() {
ToggleGroup group = new ToggleGroup();
radioButton.setToggleGroup(group);
radioButton2.setToggleGroup(group);
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467588%2fhow-to-implement-togglegroup-in-fxml-file-using-spring-vs-javafx%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Not only Nodes but also ToggleGroups can be created in the fxml. Using <fx:reference> you can use an existing object:
<?import javafx.scene.control.ToggleGroup?>
...
<RadioButton fx:id="radioButton" text="Male">
<HBox.margin>
<Insets right="3.0"/>
</HBox.margin>
<toggleGroup>
<ToggleGroup fx:id="group"/>
</toggleGroup>
</RadioButton>
<RadioButton fx:id="radioButton2" text="Female">
<HBox.margin>
<Insets right="30.0"/>
<Insets bottom="10.0"/>
</HBox.margin>
<toggleGroup>
<fx:reference source="group"/>
</toggleGroup>
</RadioButton>
...
Alternatively use the initialize method of the controller for this purpose:
@FXML
private void initialize() {
ToggleGroup group = new ToggleGroup();
radioButton.setToggleGroup(group);
radioButton2.setToggleGroup(group);
}
add a comment |
Not only Nodes but also ToggleGroups can be created in the fxml. Using <fx:reference> you can use an existing object:
<?import javafx.scene.control.ToggleGroup?>
...
<RadioButton fx:id="radioButton" text="Male">
<HBox.margin>
<Insets right="3.0"/>
</HBox.margin>
<toggleGroup>
<ToggleGroup fx:id="group"/>
</toggleGroup>
</RadioButton>
<RadioButton fx:id="radioButton2" text="Female">
<HBox.margin>
<Insets right="30.0"/>
<Insets bottom="10.0"/>
</HBox.margin>
<toggleGroup>
<fx:reference source="group"/>
</toggleGroup>
</RadioButton>
...
Alternatively use the initialize method of the controller for this purpose:
@FXML
private void initialize() {
ToggleGroup group = new ToggleGroup();
radioButton.setToggleGroup(group);
radioButton2.setToggleGroup(group);
}
add a comment |
Not only Nodes but also ToggleGroups can be created in the fxml. Using <fx:reference> you can use an existing object:
<?import javafx.scene.control.ToggleGroup?>
...
<RadioButton fx:id="radioButton" text="Male">
<HBox.margin>
<Insets right="3.0"/>
</HBox.margin>
<toggleGroup>
<ToggleGroup fx:id="group"/>
</toggleGroup>
</RadioButton>
<RadioButton fx:id="radioButton2" text="Female">
<HBox.margin>
<Insets right="30.0"/>
<Insets bottom="10.0"/>
</HBox.margin>
<toggleGroup>
<fx:reference source="group"/>
</toggleGroup>
</RadioButton>
...
Alternatively use the initialize method of the controller for this purpose:
@FXML
private void initialize() {
ToggleGroup group = new ToggleGroup();
radioButton.setToggleGroup(group);
radioButton2.setToggleGroup(group);
}
Not only Nodes but also ToggleGroups can be created in the fxml. Using <fx:reference> you can use an existing object:
<?import javafx.scene.control.ToggleGroup?>
...
<RadioButton fx:id="radioButton" text="Male">
<HBox.margin>
<Insets right="3.0"/>
</HBox.margin>
<toggleGroup>
<ToggleGroup fx:id="group"/>
</toggleGroup>
</RadioButton>
<RadioButton fx:id="radioButton2" text="Female">
<HBox.margin>
<Insets right="30.0"/>
<Insets bottom="10.0"/>
</HBox.margin>
<toggleGroup>
<fx:reference source="group"/>
</toggleGroup>
</RadioButton>
...
Alternatively use the initialize method of the controller for this purpose:
@FXML
private void initialize() {
ToggleGroup group = new ToggleGroup();
radioButton.setToggleGroup(group);
radioButton2.setToggleGroup(group);
}
answered Nov 25 '18 at 13:13
fabianfabian
52.8k115373
52.8k115373
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467588%2fhow-to-implement-togglegroup-in-fxml-file-using-spring-vs-javafx%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown