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

GridPane layout affected by Accordion (SSCCE provided)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 7u6
    • javafx
    • Windows 7, JVM 1.7.013-b20 64 bit, public JDK/JavaFX

    Description

      (Full description with images on http://stackoverflow.com/questions/16472589/layout-gridpanel-borderpanel-button-accordion)
      Here is two snapshots of a SSCCE written to show a strange behavior of layout with or without accordion as a cell into a GridPane, the code to reproduce these behaviors and finally the questions I ask.

      Good rendering, as expected, the "center" content of the BorderPane is a Label:
      ![Bad layout of the button][1]
      http://i.stack.imgur.com/rtox4.png

      Bad layout of the button, the "center" content of the BorderPane is an Accordion:

      ![Bad layout of the button][2]
      http://i.stack.imgur.com/WxsXo.png

      The code:

          import javafx.application.Application;
          import javafx.geometry.HPos;
          import javafx.scene.Scene;
          import javafx.scene.control.Accordion;
          import javafx.scene.control.Button;
          import javafx.scene.control.Label;
          import javafx.scene.control.TextField;
          import javafx.scene.control.TitledPane;
          import javafx.scene.layout.BorderPane;
          import javafx.scene.layout.GridPane;
          import javafx.scene.layout.Priority;
          import javafx.stage.Stage;
          
          public class SSCCE extends Application {
          
             public static final boolean TOO_BIG_BUTTON = true;
          // public static final boolean TOO_BIG_BUTTON = false;
          
             public static void main( String[] args ) {
                launch( args );
             }
          
             @SuppressWarnings("nls")
             @Override
             public void start( Stage stage ) {
                TextField tf = new TextField( "textfield" );
                BorderPane bp = new BorderPane();
                Label lv = new Label( "BorderPane - Center - Center - Center - Center - Center" );
                lv.setPrefHeight( 96.0 );
                if( TOO_BIG_BUTTON ) {
                   Accordion acc = new Accordion();
                   TitledPane tp = new TitledPane( "Titled pane", lv );
                   acc.getPanes().add( tp );
                   acc.setExpandedPane( tp );
                   stage.setTitle( "SSCCE - too large button" );
                   bp.setCenter( acc );
                }
                else {
                   stage.setTitle( "SSCCE - as expected" );
                   bp.setCenter( lv );
                }
                GridPane gp = new GridPane();
                Label lbl = new Label( "Label: " );
                Button btn = new Button( "button" );
                btn.setMaxWidth( Double.MAX_VALUE );
                gp.add( lbl, 0, 1 );
                gp.add( tf , 1, 1 );
                gp.add( btn, 2, 1 );
                gp.add( bp , 0, 2, 3, 1 );
                GridPane.setHgrow( tf , Priority.ALWAYS );
                GridPane.setHgrow( btn, Priority.NEVER );
                GridPane.setHalignment( btn, HPos.RIGHT );
                stage.setScene( new Scene( gp ));
                stage.centerOnScreen();
                stage.show();
             }
          }

      The questions:

      - Why?
      - How can I help the layout manager to compute the right size of the button?

        [1]: http://i.stack.imgur.com/rtox4.png
        [2]: http://i.stack.imgur.com/WxsXo.png

      Attachments

        Activity

          People

            msladecek Martin Sládeček
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: