Last active
August 29, 2015 13:57
-
-
Save abhinayagarwal/9415872 to your computer and use it in GitHub Desktop.
Focus Property of TextField
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a small example doing what you want ! I have used the `focus property` of `textfield` to add and remove miles from it ! | |
import javafx.application.Application; | |
import javafx.beans.value.ChangeListener; | |
import javafx.beans.value.ObservableValue; | |
import javafx.scene.Scene; | |
import javafx.scene.control.TextField; | |
import javafx.scene.layout.VBox; | |
import javafx.stage.Stage; | |
public class TextBinding extends Application { | |
@Override | |
public void start(Stage primaryStage) { | |
final TextField user = new TextField(); | |
TextField demo = new TextField(); | |
user.setStyle("-fx-background-color: transparent;-fx-border-color:blue;"); | |
user.focusedProperty().addListener(new ChangeListener<Boolean>() | |
{ | |
@Override | |
public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue) | |
{ | |
if (newPropertyValue) | |
{ | |
user.setText(user.getText().replace(" miles", "")); | |
} | |
else | |
{ | |
user.setText(user.getText().concat(" miles")); | |
} | |
} | |
}); | |
VBox root = new VBox(); | |
root.getChildren().addAll(user,demo); | |
Scene scene = new Scene(root, 300, 250); | |
primaryStage.setTitle("transparent text test"); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} | |
public static void main(String args[]) { | |
launch(args); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With reference to
http://stackoverflow.com/questions/22253497/permanent-text-in-a-textfield-in-java