how can i add components to Jpanel from another class

Recommended Answers

All 3 Replies

That's not enough info! Please explain what you need in a bit more detail.

I am receiving the userlist at socket in 10 seconds of interval which is a single string and i'm splitting that string to individual string of username and There is a Homepanel class where userlist is displayed and i want that panel has user name in (Jlabel)as many number as user created by splitting. how can i do that or is thre any other better way please suggest

Quickest way could be to write a public method in the Homepanel class that takes the userlist (or pre-split array of usernames) as a parameter and updates the GUI accordingly. Pass a reference to the HOmepanel into the socket-handling class so it can call the public method.
Best way, avoiding hard-wring the GUI ref into the socket layer, is to use a Listener pattern where the socket layer sends "user list updated" events to registered listeners - just like Swing does everywhere. This is better architecture, but more code - it all depends on how "serious" this application is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.