1 /*
   2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package hello;
  27 
  28 import javafx.application.Application;
  29 import javafx.geometry.Insets;
  30 import javafx.scene.Group;
  31 import javafx.scene.Scene;
  32 import javafx.scene.control.Button;
  33 import javafx.scene.control.Label;
  34 import javafx.scene.control.ScrollPane;
  35 import javafx.scene.control.TextField;
  36 import javafx.scene.control.TitledPane;
  37 import javafx.scene.image.Image;
  38 import javafx.scene.image.ImageView;
  39 import javafx.scene.layout.GridPane;
  40 import javafx.scene.layout.HBox;
  41 import javafx.scene.layout.StackPane;
  42 import javafx.scene.layout.VBox;
  43 import javafx.scene.paint.Color;
  44 import javafx.scene.text.Font;
  45 import javafx.stage.Stage;
  46 
  47 public class HelloTitledPane extends Application {
  48     
  49     public static void main(String[] args) {
  50         Application.launch(args);
  51     }
  52 
  53     @Override public void start(Stage stage) {
  54         stage.setTitle("TitledPane");
  55 
  56         // --- Simple grid test
  57         TitledPane gridTitlePane = new TitledPane();
  58         GridPane grid = new GridPane();
  59         grid.setVgap(4);
  60         grid.setPadding(new Insets(5, 5, 5, 5));
  61         grid.add(new Label("First Name: "), 0, 0);
  62         grid.add(new TextField(), 1, 0);
  63         grid.add(new Label("Last Name: "), 0, 1);
  64         grid.add(new TextField(), 1, 1);
  65         grid.add(new Label("Email: "), 0, 2);
  66         grid.add(new TextField(), 1, 2);
  67         gridTitlePane.setText("Hello World!");
  68         gridTitlePane.setContent(grid);
  69 
  70         // --- Label test
  71         TitledPane normalText = new TitledPane();
  72         Label lbl = new Label("This is a collapsible TitledPane\nthat allows for text to be wrapped.\n\nIt should be the perfect height to fit all text provided.\n\nIs it?");
  73         normalText.setText("Hello World!");
  74         normalText.setFont(Font.font(20));
  75         normalText.setContent(lbl);
  76 
  77         // --- Big button test
  78         TitledPane normal = new TitledPane();
  79         Button bn = new Button("Button");
  80         bn.setPrefSize(75, 50);
  81         StackPane pane = new StackPane(bn);
  82         pane.setPadding(new Insets(5));
  83         normal.setText("Hello World!");
  84         normal.setFont(Font.font(5));
  85         normal.setContent(pane);
  86 
  87         TitledPane unanimated = new TitledPane();
  88         unanimated.setAnimated(false);
  89         unanimated.setText("Not Animated");
  90         Button bs = new Button("Button");
  91         bs.setPrefSize(75, 50);
  92         unanimated.setContent(bs);
  93 
  94         TitledPane uncollapsible = new TitledPane();
  95         uncollapsible.setCollapsible(false);
  96         uncollapsible.setText("Not Collapsible");
  97         Button bf = new Button("Button");
  98         bf.setPrefSize(75, 50);
  99         uncollapsible.setContent(bf);
 100 
 101         // -- Content is a ScrollPane
 102         Image image = new Image("hello/duke.jpg", 200f, 200f, true, true, false);
 103         ImageView imageView = new ImageView();
 104         imageView.setImage(image);
 105 
 106         ScrollPane scrollPane = new ScrollPane(imageView);
 107         scrollPane.setPannable(true);
 108 
 109         TitledPane scrollableImage = new TitledPane();
 110         scrollableImage.setPrefHeight(100);
 111         scrollableImage.setText("ScrollPane content");
 112         scrollableImage.setContent(scrollPane);
 113 
 114         VBox hbox = new VBox(10);
 115         hbox.setPadding(new Insets(20, 0, 0, 20));
 116         hbox.getChildren().setAll(normal, gridTitlePane, normalText, unanimated, uncollapsible, scrollableImage);
 117 
 118         Scene scene = new Scene(hbox);
 119         scene.setFill(Color.GHOSTWHITE);
 120         stage.setScene(scene);
 121         stage.show();
 122     }
 123 }