Home > JavaFX > Data Binding to ListView

Data Binding to ListView

14 February 2010 Leave a comment Go to comments

ScreenShot

import javafx.scene.control.ListView;
import javafx.scene.control.TextBox;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;

/**
 * @author Pizaini
*/

// My Codes
public class ListViewer{
    var listview: ListView;
    var textInput: TextBox;
    var scene: Scene;
    var label: Label;
    init {
        label = Label{
               layoutX:10
               layoutY:10
               text:"Sparated with Comma"
               textFill: Color.BLUE
         }
         textInput = TextBox{
               layoutX:10
               layoutY:30
               width:380
               height:25
         }
         listview = ListView{
               width:150
               height:220
               layoutX:10
               layoutY:70
               items: bind textInput.text.split(",");
         }
         scene = Scene{
               width:400
               height:300
               content: [
                   textInput, listview, label
               ]
         }
    }
    //function
     public function getScene(): Scene{
        return scene;
     }
}

MainProgram.fx

import javafx.stage.Stage;

/**
 * @author Pizaini
 */

// My Codes
var listViwer = ListViewer{};
var stage: Stage;

stage = Stage{
    title:"List View"
    scene: listViwer.getScene()
}

Download Complate SorceCode

Ketik pada TexBox dan dipisahkan dengan coma(,). Lalu tekan Enter, maka item pada ListView akan mengambil data dari TexBox

  1. deni
    26 May 2011 at 22:49

    nice posting.. mas.
    Yang aku tanyakan gimana kalau dibalik list view yang ditampilkan d teksbox ??
    Merimakasih sebelumnya🙂

    • Zhein
      27 May 2011 at 08:53

      Berarti kita meletakkan aksi pada saat mengklik list view nya…ambil text sesuai dengan list yang diklik dan letakkan pada text box…semoga membantu..

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: