• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NetBeans calling JPanel from a JPanel in a separate class

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a JFrame with 2 JPanels and all 3 of these are held in separate classes. On one panel I have a button. Once clicked I want to be able to update a table that is held on the other panel. The problem is that I don’t have access to the second panel from the first panel. I have seen a lot of answers to similar questions suggest adding the second panel to the constructor of the first panel and then calling JPanel1 = new JPanel(jpanel2) from the main, but I don’t use main methods in my code. Is anyone able to help?
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Kate,

welcome to the Ranch and enjoy the stay!

One of the many ways is for instance:
 
Saloon Keeper
Posts: 15484
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avoid direct communication between UI components.

Instead, have your panels depend on the same model, and when the first panel updates the model, the second panel responds to updates in the model. Here is a very simple example:




 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Kate!

Netbeans is not a programming language nor is it a GUI framework. It's an Intelligent Design Environment (IDE), which means that it's an application whose sole purpose is to assist you in designing, implementing and testing applications. When an application moves into production, the IDE goes away.

Part of what an IDE may provide is "wizards" that can help in automatically generating application code and resources, but when all is said and done, your application isn't an "Netbeans" application, it is (in your case) a Java Swing application.

So I'm linking this thread to our Swing forum, since you can get a lot of help on Swing there even from people who don't use NetBeans.
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic