How to display various content in a TableColumn

Hello,
I would like to display in one column only the label of an object, and in the second column, based on the property of the object displayed in the first column, display a Text Field or a ChoiceBox.
Is it possible with Cell Factories? If not, what would you recommend to do that and keep the ability to add rows at a specific index with the ObservableList.

Sure it's possible. Just use the same property for both columns and set the custom cell factory on one of them.
Example:
import java.util.Arrays;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.util.Callback;
public class CustomTableCellExample extends Application {
  @Override
  public void start(Stage primaryStage) {
  TableView<Employee> table = new TableView<>();
  table.getItems().addAll(
     new Employee("Fred", "Human Resources"),
     new Employee("Jane", "Information Technology"),
     new Employee("Bob", "Management"),
     new Employee("Anne", "Management"),
     new Employee("Bill", "Finance")
  TableColumn<Employee, String> nameCol = new TableColumn<>("Name");
  nameCol.setCellValueFactory(new PropertyValueFactory<Employee, String>("name"));
  TableColumn<Employee, String> departmentLabelCol = new TableColumn<>("Department");
  departmentLabelCol.setCellValueFactory(new PropertyValueFactory<Employee, String>("department"));
  TableColumn<Employee, String> editDepartmentCol = new TableColumn<>("Edit Department");
  editDepartmentCol.setCellValueFactory(new PropertyValueFactory<Employee, String>("department"));
  editDepartmentCol.setCellFactory(new Callback<TableColumn<Employee,String>, TableCell<Employee,String>>() {
      @Override
      public TableCell<Employee, String> call(TableColumn<Employee, String> param) {
        return new DepartmentCell();
  editDepartmentCol.setEditable(true);
  table.setEditable(true);
  table.getColumns().addAll(Arrays.asList(nameCol, departmentLabelCol, editDepartmentCol));
  BorderPane root = new BorderPane();
  root.setCenter(table);
  primaryStage.setScene(new Scene(root, 300, 400));
  primaryStage.show();
  public static void main(String[] args) {
  launch(args);
  static class DepartmentCell extends TableCell<Employee, String> {
   private final ObservableList<String> knownDepartments = FXCollections.observableArrayList("Human Resources", "Information Technology", "Finance");
   private final ComboBox<String> comboBox = new ComboBox<>(knownDepartments);
   private final TextField textField = new TextField();
   DepartmentCell() {
     comboBox.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
          commitEdit(comboBox.getSelectionModel().getSelectedItem());
     textField.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
          commitEdit(textField.getText());
     textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> obs,
            Boolean oldValue, Boolean newValue) {
          if (! newValue) {
            commitEdit(textField.getText());
   @Override
   public void startEdit() {
     super.startEdit();
     if (! isEmpty() ) {
       setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
       setText(null);
       if (knownDepartments.contains(getItem())) {
         comboBox.getSelectionModel().select(getItem());
         setGraphic(comboBox);
       } else {
         textField.setText(getItem());
         setGraphic(textField);
   @Override
   public void commitEdit(String item) {
     super.commitEdit(item);
     setContentDisplay(ContentDisplay.TEXT_ONLY);
     setText(item);
     setGraphic(null);
   @Override
   public void cancelEdit() {
     super.cancelEdit();
     setContentDisplay(ContentDisplay.TEXT_ONLY);
     setText(getItem());
     setGraphic(null);
   @Override
   public void updateItem(String item, boolean empty) {
     super.updateItem(item, empty);
     if (empty) {
       setText(null);
       setGraphic(null);
     } else {
       if (isEditing()) {
         setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
         if (knownDepartments.contains(item)) {
           comboBox.getSelectionModel().select(item);
           setGraphic(comboBox);
         } else {
           textField.setText(item);
           setGraphic(textField);
       } else {
         setContentDisplay(ContentDisplay.TEXT_ONLY);
         setText(item);
  public static class Employee {
   private final StringProperty name ;
   private final StringProperty department ;
   public Employee(String name, String department) {
     this.name = new SimpleStringProperty(this, "name", name);
     this.department = new SimpleStringProperty(this, "department", department);
   public StringProperty nameProperty() {
     return name ;
   public final String getName() {
     return this.name.get();
   public final void setName(String name) {
     this.name.set(name);
   public StringProperty departmentProperty() {
     return department ;
   public final String getDepartment() {
     return this.department.get();
   public final void setDepartment(String department) {
     this.department.set(department);

Similar Messages

  • How to display the content of a region on a different page

    Hello,
    Does anyone knows how to display the content of a region on an other page. I try to make page that displays content that resides somewhere else in my portal, so I can give a summarization of some hot topics. I really want to display the whole content of some regions (not a display with custom search).
    Thanks a lot,
    Hans

    Set that page as portlet, include it in a region in another page and in the edit defaults decide which regions you want to display.
    Mere.

  • How to display the content of a BLOB column in a ADF/BC pages ?

    How to display the content of a BLOB column in a ADF/BC pages ?
    There is some image in database table blog column. And we want to display image on the screeen.
    There is some example about upload and dowload blog columns.
    (steve not yet document example page etc...)
    But We want to display blog picture in a image component...
    is there any basic way to do it ?
    Thanks a lot...

    Ali,
    You could just download the sample app... but... here is the servlet code from the demo (look at it just for technique - you'll obviously have to change it for your needs)...
    John
    package oracle.fodemo.storefront.servlet;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import oracle.jbo.ApplicationModule;
    import oracle.jbo.Key;
    import oracle.jbo.Row;
    import oracle.jbo.ViewObject;
    import oracle.jbo.client.Configuration;
    import oracle.jbo.domain.BlobDomain;
    import oracle.jbo.domain.DBSequence;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.ViewObjectImpl;
    public class ImageServlet
      extends HttpServlet
      private static final String CONTENT_TYPE =
        "image/jpg; charset=windows-1252";
      public void init(ServletConfig config)
        throws ServletException
        super.init(config);
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
        throws ServletException, IOException
        response.setContentType(CONTENT_TYPE);
        response.setContentType(CONTENT_TYPE);
        String detailProductId = request.getParameter("detail");
        String thumbnailProductId = request.getParameter("thumbnail");
        boolean thumbnail = true;
        String productId = null;
        OutputStream os = response.getOutputStream();
        String amDef = "oracle.fodemo.storefront.store.service.StoreServiceAM";
        String config = "StoreServiceAMLocal";
        ApplicationModule am =
          Configuration.createRootApplicationModule(amDef, config);
        ViewObjectImpl vo =
          (ViewObjectImpl) am.findViewObject("ProductImages"); // get view object (the same as used in the table)
        if (detailProductId != null)
          productId = detailProductId;
          thumbnail = false;
        else
          productId = thumbnailProductId;
        vo.defineNamedWhereClauseParam("paramThumbnail", null, null);
        vo.defineNamedWhereClauseParam("paramProductId", null, null);
        vo.setWhereClause("DEFAULT_VIEW_FLAG = :paramThumbnail AND PRODUCT_ID = :paramProductId");
        vo.setNamedWhereClauseParam("paramThumbnail", (thumbnail? "Y": "N"));
        vo.setNamedWhereClauseParam("paramProductId", productId);
        vo.executeQuery();
        Row product = vo.first();
        BlobDomain image = (BlobDomain) product.getAttribute("Image");
        InputStream is = image.getInputStream();
        // copy blob to output
        byte[] buffer = new byte[10 * 1024];
        int nread;
        while ((nread = is.read(buffer)) != -1)
          os.write(buffer, 0, nread);
        os.close();
        vo.setWhereClause(null);
        vo.removeNamedWhereClauseParam("paramProductId");
        vo.removeNamedWhereClauseParam("paramThumbnail");
        Configuration.releaseRootApplicationModule(am, false);
    }

  • How to display link content on the the same sharepoint page on click event

    "How to display link content on the the same sharepoint page on click event"
    Detail:
    we are using a document library where all html files are stored/uploaded.  we would like to display/open the html file on the same sharepoint page where all the files are listed.
    Thanks.

    Use jQuery and set the target to self to the anchor tag
    Regards,
    Sairam Avacorp Technologies

  • How to display the contents of the database values which are retrived.

    how to display the contents of the database values which are retrived in servlets and i am able to display the contents in the servlets and if forward to jsp using requestdespatcher,the values are to be shown in jsp one below the other.please suggest me in these........the servlet code is as shown
    while(rs.next()){
                        buffer.append(rs.getString(1));
                        buffer.append(rs.getString(2));
                        buffer.append(rs.getString(3));
                        buffer.append(rs.getString(4));
                        buffer.append(rs.getString(5));
                        buffer.append(rs.getString(6));
                        buffer.append(rs.getString(7));
                        buffer.append(rs.getString(8));
                        buffer.append(rs.getString(9));
                        buffer.append(rs.getString(10));
                        request.setAttribute("result1",buffer);
                        RequestDispatcher rq=request.getRequestDispatcher("/results.jsp");
                        rq.forward(request,response);
    in jsp iam using the getAttribute to retrieve the values as shown
    <% StringBuffer sb=(StringBuffer)request.getAttribute("result1"); %>
    <%= sb %>
    but getting the results in the stretch,i need to display the result one below the other.

    if you load it all into the buffer that is going to be very difficult. I would suggest loading it into some sort of collection. I like using an ArrayList.
    Then pass the arraylist.
    you will then on the jsp iterate through the arrayList using what every you want.. el, logic tags, scriplets.
    so something like
    ArrayList arrayList = new ArrayList();
    while(rs.next()){
    arrayList.append(rs.getString(1));
    //or possibly an arrayList of String arrays
    //maybe using nested for loops.  Inner for loop adds result to string[] then //outer adds string[] to arrayList.
    //can be done any number of ways based on your expected result set.

  • How to display the contents of java.util.list in a frame???

    i should use awt only not applet...
    i need to display the contents of java.util.list in a frame...
    the contents contains rows queried from a oracle database.....
    the contents should be displayed similar to how a lable is displayed..
    please help me out..
    thanks
    dinesh

    Of course there is something in AWT:
    http://java.sun.com/j2se/1.5.0/docs/api/java/awt/List.
    htmlagain, if you carefully read the question, he needs a
    table to display a JDBC result set. There is no
    pre-made table component in AWT.Well, I read that he filled the data into a java.util.List and now wants to display this list. So a List-component should be sufficient. But I might be wrong...
    -Puce

  • How to display the contents of an array list to a listview?

    Hi. How do I display the contents of an arraylist to a listview?
    Here is my current code:
    var c: Control= new Control();
    var simpleList: ArrayList = c.ListResult; //ListResult is an ArrayList containing strings
    var simpleListView : ListView = ListView {
            translateX: 0
            translateY: 0
            layoutX: 20
            layoutY: 80
            height: 130
            width: 200
            items: bind simpleList;
    Stage {
        title: "Trial app"
        width: 240
        height: 320
        style: StageStyle.TRANSPARENT
        scene: Scene {
            content: [ simpleListView
    } [http://img341.imageshack.us/img341/133/listview.jpg]
    My code generates the result in this screenshot above. It shows that all the contents on the arraylist is displayed in one row/item.
    It should be displayed as (see bottom image) ...
    [http://img707.imageshack.us/img707/3745/listview1.jpg]
    Do you guys have any idea on this? Thank you very much for your replies

    For your listbox data to bind the listbox requires a Sequence. This is something that you can sort out at the entrypoint of your code.
    In the example below I have used an ArrayList to simmulate the data you have entering your FX code, but then I put that list into a Sequence, in your case instead of having an ArrayList in your FX code, you simple supply the list on entry, as I have marked in the following code.
    * Main.fx
    * Created on 12-Feb-2010, 10:24:46
    package uselists;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.text.Text;
    import javafx.scene.text.Font;
    import java.util.ArrayList;
    import javafx.scene.control.ListView;
    import javafx.animation.Timeline;
    import javafx.animation.KeyFrame;
    * @author robert
    //Simmulate your data with an ArrayList
    var simpleList: ArrayList = new ArrayList;
    simpleList.add("Hello");
    simpleList.add("World");
    // *** This is what your entry point would become, just load the simpleList.toArray() into your sequence ***
    var simpleSequence = [];
    simpleSequence = simpleList.toArray();
    //after some time add some items, to show that our binding is working
    Timeline {
        repeatCount: 1
        keyFrames: [
            KeyFrame {
                time: 5s
                canSkip: true
                action: function () {
                    //you can work on the Sequence to add or remove
                    insert "Another item" into simpleSequence;
                    //if you at some point want to have your array reflect the changes
                    //then perform your changes on that too
                    simpleList.add("Another item");
                    //remember depending on your app
                    //you may keep the update of simpleList
                    //until you are finished with this view and do it in a single update
            KeyFrame {
                time: 10s
                action: function () {
                    //Alternatly, to keep your ArrayList correct at all times
                    //add items to it and then update your Sequence
                    simpleList.add("Added to array");
                    simpleSequence = simpleList.toArray();
    }.play();
    Stage {
        title: "Application title"
        scene: Scene {
            width: 250
            height: 80
            content: [
                ListView {
                    items: bind simpleSequence
    }You can bind to a function rather than the data, which I am sure would be needed some cases, for example if the listBox data was a named part of a hash value for example, all that is required is that your function returns a sequence.

  • How to display the content of a file in the portal?

    Hey guys, could anyone help?
    I just created a page which includes two iView, one is KM Navigation iView to display a certain repository, while the other is for displaying the content of a certain file I click in the navigation iView.
    And now the problem is when I click a file in the KM Navigation iView, it will pop up a new window to display it. How can I make it displayed in a fixed iView, which type of this iView should be?

    Hi,
    you can try to use the:
    <b>ConsumerTreeListPreview</b>
    layout for KM navigation ivew (or customize to your own).
    This layout shows a folder tree on the left, a document list on the right. When you click on a document from the list it shows the contents of the file on the bottom of the iview.
    Hope this helps,
    Romano

  • How to display the contents of a document set on a page?

    I want to display the contents of a document set (that contains both folders and files) on a page (with the same structure as they are in the document set like folders and files). How to achieve this?
    I tried content search webpart but it is of no use as it displays the flat list instead I need folders and files as they are present in the document set
    I tried document set contents webpart but as it doesn't accept any connection, it is not of much use.
    I will be glad if you have any pointers for me in this regard.
    Regards
    Kesava

    Hi Kesava,
    According to your description, you might want to display the content in a document set with its hierarchy.
    How about using
    Page Viewer Web Part to display the page of the corresponding document set? This would be a non-code solution I would recommend.
    More information about Page Viewer Web Part:
    https://support.office.com/en-nz/article/Page-Viewer-Web-Part-e364436c-0ec4-4819-acac-1982b3525531
    Thanks
    Patrick Liang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support,
    contact [email protected]
    Patrick Liang
    TechNet Community Support

  • How to Display the content of Excel file into Webdynpro Table

    Hi Experts
    I am following the Blog to upload a file in to the webdynpro context,but my problem is after uploading a excel file i need to extract the content from that Excel file and that content should be displayed in the webdynpro table.Can any body please guide me how to read the content from excel and to Display in the Table.
    Thanks and Regards
    Kalyan

    HI,
    Take for example, if Excel file contains 4 fields,
    Add jxl.jar to JavaBuild path and Use this snippet
    File f=new File("sample.xls");
    Workbook w=Workbook.getWorkbook(f);
    Sheet sh=w.getSheet(0);
    int cols=sh.getColumns();
    int rows=sh.getRows();
    Cell c=null;
    String s1=null;
    String s2=null;
    String s3=null;
    String s4=null;
    ArrayList al=new ArrayList();
    int j=0;
    for(int i=1;i<rows;i++)
    ITableElement table=wdContext.createTableElementz
         s1=sh.getCell(0,i).getContents();
         s2=sh.getCell(1,i).getContents();
         s3=sh.getCell(2,i).getContents();
         s4=sh.getCell(3,i).getContents();
                             table.setName(s1);
         table.setAddress(s2);
         table.setDesignation(s3);
         table.setDummy(s4);
         al.add(j,table);
         j++;                    
    wdContext.nodeTable().bind(al);
    Regards
    LakshmiNarayana

  • How to display file content in browser using servlet..? urgent!!!

    hello,
    i am building a application for which when a user logs in he will we redirected to page where he will have one link ,with this link a file is associated.
    when user press that link he should be able to see that particular file in internet browser....
    now can anybody give me a code sample of how to display a file in browser....
    please reply me as soon as possible...

    thanks for your reply....
    but i don't want this....
    i want to read a file from disk into stream or buffer and from that again reading and printing in browser.....
    a servlet should be built for this....
    i wrote this but its not working
    ========================================================
    public class FilePrinting extends HttpServlet
         public void doPost(HttpServletRequest req,HttpServletResponse res)
              throws IOException,ServletException
              ServletOutputStream out=res.getOutputStream();
              res.setContentType("text/html");
              String fileURL="/mydomainWebApp/Test.htm";
              res.setHeader("Content-disposition","attachment; filename=" +="Test.htm" );
              BufferedInputStream bis=null;
              BufferedOutputStream bos=null;
              try
                   URL url = new URL( fileURL );
                   bis=new BufferedInputStream(url.openStream());
                   bos = new BufferedOutputStream(out);
                   byte[] buff = new byte[2048];
                   int bytesRead;
                   // Simple read/write loop.
                   while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                   bos.write(buff, 0, bytesRead);
              }catch(final MalformedURLException e)
                   System.out.println ( "MalformedURLException." );
                   throw e;
              }catch(final IOException e)
                   System.out.println ( "IOException." );
                   throw e;
              }finally
                   if (bis != null)
                        bis.close();
                   if (bos != null)
                        bos.close();
    =======================================================================
    please send me sample code if anyone have../...

  • How to display html content with image in Adobe Flash and Flex mobile project?

    Hi,
      I have a html content with image in it. How to display it in Adobe Flash Builder and Flex mobile project? Which control needs to be used for this?

    Hello,
    The only current way is to use an iFrame, or if you only need some html tags you could use the Text Layout Framework.
    Here this is the iFrame approach:
    http://code.google.com/p/flex-iframe/
    If the swc do not work in Flex4 just use its ource code which works...
    ...it is basically based on this:
    http://www.deitte.com/archives/2008/07/dont_use_iframe.htm
    see also and vote, please:
    http://bugs.adobe.com/jira/browse/SDK-12291
    http://bugs.adobe.com/jira/browse/SDK-13740
    Regards
    Marc

  • How to display Flash Content uploaded in Admin Console

    HI All ,
    I have created a flash content in the admin console.Flash file is uploaded to a binary property.
    I have to display that flash file in the JSP.
    Normally , a Image can be displayed in the JSP , with following tag,
    *<img src="<%=request.getContextPath() + "/ShowProperty" + node.getPath()+"//Brochure-Image"%>" />*
    But how to display a flash content uploaded in the admin console.
    Pls suggest me in this regard,
    Srinivas

    There is no wlp tag to display flash image. You have to use HTML object tag for this. Just google it and you will find lot of answer how to include flash file in your JSP.
    Either you pass a path to your repository or save the file somewhere on you local drive and use that path.
    <object width="968" height="209" id="mymoviename">
                        <param name="movie" value="../flash/abcd.swf"/>
                        <param name="quality" value="high"/>
                        <embed src="../flash/abcd.swf" quality="high"
                        pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"
                        type="application/x-shockwave-flash" width="774" height="204"></embed>
    </object>

  • How to display topic content in non-RH window?

    Morning all,
    I'm working with my developers to find the best answer to this: How can we display topic content in a non-RH window.
    Currently, I'm running RH 8.0.2 and generating WebHelp. We want to keep all content in RH, and for one part of our web service, we want to display topic content, but not a window generated by RH. In fact, we really just need the data to appear in something simple like a table cell. We don't want to hard code the content as it's likely to change.
    I'm guessing since the folks on this forum have done everything w/ RH short of alchemy, someone out there has already done something like this.
    So far, we're looking at opening the .htm file and pulling everything inside the body tags, then displaying that in whatever structure the developers decide is best. Kinda crude.
    Questions that come up:
    How do we match the content to the page it's displayed on since we're not using any of the RH structure around the content?
    Is there a slick way to do this with the CSH API and MapIDs?
    Since we're just using the content, the title tag is unused for these topics. Is there a way we could leverage this tag to help track the topic or the page it will display on?
    As always, any enlightenment is welcome.
    Patrick

    Peter,
    Thanks, but not really. I had read through that topic a while back.
    It looks like we really need to display the content (probably everything between the body tags?) in an HTML element like a <td>. We could do frames, but for a small help window, they really eat up a lot of space and definitely don't fit in with the style of the site.
    I think the display of the content will be left in the developer's hands - that's what they get paid for.
    If you have any thoughts on how to reference the content, I'd love to hear them. I can't see MapIDs working as we're not using the CSH API. Though I suppose our developers could hack the .js file and determine how RH uses the MapIDs and recreate that. But that's a lot of work.
    Referencing the topic by the name of the .htm file locks us into that file name and makes future changes a little more difficult.
    The only thing I've come up with so far is to put a code in place of the <title> tag since the title won't be displayed. That way we could change the content w/out the developers having to recode. Crude, I know.
    Regards,
    Patrick

  • How to display smartboard content onto a ipad?

    Hi,
    I want to display content on the smartboard onto an ipad, so that a student can view the smartboard content in front of them.
    I know that you can use air play to display ipad content onto a smartboard, but how do we show smartboard content on to ipad?
    Any help would be much appreciated.
    Sam

    Hi,
    I want to display content on the smartboard onto an ipad, so that a student can view the smartboard content in front of them.
    I know that you can use air play to display ipad content onto a smartboard, but how do we show smartboard content on to ipad?
    Any help would be much appreciated.
    Sam

Maybe you are looking for