modules/controls/src/main/java/javafx/scene/control/ComboBox.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   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 javafx.scene.control;
  27 

  28 import javafx.beans.InvalidationListener;
  29 import javafx.beans.Observable;
  30 import javafx.beans.WeakInvalidationListener;
  31 import javafx.collections.WeakListChangeListener;
  32 import com.sun.javafx.scene.control.skin.ComboBoxListViewSkin;
  33 import javafx.beans.property.*;
  34 import javafx.beans.value.ChangeListener;
  35 import javafx.beans.value.ObservableValue;
  36 import javafx.beans.value.WeakChangeListener;
  37 import javafx.collections.FXCollections;
  38 import javafx.collections.ListChangeListener;
  39 import javafx.collections.ObservableList;
  40 import javafx.scene.AccessibleAttribute;
  41 import javafx.scene.AccessibleRole;
  42 import javafx.scene.Node;
  43 import javafx.util.Callback;
  44 import javafx.util.StringConverter;
  45 
  46 import java.lang.ref.WeakReference;
  47 
  48 /**
  49  * An implementation of the {@link ComboBoxBase} abstract class for the most common
  50  * form of ComboBox, where a popup list is shown to users providing them with
  51  * a choice that they may select from. For more information around the general
  52  * concepts and API of ComboBox, refer to the {@link ComboBoxBase} class 
  53  * documentation.
  54  * 
  55  * <p>On top of ComboBoxBase, the ComboBox class introduces additional API. Most
  56  * importantly, it adds an {@link #itemsProperty() items} property that works in


 361     private IntegerProperty visibleRowCount
 362             = new SimpleIntegerProperty(this, "visibleRowCount", 10);
 363     public final void setVisibleRowCount(int value) { visibleRowCount.set(value); }
 364     public final int getVisibleRowCount() { return visibleRowCount.get(); }
 365     public final IntegerProperty visibleRowCountProperty() { return visibleRowCount; }
 366     
 367     
 368     // --- Editor
 369     private TextField textField;
 370     /**
 371      * The editor for the ComboBox. The editor is null if the ComboBox is not
 372      * {@link #editableProperty() editable}.
 373      * @since JavaFX 2.2
 374      */
 375     private ReadOnlyObjectWrapper<TextField> editor;
 376     public final TextField getEditor() { 
 377         return editorProperty().get(); 
 378     }
 379     public final ReadOnlyObjectProperty<TextField> editorProperty() { 
 380         if (editor == null) {
 381             editor = new ReadOnlyObjectWrapper<TextField>(this, "editor");
 382             textField = new ComboBoxListViewSkin.FakeFocusTextField();
 383             editor.set(textField);
 384         }
 385         return editor.getReadOnlyProperty(); 
 386     }
 387 
 388     
 389     // --- Placeholder Node
 390     private ObjectProperty<Node> placeholder;
 391     /**
 392      * This Node is shown to the user when the ComboBox has no content to show.
 393      * The placeholder node is shown in the ComboBox popup area
 394      * when the items list is null or empty.
 395      * @since JavaFX 8.0
 396      */
 397     public final ObjectProperty<Node> placeholderProperty() {
 398         if (placeholder == null) {
 399             placeholder = new SimpleObjectProperty<Node>(this, "placeholder");
 400         }
 401         return placeholder;
 402     }




   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 javafx.scene.control;
  27 
  28 import com.sun.javafx.scene.control.FakeFocusTextField;
  29 import javafx.beans.InvalidationListener;
  30 import javafx.beans.Observable;
  31 import javafx.beans.WeakInvalidationListener;
  32 import javafx.collections.WeakListChangeListener;
  33 import javafx.scene.control.skin.ComboBoxListViewSkin;
  34 import javafx.beans.property.*;
  35 import javafx.beans.value.ChangeListener;
  36 import javafx.beans.value.ObservableValue;

  37 import javafx.collections.FXCollections;
  38 import javafx.collections.ListChangeListener;
  39 import javafx.collections.ObservableList;
  40 import javafx.scene.AccessibleAttribute;
  41 import javafx.scene.AccessibleRole;
  42 import javafx.scene.Node;
  43 import javafx.util.Callback;
  44 import javafx.util.StringConverter;
  45 
  46 import java.lang.ref.WeakReference;
  47 
  48 /**
  49  * An implementation of the {@link ComboBoxBase} abstract class for the most common
  50  * form of ComboBox, where a popup list is shown to users providing them with
  51  * a choice that they may select from. For more information around the general
  52  * concepts and API of ComboBox, refer to the {@link ComboBoxBase} class 
  53  * documentation.
  54  * 
  55  * <p>On top of ComboBoxBase, the ComboBox class introduces additional API. Most
  56  * importantly, it adds an {@link #itemsProperty() items} property that works in


 361     private IntegerProperty visibleRowCount
 362             = new SimpleIntegerProperty(this, "visibleRowCount", 10);
 363     public final void setVisibleRowCount(int value) { visibleRowCount.set(value); }
 364     public final int getVisibleRowCount() { return visibleRowCount.get(); }
 365     public final IntegerProperty visibleRowCountProperty() { return visibleRowCount; }
 366     
 367     
 368     // --- Editor
 369     private TextField textField;
 370     /**
 371      * The editor for the ComboBox. The editor is null if the ComboBox is not
 372      * {@link #editableProperty() editable}.
 373      * @since JavaFX 2.2
 374      */
 375     private ReadOnlyObjectWrapper<TextField> editor;
 376     public final TextField getEditor() { 
 377         return editorProperty().get(); 
 378     }
 379     public final ReadOnlyObjectProperty<TextField> editorProperty() { 
 380         if (editor == null) {
 381             editor = new ReadOnlyObjectWrapper<>(this, "editor");
 382             textField = new FakeFocusTextField();
 383             editor.set(textField);
 384         }
 385         return editor.getReadOnlyProperty(); 
 386     }
 387 
 388     
 389     // --- Placeholder Node
 390     private ObjectProperty<Node> placeholder;
 391     /**
 392      * This Node is shown to the user when the ComboBox has no content to show.
 393      * The placeholder node is shown in the ComboBox popup area
 394      * when the items list is null or empty.
 395      * @since JavaFX 8.0
 396      */
 397     public final ObjectProperty<Node> placeholderProperty() {
 398         if (placeholder == null) {
 399             placeholder = new SimpleObjectProperty<Node>(this, "placeholder");
 400         }
 401         return placeholder;
 402     }