开发者

JTabbedPane event fired when tab selected [closed]

开发者 https://www.devze.com 2023-01-05 20:15 出处:网络
开发者_StackOverflow中文版 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its cu
开发者_StackOverflow中文版 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago.

I need an event to be fired when, let's say, tab 1 is focused by the user. Any tips on how to do this?


This is what I used:

tabbedPane.addChangeListener(new ChangeListener() {
private boolean init;

public void stateChanged(ChangeEvent e) {
    if (!init) {                                        
        init = true;

        new SwingWorker<Boolean, Void>() {
            @Override
            protected void done() {
                try {
                    boolean loggedIn = get();

                    if (loggedIn) {
                        // Success so perform tab operations.
                    }
                } catch (InterruptedException e1) {
                    e1.printStackTrace(); // Handle this.
                } catch (ExecutionException e1) {
                    e1.printStackTrace(); // Handle this.
                }
            }

            protected Boolean doInBackground() throws Exception {
                // Perform login on background thread.  Return true if successful.
                return true;
            }
        }.execute();
    }
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号