Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-28-2012, 09:36 PM   PM User | #1
rich1051414
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
rich1051414 is an unknown quantity at this point
[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..
rich1051414 is offline   Reply With Quote
Old 12-28-2012, 09:45 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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).
Fou-Lu is offline   Reply With Quote
Old 12-28-2012, 09:48 PM   PM User | #3
rich1051414
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
rich1051414 is an unknown quantity at this point
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..
rich1051414 is offline   Reply With Quote
Old 12-28-2012, 10:12 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 12-28-2012, 10:27 PM   PM User | #5
rich1051414
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
rich1051414 is an unknown quantity at this point
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..
rich1051414 is offline   Reply With Quote
Old 12-29-2012, 08:53 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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).
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:06 PM.


Advertisement
Log in to turn off these ads.