0

I'm looking to build out a Java GUI with a table area and an area that will display the data of a selected row of the table. I've never tried a multi-frame set up before so before I venture to do this I wanted to check with others. Is it difficult to have two frames and have them passing data back and forth? The idea would be that I could move the details frame anywhere I like on the screen or to a second monitor and allow the table to go full-screen if the user wants. Any input or examples are appreciated.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Nicholas Hazen
  • 1,245
  • 2
  • 9
  • 13

3 Answers3

2
  • don't to create two of more JFrames use JDialog instead,

  • reuse this JDialog for another action(s)

  • create one JFrame and one JDialog for displaying details

  • have to determine if and which of JTables row(s) is selected

  • better would be to set ListSelectionMode to the SingleSelection

  • maybe would be better to invoke (show that already exist) JDialog from JPopupMenu Action

mKorbel
  • 109,525
  • 20
  • 134
  • 319
1

You should have no problem in doing what you are after. You can have public methods in each frame which expose properties and/or structures and you then pass the instance of one JFrame to the other. This should allow you to pass data back and forth.

That being said however, I think that this scenario is valid only when you have one, two, or at most three JFrames. Having a lot of frames calling each other could result a maintenance nightmare.

npinti
  • 51,780
  • 5
  • 72
  • 96
0

there are several possibilities to do so:

  • you can add one of the jframes as a listener to anothe, or both to each other. For this, you have to implement a listener mechanism, like in java.awt. You can pass the information contained in the event objects - this would be the most clean alternative
  • you can pass the instance of the detailframe directly in the constructor of the main frame and call operations from main frame on detail frame. this is the simplest way, but you will need lot of code changes if you have some new features to add
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Leonkur
  • 71
  • 3