0

I want to change my JFrame mouse cursor when the data is being lazy-loaded by a Hibernate session, setting it to wait mode. How can I get that done? Thank you

smr
  • 33
  • 6

1 Answers1

0

You should always include some code as to show what you've done so that we can add/edit it in order to give you the answer.

However, I'll give you a basic idea about how to do it:

You specify it while declaring the entity whether you want lazy loading or eager loading.

Now, when you load child elements, you can change your cursor before accessing child elements and revert it back to normal when loading is complete. I have demonstrated it using threads.

//lets suppose this is your class and it is currently lazy loaded
private Set<Child> children = parent.getChildren(); // Currently it doesn't contain anything because it is set to Lazy load

and Let's suppose this is how you're lazy loading your objects

public static void yourCurrentMethod() {
    ...

    children.size();
    children.iterator();

    ...
}

Instead of this, you can write your method this way:

public static void yourCurrentMethod() {
    ...

    scroll.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));        
    SwingUtilities.invokeLater(new Runnable() {
        children.size();
        children.iterator();
        scroll.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    });

    ...
}

Please refer to these answers for more info:
1. https://stackoverflow.com/a/21016898/2815219
2. https://stackoverflow.com/a/2192271/2815219

Community
  • 1
  • 1
Raman Sahasi
  • 24,890
  • 6
  • 51
  • 66