Skip to content

Commit 382c6b9

Browse files
authored
Updated setPlaceholder( Node, Pos ) (#1036)
1 parent 586404c commit 382c6b9

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Collections;
99
import java.util.List;
1010
import java.util.Locale;
11+
import java.util.Objects;
1112
import java.util.Optional;
1213
import java.util.function.BiConsumer;
1314
import java.util.function.BiFunction;
@@ -392,11 +393,11 @@ public Node getParagraphGraphic( int parNdx ) {
392393
* <br>To customize the placeholder's layout override {@link #configurePlaceholder( Node )}
393394
*/
394395
public final void setPlaceholder(Node value) { setPlaceholder(value,Pos.CENTER); }
395-
public final void setPlaceholder(Node value, Pos where) { placeHolderProp.set(value); placeHolderPos = where; }
396+
public void setPlaceholder(Node value, Pos where) { placeHolderProp.set(value); placeHolderPos = Objects.requireNonNull(where); }
396397
private ObjectProperty<Node> placeHolderProp = new SimpleObjectProperty<>(this, "placeHolder", null);
397398
public final ObjectProperty<Node> placeholderProperty() { return placeHolderProp; }
398399
public final Node getPlaceholder() { return placeHolderProp.get(); }
399-
private Pos placeHolderPos;
400+
private Pos placeHolderPos = Pos.CENTER;
400401

401402
private ObjectProperty<ContextMenu> contextMenu = new SimpleObjectProperty<>(null);
402403
@Override public final ObjectProperty<ContextMenu> contextMenuObjectProperty() { return contextMenu; }
@@ -929,7 +930,7 @@ private void displayPlaceHolder( boolean show, Node newNode )
929930
*/
930931
protected void configurePlaceholder( Node placeholder )
931932
{
932-
positionPlaceholder = true;
933+
positionPlaceholder = true;
933934
}
934935

935936
/* ********************************************************************** *
@@ -1691,10 +1692,10 @@ protected void layoutChildren() {
16911692
});
16921693

16931694
Node holder = placeholder;
1694-
if (holder != null && holder.isResizable() && holder.isManaged()) {
1695-
holder.autosize();
1696-
if ( positionPlaceholder ) Region.positionInArea
1697-
(
1695+
if (holder != null && holder.isManaged()) {
1696+
if (holder.isResizable()) holder.autosize();
1697+
if (positionPlaceholder) Region.positionInArea
1698+
(
16981699
holder, getLayoutX(), getLayoutY(), getWidth(), getHeight(), getBaselineOffset(),
16991700
ins, placeHolderPos.getHpos(), placeHolderPos.getVpos(), isSnapToPixel()
17001701
);

richtextfx/src/main/java/org/fxmisc/richtext/StyledTextField.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javafx.css.StyleableObjectProperty;
2020
import javafx.event.ActionEvent;
2121
import javafx.event.EventHandler;
22+
import javafx.geometry.Pos;
2223
import javafx.scene.AccessibleRole;
2324
import javafx.scene.Group;
2425
import javafx.scene.Node;
@@ -213,9 +214,11 @@ public String getName() {
213214
* <p>The Text will be aligned according to the text fields alignment setting and have a default
214215
* text fill of GRAY unless you have changed it by any means, e.g. with CSS "-fx-prompt-text-fill"
215216
*/
217+
public final void setPromptText( Text value ) { placeholderProperty().set( value ); }
216218
public final ObjectProperty<? super Text> promptTextProperty() { return placeholderProperty(); }
217219
public final Text getPromptText() { return getPlaceholder() instanceof Text ? (Text) getPlaceholder() : null; }
218-
public final void setPromptText( Text value ) { setPlaceholder( value ); }
220+
/** setPlaceholder is not supported by StyledTextField, use setPromptText instead */
221+
@Override public void setPlaceholder( Node value, Pos where ) { throw new UnsupportedOperationException("Use setPromptText instead"); }
219222
@Override protected void configurePlaceholder( Node placeholder )
220223
{
221224
placeholder.layoutYProperty().bind( Bindings.createDoubleBinding( () ->

0 commit comments

Comments
 (0)