• 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 information into a JTable from a drawing Canvas

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ranchers,

I have a drawing Canvas on which I draw various things.
I can right-click on them and bring up a JPopupMenu.
I have a JTable also that is in its own JFrame.


I am not sure how to implement the following procedures.



The objects on the canvas refer to real electrical elements and I want to pass information to the JTable about the element clicked on.

I need to pass about 6 TextFields for each element.
Do I use a JPanel to do this?

Whichever container I use, I have to be able to move it around on screen.

I enter the data and then click a button and then pass this data to the JTable.

The container closes.

Kind regards,

The Apprentice
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a job for Model View Controller - make model objects for the data you need for the electrical elements. You'll probably need to make another model object to consolidate the elements you want to display in the canvas, to collect them and perhaps hold information about connections. The canvas will be the view for this model. Then, you'll want to make another model object by implementing TableModel (or extending DefaultTableModel if you can) to hold all the electrical element model objects you want to appear in the table. A JTable will be the view of this model. Then you write controllers - these will be the listeners and event handlers that pass electrical element model objects between the canvas and the table, handle adding/deleting elements from the canvas or table, etc.
 
Kieran Murray
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Nate,

Thanks. I am trying to implement this MVC philosophy and am quite some way down the path but I am not sure about passing information from one package to another. My JTable is in one package - tables and my drawing Canvas is in another - translation.
I can input information into my JTable from the screen. However, I also want to be able to pass information into the JTable from the Drawing Canvas - this is where it all gets fuzzy.

This is the code for the popup Window to input data for the Generator from the Drawing Canvas



How do I get the information from here into this



I should press the EnterButton in the Generator Input Details class and then somehow get the information from the JTextFields and pass it on. It is this that I do not understand.

Kind regards,

Kieran
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please edit your code to get rid of the very long lines which make it very difficult to read. It is also impossible to try out because you are using a non-standard class (SpringUtilities) and not telling us where to get it from.

You would need to import the tables.GeneratorData class, and pushing the buttons would create a GeneratorData object.
 
Kieran Murray
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ranchers,

Thank you for your help. Finally settled on the code below. The important method for passing of data is setGeneratorValues();
I import tables.*;



The code SpringUtilities is from the Java Sun Tutorial on Spring layouts.

Thanks again,

Kieran
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome; not sure how much I helped.

And I could never understand SpringLayout anyway.
reply
    Bookmark Topic Watch Topic
  • New Topic