implementation de a barre de recherche

This commit is contained in:
SeekDaSky 2017-12-12 13:59:53 +01:00
parent 30b1298c9d
commit b3496dc181
1 changed files with 31 additions and 0 deletions

View File

@ -13,10 +13,16 @@ import Classes.css.user.SubMenuStyleSheet;
import Interfaces.Event;
import Interfaces.EventObserver;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.FlowPane;
@ -143,6 +149,31 @@ public class RootLayout extends Application implements EventObserver {
if(NewsListModel.getInstance().getNews().size() != 0) {
this.articles.clearContent();
TextField tx = new TextField();
tx.setPromptText("search...");
tx.setId("mag_searchbar");
tx.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent arg0) {
if(arg0.getCode() == KeyCode.ENTER) {
NewsListModel.getInstance().query(tx.textProperty().get());
}
}
});
Platform.runLater(new Runnable() {
@Override
public void run() {
RootLayout.this.main_container.getChildren().add(tx);
}
});
// For each news
for( NewsModel news : NewsListModel.getInstance().getNews() ){