Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

help getting a sub-pane of a JTabbedPane to initialize

mecaseApr 17 2013 — edited Apr 17 2013
Hi,

I have an application that a JTabbedPane with 5 tabs/panes. One of these has three tabbed panes in it. What I want to do is that when I switch between one of the top-level five and the three inside another one of the top five (i.e. the sub-panes, I guess you could call them) I want certain values to update from an underlying model.

The current code does this updating (in some cases but not this one) by invoking methods in the other panes like "updateGUI". The simplest solution is to let them all have a reference to each other and call the appropriate updates on the other panes. In fact, most have references to each other. I was simply trying to avoid these explicit calls from various places on condition of this and that to change this or that when a simple solution seems to me to be to tell the GUI to update its values when it gains focus. But I never trigger this. Relevant code:

The engtab pane has 3 panes:
    JTabbedPane engtab;

    public void buildGUI() {
//...bunch of stuff
        engtab.addFocusListener(new engtabFocusListener());
        MGUI.PaneBuild(engtab);
        MIP.PaneBuild(engtab);
        PowerSwitch.PaneBuild(engtab);
The calls to PaneBuild are implemented like this:
public void PaneBuild(JTabbedPane JTP) {
//...build the rest of the pane.
    JTP.add("Motor GUI", mainPanel);
}
I naively tried to add a focus listener to engtab in the first class (the one that calls the PaneBuild methods) like so:
    private class engtabFocusListener implements FocusListener {

        public engtabFocusListener() {
        }

        @Override
        public void focusGained(FocusEvent fe) {
            System.out.println("focusGained for engtab of main.");
//            MGUI.updateGUI(MotorEnum.all, true, 1);
//            InstCon.updatecurrentGUI();
//            InstCon.updatenextGUI();
            MIP.updateGUI();
        }

        @Override
        public void focusLost(FocusEvent fe) {
            System.out.println("focusLost for engtab of main Not supported yet.");
        }
    }

    public void buildGUI() {
//... stuff

        engtab = new JTabbedPane();        
        engtab.addFocusListener(new engtabFocusListener());
I never see the messages about focus. Thanks for your help.

Edited by: mecase on Apr 17, 2013 8:44 AM

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 15 2013
Added on Apr 17 2013
1 comment
1,291 views