How to display the content in a TableColumn

Hello

I want to display in a 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 this possible with Cell Factories? If this is not the case, what would you recommend to do that and keep the possibility to add lines on a specific index with the ObservableList.

It is of course possible. Just use the same property for two columns and carried out of the plant cell 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 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 nameCol = new TableColumn<>("Name");
  nameCol.setCellValueFactory(new PropertyValueFactory("name"));

  TableColumn departmentLabelCol = new TableColumn<>("Department");
  departmentLabelCol.setCellValueFactory(new PropertyValueFactory("department"));

  TableColumn editDepartmentCol = new TableColumn<>("Edit Department");
  editDepartmentCol.setCellValueFactory(new PropertyValueFactory("department"));
  editDepartmentCol.setCellFactory(new Callback, TableCell>() {
      @Override
      public TableCell call(TableColumn 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 {
   private final ObservableList knownDepartments = FXCollections.observableArrayList("Human Resources", "Information Technology", "Finance");
   private final ComboBox comboBox = new ComboBox<>(knownDepartments);
   private final TextField textField = new TextField();
   DepartmentCell() {
     comboBox.setOnAction(new EventHandler() {
        @Override
        public void handle(ActionEvent event) {
          commitEdit(comboBox.getSelectionModel().getSelectedItem());
        }
     });
     textField.setOnAction(new EventHandler() {
        @Override
        public void handle(ActionEvent event) {
          commitEdit(textField.getText());
        }
     });
     textField.focusedProperty().addListener(new ChangeListener() {
        @Override
        public void changed(ObservableValue 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);
   }
  }
}

Tags: Java

Similar Questions

  • CS6: How to display the contents of the image when moving/resizing

    CS6 Indesign, Windows 7 64 bit

    Hi all

    I am a tech IT tries to help one of my users, so I'm not proficient in Indesign by any means. That being said, I was wondering if there is a way to display the content of a picture by dragging or resizing the image?

    Thanks, Shaun

    Edit/Preferences/Interface/Live screen drawing/immediate is or to drag click, hold for a moment, and then drag.

  • How to display the content of the message in the preview pane? He went with the last update.

    Before the last updating Thunderbird. I was able to see the content of the message in its entirety in the preview or show the pane at the bottom of the page. Now, I have to select an option to display the classic view tab. How to return to the original display option?

    Try restarting with disabled addons. I think remember me someone having an old adds on the cause.

    You can do this in the Help Menu.

  • How can I adjust the settings of Firefox to display the content in a format widescreen?

    How can I adjust the settings of Firefox to display the content in a format widescreen?

    You mean zoom? If so, check the module NoSquint .

  • How to see the content of what's currently on my iCloud of this site

    How to see the content of what's currently on my iCloud.  I would like to see these files presented in a display of file manager type in order to sort and remove if necessary.

    Go to iCloud.com, then click on your iCloud drive icon.  I hope this is what you mean or what you are looking for.

    iCloud Drive FAQ - Apple Support

  • How to replace the contents of the settings/passwords backup server / current browser bookmarks?

    Classic scenario: after the bookmark long manual organization Firefox Sync adds trash of its server to my laptop or tablet.

    Where can I find how to replace the content of the backup of the server by settings/passwords / current browser bookmarks? Stupid me, I put a new synchronization and lost this ability.

    It is not recommended to go back to the old version of Sync

    The old version is removed he'll stop being available soon, it takes getting used to using the new version.

    IIRC, it is actually possible to force synchronization of the old working with Fx29 & Fx30 using an old profile or preferences of piracy, but I don't think I should encourage users to try this, but it would be better than using an older version of Firefox which is really bad. In fact using an old outdated version of Firefox is so bad, that it is customary to recommend using a browser on alternative day of someone else instead.

    Firefox ESR is aimed at corporate users, definitely, at the moment, it will use the synchronization of the former. Who will update soon to use synchronization well again, and this time, I guess the synchronization of the former will probably totally frowned upon for example are not available at all.

    It is possible to use the feedback system to leave a short comment on Sync. I would recommend this making, but at least to make very many people of spirit comments that I doubt will have no effect.

  • . CBV file type displays the content rather that give download options

    I just changed my Web site hosting provider; old and new providers of Linux services.
    My site is scottishcca.co.uk - a site of chess by correspondence - and I use Win7 and 26.0 Firefox.
    There is a page (members/downloads) where members can download files of games of chess and e-magazines - the page is password protected using htaccess/htpasswd which works well.
    Each e-magazine has 4 download links: pdf, zip and pgn all work fine, but cbv does not - it just displays the contents of the file in the browser page. What needs to happen is that the browser should display a dialog box asking if the file should be opened with ChessBase 11 database software (which is associated with the type of file .cbv on my computer - I checked my default program settings). File .pgn type is also associated with the ChessBase 11 database software and working properly - the dialog box allows me to open or save.
    All the links work correctly when I use Google Chrome.
    I'm puzzled - advice please!
    Iain

    I think I have a solution for this. I went back to my new hosting provider (easyspace) and received this response:
    'Hi Iain,

    I did some research on this for you and have a suggestion for you to try.
    It is possible that Firefox is not to recognize the MIME Type application/cbv, because it is not just a registered IANA MIME Type.
    You could try instead of application/octet-stream, which is a generic MIME Type for non-text files.
    This idea came to me while reading the page at https://developer.mozilla.org/en/docs/Properly_Configuring_Server_MIME_Types and this document can give you more of an idea of why this does not work in Firefox.
    Can you try this please and let me know how you go.
    Best regards
    Gerry Munn
    Support services
    I implemented the suggestion of Gerry via .htaccess in my root directory and everything works now (after clearing the cache of Firefox). Maybe you could send Gerry an certificate of ability!

  • How to restore the contents of the folder workstation in the default format in Windows XP?

    Dear Sir or Madam:

    I have a desktop of Microsoft Windows XP Home Edition Version 2002 Service Pack 3.

    Contents of the my computer folder is not in the correct format, I want whatever it is corrupt.

    How to restore the contents of the folder workstation to the original format?

    The first JPEG image is the content of the folder post current work that has the corrupted display format.

    The second JPEG image is the content of the folder post original work that is in the correct format.

    Please reply back soon.

    Thank you.

    Looks like you saw. Rearrange icons by | Name. Try to organize by Type and other options while keeping rearrange icons by | Show in groups were also checked.
     
  • CD\DVD player does not display the contents of the data DVD.

    CD\DVD player does not display the contents of the data DVD, but will display the content of the data CD.  What is happening on more than one PC, and it began when Active Directory GPOS have been applied for the PC.  If untying policies the problem persists.  What happens on DVD ROM and DVD RAM drives.  Scanning software has been added to these machines, think it might be an ASPI crush.  All these machines are XP SP3 running McAfee.  When you insert a DVD with data on this topic, the name of the drive in windows password DVD RAM drive to CD drive, and if you try and browse the DVD it displays as a blank CD.  I changed something on the PC with the policy but cannot understand what he.  Other identical PC can view the contents of the DVD very well, but they never had the same strategies.  Any ideas, thank you.

    Hi PDoneen,

    The restore of the system; restore the computer to the before date when policies have been launched on one of the affected computer.

    You can check the link for the steps below: how to restore Windows XP to a previous state:http://support.microsoft.com/kb/306084

    Post back with the results.

    With regard to:

    Samhrutha G S - Microsoft technical support.

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • In Windows 7, how to display window contents while dragging?

    In Windows 7, how to display window contents while dragging?

    It is correct. With so many required customizations, no two machines are identical :)

    I give you another way for steps 1 and 2. I hope this helps.

    1. Press Windows Key + R.
    2. In the run window, type systempropertiesadvanced, and then click OK.
    3. In the performance section, click settings.
    4. In the box, check Show contents of window while dragging, and click OK.

    Homepage: http://www.baxiabhishek.info | Blog of Windows 7: http://windows7blog.info

  • HTML Help Home button - how to change the content

    I use Robohelp 11 and we post our content as microsoft HTML help.  I wonder how to change the content of the button the top of the page next to the front buttons and back at home.  Since it's HTML Help I can't use a skin to change the buttons, but I need to change what is displayed when you click the home button.  I can't find how to change when the button links to.  I just want to link to our home page.

    Thank you!

    Matthew

    Hello

    On luck outside, that you are not really wanting to address the 'skin in a CHM' quite yet, try this.

    First, note the path and the name of the file that you want to appear when the user clicks on the Home link.

    Open the pod of setting up a project. (View > pods > project configuration)

    Expand Windows, and then double-click the CHM window. (If you do not see a CHM window, you will need to create a)

    In the Properties window, click the Advanced Properties button.

    And from the Advanced Properties dialog box, you type (Yes, you heard that right, TYPE) the path and the name of the file you want. (Remember this first step?) Note that you can also type a URL pointing to a website here.

    Hope this helps... Rick

  • Error message "To display the contents of the Flash technology in this PDF file, please install this version of Flash Player that supports Adobe Reader and Acrobat".

    I converted MS-Outlook 2010 e-mail folder (and emails) into a PDF portfolio. When I have Adobe Reader X R-clicked, selected, I got and error message "To display the contents of the Flash technology in this PDF file, please install this version of Flash Player that supports Adobe Reader and Acrobat". I get the same msg when I try to open it with Acrobat. He worked the week last in Adobe Reader. I have the latest version of Flash Player installed. The portfolio opens when I click on < more >, but the Index is missing and I can't get to the first email. PC platform. Anyone else having this problem? If so, how to fix?

    You are running Internet Explorer by chance? If so, the Flash Player you have is NOT in need of Adobe Reader and Acrobat. If there is a link in the message, use that, rather than assuming that you already have Flash Player. If this does not work, let us know.

  • Adobe Muse: Why I can not get my page to scroll vertically to display the content of the page in the browser preview?

    Adobe Muse: Why I can not get my page to scroll vertically to display the content of the page in the browser preview?

    I am a novice and I do not talk about the web, so please excuse my ignorance!

    I content on my web pages in Muse design that descends below the visible window, but when I go to preview in browser, it only presents a preview which is visible in my window. Of course, I can press command + /, but I should be able to use my mouse wheel or my scroll bar to see the lowest content. I just can't understand how do! Is this something to do with the positions of Master Page header footer? They all look fine and normal and all the other sites I've done. In ADDITION, I checked non paged area (Mount table), and there is NO hidden content.

    I tried to move my content down (to 'wrong' it to enable vertical scrolling). I tried to move my foot higher than the content, but all useless page.

    Preview in browser = will just not scroll down.

    Hope it's a simple solution. Thanks in advance.

    See you soon,.

    I had the same problem and it took me almost 2 days to find a solution.

    See if that solves your problem (if all goes well it has been resolved since you posted).

    1. in the model Master, click on Page > Page Properties > metadata

    2. remove the small piece of code next to the body tag-{overflow-y: hidden}

    3. click on OK, then get an overview of your pages.

  • How to display the parameter string registered by DBMS_XMLINDEX?

    This is probably a stupid question, but I can't seem to find any function to display the setting of a parameter string that was recorded by DBMX_XMLINDEX. REGISTERPARAMETER.

    For example,.

    If I have:
    BEGIN
    DBMX_XMLINDEX.REGISTERPARAMETER('indexParam', 'xxxxxxxx');
    END;
    /
    How to display the value of 'indexParam' after creation?
    SQL> set long 1000
    SQL>
    SQL> select paramstr
      2  from xdb.xdb$xidx_param_t
      3  where param_name = 'MYINDEXPARAM'
      4  ;
    
    PARAMSTR
    --------------------------------------------------------------------------------
    PATH TABLE po_ptab
        PATH ID INDEX po_pidx
        ORDER KEY INDEX po_oidx
        VALUE INDEX po_vidx
        PATHS(NAMESPACE MAPPING(xmlns:p="http://www.example.com/IPO"))
        GROUP MASTERGROUP XMLTABLE PO_TAB
        ('/p:PurchaseOrder'
            COLUMNS
               REFERENCE VARCHAR2(30) PATH 'p:Reference',
               REQUESTOR VARCHAR2(30) PATH 'p:Requestor' )
        GROUP ITEMGROUP XMLTABLE ITEMGROUP_TAB
        ('/p:PurchaseOrder/p:LineItems/p:LineItem'
            COLUMNS
               LINENUMBER NUMBER(38) PATH '@p:ItemNumber',
               QUANTITY NUMBER(38) PATH '@p:Quantity',
               DESCRIPTION VARCHAR2(256) PATH 'p:Description')
     
    

    After you add it to an index, you can also view the content in USER_XML_INDEXES. PARAMETERS (XML format).

  • Enter a folder instead of just '+' or '-' to display the content?

    Try to configure Dreamweaver 6 PC similar to the Coda (Mac), in the Coda I can double click on the folder and I enter the folder in my local browser, so I don't see other folders on my Local Site.  How can I change my site monitor so that I can "enter" file instead of simply hitting the '+' or '-' to display the contents of the folder?

    DW has no provision.  Use your browser to open your folder of the Local Site.

    URL: file:///C:/yourSiteName/Folder/

    Nancy O.

Maybe you are looking for

  • Can I install Win 8 on Satellite A660?

    I tried to get a post in response to my question.I wasn't able to do. Please forgive me if its duplicate. You can install windows 8 on an A660? is there an incompatibility in the car? Please share any food in return, you may have. Thank you.

  • HP 7640: Double-sided printing

    Same problem a few days ago.  REF 3021633216 (George) corrects this problem. Today, when you click on 'Contact HP support' I get Page not found.  Made my wife on his computer.  So I cannot support and no text take control of your computer and fix it

  • my volume control on my taskbar does not work... why?

    Volume controls in Control Panel work very well... it's just that the bottom right does not work?

  • How to print specific pages does not not in LJColorPro M177

    You just bought a new LJ MFP M177 ColorPro works with a Mac in Mac OS 10.6. I want to print specific pages in the HP manual that came with the installation diskettes. No matter what page numbers I can print, they never match the screen pages in this

  • Problems of Windows 8

    Hi, recently I have problems with WMP and sound; I have an Aspire E1 - 571 laptop running W8, everything is now up-to-date and I checked all the pilots involved and all are the latest drivers available. When I try to play a music file I sometimes get