Results 1 to 3 of 3
  1. #1
    GRPsuper9 is offline Member
    Join Date
    May 2015
    Posts
    16
    Rep Power
    0

    Default Adding ID value to TableColumn

    Hey guys,

    I have an observable list that changes the tablecolumn items whenever it is changed. I am curious to know how I would add a "column id" to a tablecolumn?

    In visual basic, it would be somewhere around the lines of table.items.add(intID, "asdf", "asdf", "asdf").

    Currently I have
    Java FX Code:
            colCreated = new TableColumn("Created");
            colCreated.setCellValueFactory(new PropertyValueFactory<Match, String>("player"));
    Which works as intended and gets the value from the object.

    But how would I make it instead of getting the value from an object, it gets it from me?

    Java FX Code:
            colAction = new TableColumn("Action");
            colAction.setCellFactory(new Callback<TableColumn<Match, String>, TableCell<Match, String>>() {
                @Override
                public TableCell<Match, String> call(TableColumn<Match, String> param) {
                    return new TableCell<Match, String>() {
                        @Override
                        protected void updateItem(String string, boolean empty) {
                            super.updateItem(string, empty);
                            if(empty) {
                                setText(null);
                                
                            }else {
                                setText("Play");
                            }
                        }
                    };
                }
                
            });
    I believe this code is too long to just be putting the custom word "Play" into every cell column. I guess what I am asking is, how would I shorten this code to put a custom value?

    Thanks!

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Adding ID value to TableColumn

    I'm not familiar with JavaFX yet, but my interpretation of the snippet is that your problem is mainly that you're sticking generic String objects in the table column, rather than your own bean class which has among other things an ID and a label.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    GRPsuper9 is offline Member
    Join Date
    May 2015
    Posts
    16
    Rep Power
    0

    Default Re: Adding ID value to TableColumn

    Quote Originally Posted by gimbal2 View Post
    I'm not familiar with JavaFX yet, but my interpretation of the snippet is that your problem is mainly that you're sticking generic String objects in the table column, rather than your own bean class which has among other things an ID and a label.
    My idea behind this is that I want to control an objID value within my class. Every time I add a new object for example, I want to objID++. Along with incrementing the integer objID, I also want to display that objID to the user. The issue I am having is knowing how to add my own text into the column rather than a property value from an object. Would I be able to do the following? Adding the integer '1' to the column?
    Java FX Code:
    colAction.setCellValueFactory(new PropertyValueFactory<Integer, Integer>(1));

Similar Threads

  1. Adding an AVD
    By tnrh1 in forum Android
    Replies: 2
    Last Post: 12-06-2012, 02:47 PM
  2. Adding 2
    By helpr in forum New To Java
    Replies: 3
    Last Post: 11-01-2012, 01:31 AM
  3. Replies: 1
    Last Post: 04-05-2011, 08:58 PM
  4. Replies: 2
    Last Post: 03-01-2011, 01:30 AM
  5. Adding
    By natep67 in forum New To Java
    Replies: 2
    Last Post: 04-22-2009, 07:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •