• 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

Getting data for display in a new JFrame

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

I am learning Swing from the web, which is obviously not a good idea with such a big topic. I ran into the following simple question:

If I spawn a new JFrame from another JFrame, for example from a menu item, where do I load the data, in my case some text from a file, that is needed for display in the new frame?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about the constructor?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you want to spawn a new frame from an existing frame? It is a good idea to use Dialogs in such scenarios. Check out JDialog and JOptionPane API. The JOPtionPane#showXXXDialog accepts an Object as the dialog content. So you can even considering passing a JPanel with other controls as its children

How to load data is a design question. I usually define a sequence in my constructor, where the components are initialized, then laid out on the parent container using appropriate layouts. If I plan to use the same UI to display details of multiple objects, I have a method which accepts the objects, and changes the values inside the components. That way I do not need to initialize and re-layout the components every time.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a lot depends on the purpose of frame2, and its necessity
i.e. many (most) similar posts (re frame2) end up changing
their design to either a CardLayout, or use of a modal JDialog

 
Ruben Matthews
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have used the constructor. Thanks Maneesh for the remarks. I need to dig deeper into this subject, because right now I am doing what works instead what is the intended use of Swing
 
Poop goes in a willow feeder. Wipe with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic