javafx ComboBox Event and change cell color

public class EffectTest extends Application {
public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(Stage stage) {
    stage.setTitle("ComboBoxSample");
    Scene scene = new Scene(new Group(), 450, 250);

    ComboBox emailComboBox = new ComboBox();
    emailComboBox.getItems().addAll("A","B","C","D","E");

        emailComboBox.setPromptText("Email address");
    emailComboBox.setEditable(true);
    emailComboBox.valueProperty().addListener(new ChangeListener<String>() {
        @Override public void changed(ObservableValue ov, String t, String t1) {
          System.out.println(ov);
            System.out.println(t);
            System.out.println(t1);
        }
    });

    emailComboBox.setCellFactory(
        new Callback<ListView<String>, ListCell<String>>() {
            @Override public ListCell<String> call(ListView<String> param) {
                final ListCell<String> cell = new ListCell<String>() {
                    {
                        super.setPrefWidth(100);
                    }
                    @Override public void updateItem(String item,
                        boolean empty) {
                            super.updateItem(item, empty);
                            if (item != null) {
                                setText(item);
                                if (item.contains("A")) {
                                    setTextFill(Color.RED);
                                }
                                else if (item.contains("B")){
                                    setTextFill(Color.GREEN);
                                }
                                else {
                                    setTextFill(Color.BLACK);
                                }
                            }
                            else {
                                setText(null);
                            }
                        }
            };
            return cell;
        }

    });

    GridPane grid = new GridPane();
    grid.setVgap(4);
    grid.setHgap(10);
    grid.setPadding(new Insets(5, 5, 5, 5));
    grid.add(new Label("To: "), 0, 0);
    grid.add(emailComboBox, 1, 0);

    Group root = (Group) scene.getRoot();
    root.getChildren().add(grid);
    stage.setScene(scene);
    stage.show();

  }

}
时间: 2024-10-23 08:01:48

javafx ComboBox Event and change cell color的相关文章

change the color of a disabled TEdit?

Author: P. Below Category: VCL {Question:How can I change the color of a disabled (Edit1.Enabled := false;) control?I do not want the normal grey color. Answer:Two options: 1) place the control on a panel and disable the panel instead of the control.

Change column color for columnChart in extjs

var store = Ext.create('Ext.data.JsonStore', { fields: ['name', 'data'], data: [ { 'name': 'metric one',   'data':10 }, { 'name': 'metric two',   'data': 7 }, { 'name': 'metric three', 'data': 5 }, { 'name': 'metric four',  'data': 2 }, { 'name': 'me

Change the color of a link in an NSMutableAttributedString

Swift Updated for Swift 3 Use with a textView.linkTextAttributes = [NSForegroundColorAttributeName: UIColor.green] And in context: let attributedString = NSMutableAttributedString(string: "This is an example by @marcelofabri_") let linkRange = (

WPF中ComboBox用法

The ComboBox control is in many ways like the ListBox control, but takes up a lot less space, because the list of items is hidden when not needed. The ComboBox control is used many places in Windows, but to make sure that everyone knows how it looks

EventLog.EntryWritten Event

刚看到在MSND论坛上有人问一个EventLog.EntryWritten Event相关的问题,说是在2015触发了一个2013年的EventWritten的事件,比较好奇,然后查看了下这个类: https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.entrywritten%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 在的Remarks里看到有这么一段话: Th

FileSystemWatcher触发多次Change事件的解决办法

(转) 最近要用到FileSystemWatcher来监控某个目录中的文件是否发生改变,如果改变就执行相应的操作(具体操作如:打开文档,添加一行,保存).但在开发过程中,发现FileSystemWatcher在文件创建或修改后,会触发多个Created或Changed事件,具体原因就是处理文件的过程中执行了多次文件系统操作,触发了多次事件.具体可以参看微软的关于FileSystemWatcher这方面的解释:Troubleshooting FileSystemWatcher Components

HTML DOM Event 对象

var event;if (document.createEvent){event = document.createEvent("HTMLEvents");event.initEvent("change", true, false);document.getElementById("fname").dispatchEvent(event);} else {document.getElementById("fname").fi

html change 事件

The change event is fired for <input>, <select>, and <textarea> elements when a change to the element's value is committed by the user. Unlike the inputevent, the change event is not necessarily fired for each change to an element's valu

zepto源码学习-04 event

之前说完$(XXX),然后还有很多零零碎碎的东西需要去分析,结果一看代码,发现zepto的实现都相对简单,没有太多可分析的.直接略过了一些实现,直接研究Event模块,相比JQuery的事件系统,zepto的设计相对简单很多,看起来也就相对轻松,整个event模块也就300行代码. 先看事件的相关接口以及用法 $.Event $.Event(type, [properties]) ⇒ event 创建并初始化一个指定的DOM事件.如果给定properties对象,使用它来扩展出新的事件对象.默认