Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8120539

button returns incorrect sizes


    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: fx2.0
    • Fix Version/s: None
    • Component/s: javafx
    • Environment:

      WXP SP3, JFX b38


      Someone pointed me to a layout issue with MigLayoutFX2, and after some examination it seems that JavaFX is at fault. The problem seems to be that Buttons do not return correct prefWidth and maxWidth values. In MigLayoutFX2 I query min, pref and max width for layout. If I setup an example using a button, I get these values:

      Button@df8f5e[styleClass=button] getMinimumWidth 10
      Button@df8f5e[styleClass=button] getPreferredWidth 38
      Button@df8f5e[styleClass=button] getMaximumWidth 38
      Button@df8f5e[styleClass=button] setBound x=7,y=67 / w=38,h=17 / resizable=true

      MigLayoutFX2 uses exactly the values it got from the node for setBound. Strange is that maxwidth it got back is the same as preferred width. Also it turns out that prefWidth is just a few pixels too small; the last 2 letters of the text are not shown, but "..." instead.

      If I replace the button with a TextBox then I get these values:

      TextBox@15b9e68[styleClass=text-box] getMinimumWidth 9
      TextBox@15b9e68[styleClass=text-box] getPreferredWidth 73
      TextBox@15b9e68[styleClass=text-box] getMaximumWidth 2147483647
      TextBox@15b9e68[styleClass=text-box] setBound x=7,y=66 / w=286,h=18 / resizable=true

      These values make sense. The w=286 is because a "grow horizontally" is active.

      This is the relevant code in MigLayoutFX2, no strange stuff there:

              public int getMinimumWidth(int height) {
                  int v = (int)node.minWidth(height);
                  System.out.println(getComponent() + " getMinimumWidth " + v);
                  return v;

              public int getPreferredWidth(int height) {
                  int v = (int)node.prefWidth(height);
                  System.out.println(getComponent() + " getPreferredWidth " + v);
                  return v;

              public int getMaximumWidth(int height) {
                  int v = (int)node.maxWidth(height);
                  System.out.println(getComponent() + " getMaximumWidth " + v);
                  return v;

      I have the same Button problem with CheckBox, but not with ChoiceBox. So it seems button related.

      I tried reproducing this using GridPane; it layouts correctly, but all buttons return -1.0 for their sizes.





            • Assignee:
              tbee Tom Eugelink
            • Votes:
              3 Vote for this issue
              6 Start watching this issue


              • Created: