Thread: TableView

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    4
    Rep Power
    0

    TableView


    have recently tried my hand at javafx - got to the TableView and checkboxes. What I have is a table with two columns, in the first column there is a checkbox, what I'd like to happen is that when I check this checkbox, I'd like a combo box to appear in the next column to chose from a list, then have the combo box dissappear and put that name in that cell. Please help in any way - am at a loss.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    103
    Rep Power
    3
    Well, there are many ways you could do this. One of them would be to create the combo box in the second row of the table. Initially set it to invisible. Then, setup an event for the checkbox for when checked that will set the visibility of the combobox to visible.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    4
    Rep Power
    0

    Thank you


    Much appreciated but;
    If this is my code:

    Code:
    final TableColumn ioCol = new TableColumn("Out");
            ioCol.setMinWidth(100);
            ioCol.setCellValueFactory(
                    new PropertyValueFactory<Book, Boolean>("io"));
            ioCol.setCellFactory(CheckBoxTableCell.forTableColumn(ioCol));
            ioCol.setEditable(true);
            ioCol.setOnEditCommit(
                    new EventHandler<CellEditEvent<Book, Boolean>>() {
                @Override
                public void handle(CellEditEvent<Book, Boolean> t) {
                    try {
                        ((Book) t.getTableView().getItems().get(
                                t.getTablePosition().getRow())).setIO(t.getNewValue());    
                        writeFile();
                     
                    } catch (IOException ex) {
                        Logger.getLogger(Books.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });
    
    
            TableColumn whoCol = new TableColumn("Who to");
            whoCol.setMinWidth(100);
            whoCol.setCellValueFactory(
                    new PropertyValueFactory<Book, String>("who"));
            whoCol.setCellFactory(ComboBoxTableCell.forTableColumn(p.data));
            whoCol.setEditable(true);
            whoCol.setVisible(true);
            whoCol.setOnEditCommit(
                    new EventHandler<CellEditEvent<Book, String>>() {
                @Override
                public void handle(CellEditEvent<Book, String> t) {
                    try {
                        ((Book) t.getTableView().getItems().get(
                                t.getTablePosition().getRow())).setWho(t.getNewValue());
                        writeFile();
                    } catch (IOException ex) {
                        Logger.getLogger(Books.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (ClassCastException cce) {
                    }
                }
            });

    I'd like, if the CheckBoxTableCell in ioCol is checked, then the ComboBoxTableCell will show. what can't be figured is where is the status of the checkbox to be found?? Have placed if statements after each line and cannot get an answer as to what state the checkbox is in. Please and again thank you for any assistance. *Theory might give a clue( willing to give it a try); code would be better assistance, but only if I cant understand.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    103
    Rep Power
    3
    I don't know what GUI libraries your using, but if it's swing then you should be able to call the isSelected() on your JCheckBox object to see if it is checked or not.

    If it were me I would setup an event listener that triggers when an action is performed on the JCheckBox. At that point I would check to see if it is selected or not and take the appropriate action.

    http://www.java-forums.org/javax-swing/9556-how-use-swing-checkboxes.html
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    4
    Rep Power
    0
    sorry am using javafx

    javafx.scene.control
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    103
    Rep Power
    3
    http://stackoverflow.com/questions/13726824/javafx-event-triggered-when-selecting-a-check-box

    Google is a wondrous tool.

    The listeners shown there will trigger whenever a change is made to a checkbox (checked or unchecked).
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    4
    Rep Power
    0
    awesome ty ty ty

IMN logo majestic logo threadwatch logo seochat tools logo