JavaFX - How to make ComboBox hgrow?
I have a problem with JavaFX(8), HBox, ComboBox and HGrow.
HGrow does not work in combination with ComboBox.
(INFO: with TextField (instead of ComboBox), it works as expected!)
This is my FXML-Code:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox prefHeight="117.0" prefWidth="285.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.test.TestController">
<children>
<HBox prefHeight="105.0" prefWidth="196.0" VBox.vgrow="ALWAYS">
<children>
<ComboBox fx:id="fxCboTest" prefHeight="25.0" prefWidth="62.0" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</children>
</VBox>
this Code will result in:
i also tried following code (without success, this code does nothing):
HBox.setHgrow(uiController.fxCboTest, Priority.ALWAYS);
Does anyone has an idea how to make an ComboBox HGrow?
combobox javafx javafx-8
add a comment |
I have a problem with JavaFX(8), HBox, ComboBox and HGrow.
HGrow does not work in combination with ComboBox.
(INFO: with TextField (instead of ComboBox), it works as expected!)
This is my FXML-Code:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox prefHeight="117.0" prefWidth="285.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.test.TestController">
<children>
<HBox prefHeight="105.0" prefWidth="196.0" VBox.vgrow="ALWAYS">
<children>
<ComboBox fx:id="fxCboTest" prefHeight="25.0" prefWidth="62.0" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</children>
</VBox>
this Code will result in:
i also tried following code (without success, this code does nothing):
HBox.setHgrow(uiController.fxCboTest, Priority.ALWAYS);
Does anyone has an idea how to make an ComboBox HGrow?
combobox javafx javafx-8
add a comment |
I have a problem with JavaFX(8), HBox, ComboBox and HGrow.
HGrow does not work in combination with ComboBox.
(INFO: with TextField (instead of ComboBox), it works as expected!)
This is my FXML-Code:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox prefHeight="117.0" prefWidth="285.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.test.TestController">
<children>
<HBox prefHeight="105.0" prefWidth="196.0" VBox.vgrow="ALWAYS">
<children>
<ComboBox fx:id="fxCboTest" prefHeight="25.0" prefWidth="62.0" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</children>
</VBox>
this Code will result in:
i also tried following code (without success, this code does nothing):
HBox.setHgrow(uiController.fxCboTest, Priority.ALWAYS);
Does anyone has an idea how to make an ComboBox HGrow?
combobox javafx javafx-8
I have a problem with JavaFX(8), HBox, ComboBox and HGrow.
HGrow does not work in combination with ComboBox.
(INFO: with TextField (instead of ComboBox), it works as expected!)
This is my FXML-Code:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox prefHeight="117.0" prefWidth="285.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.test.TestController">
<children>
<HBox prefHeight="105.0" prefWidth="196.0" VBox.vgrow="ALWAYS">
<children>
<ComboBox fx:id="fxCboTest" prefHeight="25.0" prefWidth="62.0" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</children>
</VBox>
this Code will result in:
i also tried following code (without success, this code does nothing):
HBox.setHgrow(uiController.fxCboTest, Priority.ALWAYS);
Does anyone has an idea how to make an ComboBox HGrow?
combobox javafx javafx-8
combobox javafx javafx-8
asked Apr 7 '15 at 10:55
BenBen
2,2971438
2,2971438
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
This is an answer to my own question.
After some testing, I found out that when setting Max Width to MAX_VALUE, it works:
This will result in following code/xml from SceneBuilder:
...
<children>
<ComboBox maxWidth="1.7976931348623157E308" prefWidth="150.0" HBox.hgrow="ALWAYS" />
</children>
...
where 1.7976931348623157E308 looks like Double.MAX_VALUE.
This will also work with multiple controls in Hbox.
In my opinion, this is not very consequently/consistently.
I still don't unserstand why HGrow does not work for ComboBox.
hgrow
will not override a resizable node's maximum width, which is set to the preferred size by default. There's a little information on this in the tutorial and also an excellent presentation at Parleys (registration required).
– James_D
Apr 7 '15 at 13:00
1
So, why does it work when just replacing ComboBox with TextField in XML?
– Ben
Apr 7 '15 at 13:07
4
Dug a little further into the default settings. ThemaxWidth
defaults for both to the sentinel valueRegion.COMPUTED_SIZE
, which causes a call tocomputeMaxWidth(...)
. For controls, this in turn delegates to the skin implementation. Digging into the source code,ComboBoxBaseSkin
resolves this by returning the preferred width; theTextFieldSkin
just inherits the defaultSkinBase
implementation, which returnsDouble.MAX_VALUE
. Hence a combo box by default is limited to its preferred size; a text field is allowed to grow indefinitely. The bottom line is they have different defaults.
– James_D
Apr 8 '15 at 2:15
add a comment |
This is a hack, but it should work. Inside the controller's intialize method, define a binding.
@Override
public void initialize(URL location, ResourceBundle resources) {
fxCboTest.prefWidthProperty().bind(hbox.widthProperty());
}
Thanks for your suggestion, but this code may not work properly when (not in my code example, cause i want keep my example as simple as possible) the hbox contains multiple controls, like ComboBox and Button. i want to avoid too much calculating by myself.
– Ben
Apr 7 '15 at 11:45
The question never mentioned that you wanted multiple children in the HBox.
– ItachiUchiha
Apr 7 '15 at 12:47
You are right, this is why i add an comment to your answer why your solution may not work with multiple controls. i didn't said that your solution is absolute unhelpful.
– Ben
Apr 7 '15 at 13:01
add a comment |
I had the same problem, but I'm not using Scene Builder
.
So my fix, based on Ben's answer, is in the code below:
ComboBox comboBox = new ComboBox(...);
...
comboBox.setMaxWidth(Double.MAX_VALUE);
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%2f29489880%2fjavafx-how-to-make-combobox-hgrow%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is an answer to my own question.
After some testing, I found out that when setting Max Width to MAX_VALUE, it works:
This will result in following code/xml from SceneBuilder:
...
<children>
<ComboBox maxWidth="1.7976931348623157E308" prefWidth="150.0" HBox.hgrow="ALWAYS" />
</children>
...
where 1.7976931348623157E308 looks like Double.MAX_VALUE.
This will also work with multiple controls in Hbox.
In my opinion, this is not very consequently/consistently.
I still don't unserstand why HGrow does not work for ComboBox.
hgrow
will not override a resizable node's maximum width, which is set to the preferred size by default. There's a little information on this in the tutorial and also an excellent presentation at Parleys (registration required).
– James_D
Apr 7 '15 at 13:00
1
So, why does it work when just replacing ComboBox with TextField in XML?
– Ben
Apr 7 '15 at 13:07
4
Dug a little further into the default settings. ThemaxWidth
defaults for both to the sentinel valueRegion.COMPUTED_SIZE
, which causes a call tocomputeMaxWidth(...)
. For controls, this in turn delegates to the skin implementation. Digging into the source code,ComboBoxBaseSkin
resolves this by returning the preferred width; theTextFieldSkin
just inherits the defaultSkinBase
implementation, which returnsDouble.MAX_VALUE
. Hence a combo box by default is limited to its preferred size; a text field is allowed to grow indefinitely. The bottom line is they have different defaults.
– James_D
Apr 8 '15 at 2:15
add a comment |
This is an answer to my own question.
After some testing, I found out that when setting Max Width to MAX_VALUE, it works:
This will result in following code/xml from SceneBuilder:
...
<children>
<ComboBox maxWidth="1.7976931348623157E308" prefWidth="150.0" HBox.hgrow="ALWAYS" />
</children>
...
where 1.7976931348623157E308 looks like Double.MAX_VALUE.
This will also work with multiple controls in Hbox.
In my opinion, this is not very consequently/consistently.
I still don't unserstand why HGrow does not work for ComboBox.
hgrow
will not override a resizable node's maximum width, which is set to the preferred size by default. There's a little information on this in the tutorial and also an excellent presentation at Parleys (registration required).
– James_D
Apr 7 '15 at 13:00
1
So, why does it work when just replacing ComboBox with TextField in XML?
– Ben
Apr 7 '15 at 13:07
4
Dug a little further into the default settings. ThemaxWidth
defaults for both to the sentinel valueRegion.COMPUTED_SIZE
, which causes a call tocomputeMaxWidth(...)
. For controls, this in turn delegates to the skin implementation. Digging into the source code,ComboBoxBaseSkin
resolves this by returning the preferred width; theTextFieldSkin
just inherits the defaultSkinBase
implementation, which returnsDouble.MAX_VALUE
. Hence a combo box by default is limited to its preferred size; a text field is allowed to grow indefinitely. The bottom line is they have different defaults.
– James_D
Apr 8 '15 at 2:15
add a comment |
This is an answer to my own question.
After some testing, I found out that when setting Max Width to MAX_VALUE, it works:
This will result in following code/xml from SceneBuilder:
...
<children>
<ComboBox maxWidth="1.7976931348623157E308" prefWidth="150.0" HBox.hgrow="ALWAYS" />
</children>
...
where 1.7976931348623157E308 looks like Double.MAX_VALUE.
This will also work with multiple controls in Hbox.
In my opinion, this is not very consequently/consistently.
I still don't unserstand why HGrow does not work for ComboBox.
This is an answer to my own question.
After some testing, I found out that when setting Max Width to MAX_VALUE, it works:
This will result in following code/xml from SceneBuilder:
...
<children>
<ComboBox maxWidth="1.7976931348623157E308" prefWidth="150.0" HBox.hgrow="ALWAYS" />
</children>
...
where 1.7976931348623157E308 looks like Double.MAX_VALUE.
This will also work with multiple controls in Hbox.
In my opinion, this is not very consequently/consistently.
I still don't unserstand why HGrow does not work for ComboBox.
edited Oct 2 '16 at 10:44
answered Apr 7 '15 at 12:04
BenBen
2,2971438
2,2971438
hgrow
will not override a resizable node's maximum width, which is set to the preferred size by default. There's a little information on this in the tutorial and also an excellent presentation at Parleys (registration required).
– James_D
Apr 7 '15 at 13:00
1
So, why does it work when just replacing ComboBox with TextField in XML?
– Ben
Apr 7 '15 at 13:07
4
Dug a little further into the default settings. ThemaxWidth
defaults for both to the sentinel valueRegion.COMPUTED_SIZE
, which causes a call tocomputeMaxWidth(...)
. For controls, this in turn delegates to the skin implementation. Digging into the source code,ComboBoxBaseSkin
resolves this by returning the preferred width; theTextFieldSkin
just inherits the defaultSkinBase
implementation, which returnsDouble.MAX_VALUE
. Hence a combo box by default is limited to its preferred size; a text field is allowed to grow indefinitely. The bottom line is they have different defaults.
– James_D
Apr 8 '15 at 2:15
add a comment |
hgrow
will not override a resizable node's maximum width, which is set to the preferred size by default. There's a little information on this in the tutorial and also an excellent presentation at Parleys (registration required).
– James_D
Apr 7 '15 at 13:00
1
So, why does it work when just replacing ComboBox with TextField in XML?
– Ben
Apr 7 '15 at 13:07
4
Dug a little further into the default settings. ThemaxWidth
defaults for both to the sentinel valueRegion.COMPUTED_SIZE
, which causes a call tocomputeMaxWidth(...)
. For controls, this in turn delegates to the skin implementation. Digging into the source code,ComboBoxBaseSkin
resolves this by returning the preferred width; theTextFieldSkin
just inherits the defaultSkinBase
implementation, which returnsDouble.MAX_VALUE
. Hence a combo box by default is limited to its preferred size; a text field is allowed to grow indefinitely. The bottom line is they have different defaults.
– James_D
Apr 8 '15 at 2:15
hgrow
will not override a resizable node's maximum width, which is set to the preferred size by default. There's a little information on this in the tutorial and also an excellent presentation at Parleys (registration required).– James_D
Apr 7 '15 at 13:00
hgrow
will not override a resizable node's maximum width, which is set to the preferred size by default. There's a little information on this in the tutorial and also an excellent presentation at Parleys (registration required).– James_D
Apr 7 '15 at 13:00
1
1
So, why does it work when just replacing ComboBox with TextField in XML?
– Ben
Apr 7 '15 at 13:07
So, why does it work when just replacing ComboBox with TextField in XML?
– Ben
Apr 7 '15 at 13:07
4
4
Dug a little further into the default settings. The
maxWidth
defaults for both to the sentinel value Region.COMPUTED_SIZE
, which causes a call to computeMaxWidth(...)
. For controls, this in turn delegates to the skin implementation. Digging into the source code, ComboBoxBaseSkin
resolves this by returning the preferred width; the TextFieldSkin
just inherits the default SkinBase
implementation, which returns Double.MAX_VALUE
. Hence a combo box by default is limited to its preferred size; a text field is allowed to grow indefinitely. The bottom line is they have different defaults.– James_D
Apr 8 '15 at 2:15
Dug a little further into the default settings. The
maxWidth
defaults for both to the sentinel value Region.COMPUTED_SIZE
, which causes a call to computeMaxWidth(...)
. For controls, this in turn delegates to the skin implementation. Digging into the source code, ComboBoxBaseSkin
resolves this by returning the preferred width; the TextFieldSkin
just inherits the default SkinBase
implementation, which returns Double.MAX_VALUE
. Hence a combo box by default is limited to its preferred size; a text field is allowed to grow indefinitely. The bottom line is they have different defaults.– James_D
Apr 8 '15 at 2:15
add a comment |
This is a hack, but it should work. Inside the controller's intialize method, define a binding.
@Override
public void initialize(URL location, ResourceBundle resources) {
fxCboTest.prefWidthProperty().bind(hbox.widthProperty());
}
Thanks for your suggestion, but this code may not work properly when (not in my code example, cause i want keep my example as simple as possible) the hbox contains multiple controls, like ComboBox and Button. i want to avoid too much calculating by myself.
– Ben
Apr 7 '15 at 11:45
The question never mentioned that you wanted multiple children in the HBox.
– ItachiUchiha
Apr 7 '15 at 12:47
You are right, this is why i add an comment to your answer why your solution may not work with multiple controls. i didn't said that your solution is absolute unhelpful.
– Ben
Apr 7 '15 at 13:01
add a comment |
This is a hack, but it should work. Inside the controller's intialize method, define a binding.
@Override
public void initialize(URL location, ResourceBundle resources) {
fxCboTest.prefWidthProperty().bind(hbox.widthProperty());
}
Thanks for your suggestion, but this code may not work properly when (not in my code example, cause i want keep my example as simple as possible) the hbox contains multiple controls, like ComboBox and Button. i want to avoid too much calculating by myself.
– Ben
Apr 7 '15 at 11:45
The question never mentioned that you wanted multiple children in the HBox.
– ItachiUchiha
Apr 7 '15 at 12:47
You are right, this is why i add an comment to your answer why your solution may not work with multiple controls. i didn't said that your solution is absolute unhelpful.
– Ben
Apr 7 '15 at 13:01
add a comment |
This is a hack, but it should work. Inside the controller's intialize method, define a binding.
@Override
public void initialize(URL location, ResourceBundle resources) {
fxCboTest.prefWidthProperty().bind(hbox.widthProperty());
}
This is a hack, but it should work. Inside the controller's intialize method, define a binding.
@Override
public void initialize(URL location, ResourceBundle resources) {
fxCboTest.prefWidthProperty().bind(hbox.widthProperty());
}
answered Apr 7 '15 at 11:15
ItachiUchihaItachiUchiha
27.6k677136
27.6k677136
Thanks for your suggestion, but this code may not work properly when (not in my code example, cause i want keep my example as simple as possible) the hbox contains multiple controls, like ComboBox and Button. i want to avoid too much calculating by myself.
– Ben
Apr 7 '15 at 11:45
The question never mentioned that you wanted multiple children in the HBox.
– ItachiUchiha
Apr 7 '15 at 12:47
You are right, this is why i add an comment to your answer why your solution may not work with multiple controls. i didn't said that your solution is absolute unhelpful.
– Ben
Apr 7 '15 at 13:01
add a comment |
Thanks for your suggestion, but this code may not work properly when (not in my code example, cause i want keep my example as simple as possible) the hbox contains multiple controls, like ComboBox and Button. i want to avoid too much calculating by myself.
– Ben
Apr 7 '15 at 11:45
The question never mentioned that you wanted multiple children in the HBox.
– ItachiUchiha
Apr 7 '15 at 12:47
You are right, this is why i add an comment to your answer why your solution may not work with multiple controls. i didn't said that your solution is absolute unhelpful.
– Ben
Apr 7 '15 at 13:01
Thanks for your suggestion, but this code may not work properly when (not in my code example, cause i want keep my example as simple as possible) the hbox contains multiple controls, like ComboBox and Button. i want to avoid too much calculating by myself.
– Ben
Apr 7 '15 at 11:45
Thanks for your suggestion, but this code may not work properly when (not in my code example, cause i want keep my example as simple as possible) the hbox contains multiple controls, like ComboBox and Button. i want to avoid too much calculating by myself.
– Ben
Apr 7 '15 at 11:45
The question never mentioned that you wanted multiple children in the HBox.
– ItachiUchiha
Apr 7 '15 at 12:47
The question never mentioned that you wanted multiple children in the HBox.
– ItachiUchiha
Apr 7 '15 at 12:47
You are right, this is why i add an comment to your answer why your solution may not work with multiple controls. i didn't said that your solution is absolute unhelpful.
– Ben
Apr 7 '15 at 13:01
You are right, this is why i add an comment to your answer why your solution may not work with multiple controls. i didn't said that your solution is absolute unhelpful.
– Ben
Apr 7 '15 at 13:01
add a comment |
I had the same problem, but I'm not using Scene Builder
.
So my fix, based on Ben's answer, is in the code below:
ComboBox comboBox = new ComboBox(...);
...
comboBox.setMaxWidth(Double.MAX_VALUE);
add a comment |
I had the same problem, but I'm not using Scene Builder
.
So my fix, based on Ben's answer, is in the code below:
ComboBox comboBox = new ComboBox(...);
...
comboBox.setMaxWidth(Double.MAX_VALUE);
add a comment |
I had the same problem, but I'm not using Scene Builder
.
So my fix, based on Ben's answer, is in the code below:
ComboBox comboBox = new ComboBox(...);
...
comboBox.setMaxWidth(Double.MAX_VALUE);
I had the same problem, but I'm not using Scene Builder
.
So my fix, based on Ben's answer, is in the code below:
ComboBox comboBox = new ComboBox(...);
...
comboBox.setMaxWidth(Double.MAX_VALUE);
edited Nov 27 '18 at 1:58
סטנלי גרונן
1,75682244
1,75682244
answered Nov 26 '18 at 20:29
pinkston00pinkston00
737
737
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%2f29489880%2fjavafx-how-to-make-combobox-hgrow%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