Inter object communication in Java?

I have a code which is half generated by Netbeans IDE through selecting the containers and controllers.  Within the project I have a couple of packages which should work together and be able to see one another's variables and methods.  In one of the packages I have a JList item which needs to be populated when the JPanel from this other package receives the user input.  However for some reason this link is not possible!  

I even place a public getter method inside the LMBView class but still can't access the LMBView object!


PACKAGE LMB ------------------------------------------------

//This is the main class initializing the LMBView class
public class IDAApp extends SingleFrameApplication {

      @Override
       protected void startup() {
            show(new LMBView(this));
        }
}

    
public class LMBView extends FrameView {

      public javax.swing.JList jList_PortalList;

      private void initComponents() {
             jList_PortalList = new javax.swing.JList();
                  .
                  .
                  .
      }

Open in new window


PACKAGE LMB.resources---------------------------------------

LMB.LMBView.jList_PortalList  // DOES NOT WORK OR LINKS TO THE CALLING OBJECT

Open in new window




This is the error message shown

     
non-static variables jList_PortalList cannot be referenced from a static context

Open in new window

snajalmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>public javax.swing.JList jList_PortalList;

Don't do that. Make it private and do the below, calling that method from where you want to access the JList
public JList getPortalList();
    return jList_PortalList;
}

Open in new window

0
CEHJCommented:
If you do

>>show(new LMBView(this));

you're going to lost the reference to LMBView, so you won't be able to call the method i just gave you. You need
LMBView lmb = new LMBView(this);
JList portalList = lmb.getPortalList();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
snajalmAuthor Commented:
Is this the right way of constructing it??!  This LMBApp class contains the main view which ultimately make a call to the LMBView class.  I applied your fix but it seems not working!

/*
 * LMBApp.java
 */
package ida;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class LMBApp extends SingleFrameApplication {
    LMBView lmbView;
    /**
     * At startup create and show the main frame of the application.
     */
    @Override
    protected void startup() {
        lmbView = new LMBView(this);
        show(lmbView);
        //show(new IDAView(this));
    }
    
    public LMBView getLMBViewInstance() {
        return lmbView;
    }
    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override
    protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of IDAApp
     */
    public static IDAApp getApplication() {
        return Application.getInstance(LMBApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) throws Exception {
        launch(LMBApp.class, args);
    }
}

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

CEHJCommented:
What about it is 'not working'?
0
for_yanCommented:


non-static variables jList_PortalList cannot be referenced from a static context

this means you are using your non-static instance  variable jList_PortalList
within a static mathod. But in the code which you show we don't see any static
methods. Which is the line which generates thios error?
0
snajalmAuthor Commented:
Here's what I've done which is working but I'd want to know whether this is logically right!!!!  

Please look at the methods getLMBViewInstance() and startup()  (as CEHJ) recommended it!  Now it seems that I can have a little getter method inside the LMBView class and access the jList_PortalList controller!

/*
 * LMBApp.java
 */
package lmb;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class LMBApp extends SingleFrameApplication {
    static LMBView lmbView;
    /**
     * At startup create and show the main frame of the application.
     */
    @Override
    protected void startup() {
        lmbView = new LMBView(this);
        show(lmbView);
        //show(new LMBView(this));
    }
    
	// IS THIS METHOD LOGICALLY RIGHT
    public static LMBView getLMBViewInstance() {
        return lmbView;
    }
    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override
    protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of LMBApp
     */
    public static LMBApp getApplication() {
        return Application.getInstance(LMBApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) throws Exception {
        launch(LMBApp.class, args);
    }
}

Open in new window

0
for_yanCommented:
Seems not worse than anything else.

If I were you, I'd go away form all this NetBeans stuff.
It is all so confusing.

And it is much better to create these GUI yourself - than you are in command of everything
and don't depend on their weird code.

0
CEHJCommented:
Yes. What i'm not familiar with is the JSR on which the framework is based, so i can't tell you if it's 'correct' from a design point of view. From a programming point of view, it's fine
0
CEHJCommented:
You'll need to study it probably:

http://jcp.org/en/jsr/detail?id=296
0
snajalmAuthor Commented:
Thank you!
0
CEHJCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.