Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    [Resolved]Odd JavaFX problem

    So I have a listview that displays a label on a callback that checks a list if that particular item is disabled, and adjusts it display string and appearance occordingly, however, it does not update unless the form is reloaded or I scroll down and back up.

    Is there a call I need to make to ensure the cell is repainted after I make a change? I have caching disabled on the listview already, doesn't seem to make a difference. This is my callback:

    Code:
    ...
    lv.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
                @Override
                public ListCell<String> call(ListView<String> list) {
                    return new LabelCell();
                }
            });
    ...
    static class LabelCell extends ListCell<String> {
    
            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (item != null) {
                    String s = item;
                    Label l;
                    if (disabledMods.contains(item)) {
                        s = "DISABLED " + s;
                        l = new Label(s);
                        l.disableProperty().setValue(Boolean.TRUE);
                    } else {
                        l = new Label(item);
                        l.disableProperty().setValue(Boolean.FALSE);
                    }
                    setGraphic(l);
                }
            }
        }
    Last edited by rich1051414; 12-28-2012 at 10:40 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Despite the similar sounding names, Java is not the same as Javascript.
    Moving from javascript forum to Java forum.

    I'm not familiar with the JavaFX library (which I recall looking a bit into and its a gui extension?), but what you have here looks similar to swing. Under the description you have here, it is similar to a swing component issue as well. The setGraphic is a bit different though.

    Does the JavaFX have an invalidate option as a part of its base component? If so, try invalidating "this" and see if the gui forces a repaint. I often have these same issues with the swing which is why I typically reserve components that are treatable as input components as the container for anything dynamic (textboxes for example will always repaint).

  • #3
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Despite the similar sounding names, Java is not the same as Javascript.
    Moving from javascript forum to Java forum.

    I'm not familiar with the JavaFX library (which I recall looking a bit into and its a gui extension?), but what you have here looks similar to swing. Under the description you have here, it is similar to a swing component issue as well. The setGraphic is a bit different though.

    Does the JavaFX have an invalidate option as a part of its base component? If so, try invalidating "this" and see if the gui forces a repaint. I often have these same issues with the swing which is why I typically reserve components that are treatable as input components as the container for anything dynamic (textboxes for example will always repaint).
    I know the difference, and I thought I did post in the Java forum.
    And javafx does not invalidate, nor can I find anything about repaint/redraw/paint/etc you would expect from typical java.
    Last edited by rich1051414; 12-28-2012 at 09:52 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by rich1051414 View Post
    I know the difference, and I thought I did post in the Java forum.
    And javafx does not invalidate, nor can I find anything about repaint/redraw/paint/etc you would expect from typical java.
    Hmm, is the behaviour the same as it is in swing with changing label text? If so I can try and track down something online for the JavaFX to see if there is anything in particulars.

  • #5
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Hmm, is the behaviour the same as it is in swing with changing label text? If so I can try and track down something online for the JavaFX to see if there is anything in particulars.
    I have read many problems with javafx controls not refreshing their view, but none of these seem to work in my situation. I have also tried mapping seperate labels for each item, and setting the text, but it still does not trigger a redraw. I have also tried setting the labels invisible and visible again, but this also does not trigger a redraw, I am a bit stumped.

    Edit: I fixed it by forcefully clearing and repopulating the list, forcing it to redraw all items. Not ideal, but it works.
    Last edited by rich1051414; 12-28-2012 at 10:40 PM.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by rich1051414 View Post
    I have read many problems with javafx controls not refreshing their view, but none of these seem to work in my situation. I have also tried mapping seperate labels for each item, and setting the text, but it still does not trigger a redraw. I have also tried setting the labels invisible and visible again, but this also does not trigger a redraw, I am a bit stumped.

    Edit: I fixed it by forcefully clearing and repopulating the list, forcing it to redraw all items. Not ideal, but it works.
    Glad you found a solution to this. Swing is bad enough in you typically have to invalidate a component, but needing to force a redraw by repopulating certainly isn't ideal. I'd assume that there is a better approach to it as well, but I'm afraid I can't really help with it since I'm not versed in javafx at all. Eventually you'll stumble on the best solution though (you'd think oracle would be explicit in their documentation for stuff like this).


  •  

    Posting Permissions

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