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

Button placed in TitledPane expands to fill the Pane

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: fx2.0
    • Fix Version/s: fx2.1
    • Component/s: javafx
    • Labels:
    • Environment:

      JavaFX 2.0GA JDK7u2b8

      Description

      Place a button in a TitledPane and it will fill the control.

      Amy's comment on RT-17226 says "Buttons have a default max size clamped to their preferred size, which is why the buttons don't expand to fill the tiles by default. " However, in this case, the button does expand without unclamping the max size of the button.

      As a workaround, you can put the button inside a StackPane inside the TitledPane and it won't resize itself.

      Example attached.

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TitledPane;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class TitledPaneWidthTest extends Application {
        public static void main(String[] args) {
          Application.launch(args);
        }

        @Override
        public void start(Stage primaryStage) {
          primaryStage.setTitle("Titled Pane Width Test");

          final Button b1 = new Button("Hit Me B1");
          final TitledPane p1 = new TitledPane("Button should be skinnier", b1);

          final StackPane stackPane = new StackPane();
          final Button b2 = new Button("Hit Me B2");
          stackPane.getChildren().add(b2);
          final TitledPane p2 = new TitledPane("Button in StackPane so ok", stackPane);

          // display the scene.
          final VBox root = new VBox();
          root.setSpacing(10);
          root.getChildren().addAll(p1, p2);
          Scene scene = new Scene(root, 500, 300);
          primaryStage.setScene(scene);
          primaryStage.show();
        }
      }

        Attachments

          Activity

            People

            Assignee:
            kwwong Kinsley Wong
            Reporter:
            josmithjfx John Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: