File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Sharing Objects Between Tabs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Sharing Objects Between Tabs" Watch "Sharing Objects Between Tabs" New topic
Author

Sharing Objects Between Tabs

Sunny Rodriguez
Greenhorn

Joined: Jun 30, 2009
Posts: 5
Hello everyone,
I created a program that allows teachers to create topics from different assignments and compare grades and get an overall comprehension level. The program uses tabs to help the user go step by step to the final overview tab. I have an Import, Allocate Assignments, and Overview tab that all share a Gradebook object.

The problem is the Gradebook object is not updating in every tab. My work-around was to update every tab by passing in a new Gradebook object every time the user changes tab. I do not like this setup because the program updates even if nothing was changed in the Gradebook object, which is inefficient. Is there a better way?

Thank you for your time.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10519
    
    9

Hi Sunny,
Welcome to the Ranch.

Have you considered using a propery change listener?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Sunny Rodriguez
Greenhorn

Joined: Jun 30, 2009
Posts: 5
Thank you for your input. I did not realize there was even such a thing available. I Google searched property change listener and found a tutorial directly from Sun, here How to Write a Property Change Listener.

Seems I have much to learn since the tutorial began talking about JavaBeans. I do not have any experience with Beans, does anyone know a great resource to get me in the right direction?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
try just using a ChangeListener.

Basically, it fires whenever the selected tab changes,
so you can put your update code in that event's stateChanged()
Vandre Caetano
Greenhorn

Joined: Dec 19, 2007
Posts: 15
Ok, here is an exemple:



Then your tabs are going to have something like this:



I hope it helps
Sunny Rodriguez
Greenhorn

Joined: Jun 30, 2009
Posts: 5
Vandre Caetano wrote:Ok, here is an exemple:

public class SomeThingBean {
public static final String POJO = "pojo";

private Pojo pojo;
private PropertyChangeSupport changeSupport;

...

I hope it helps


Thank you! It will take me time to understand all of this. E.G., I had to look up POJO, which I now know is an acronym for "Plain Old Java Object".

I am confused by your final POJO string. Can the string contain anything? I guess I'm wondering what the purpose of the string is in general.
Vandre Caetano
Greenhorn

Joined: Dec 19, 2007
Posts: 15
Sunny Rodriguez wrote:
Vandre Caetano wrote:Ok, here is an exemple:

public class SomeThingBean {
public static final String POJO = "pojo";

private Pojo pojo;
private PropertyChangeSupport changeSupport;

...

I hope it helps


Thank you! It will take me time to understand all of this. E.G., I had to look up POJO, which I now know is an acronym for "Plain Old Java Object".

I am confused by your final POJO string. Can the string contain anything? I guess I'm wondering what the purpose of the string is in general.


When you fire a property change event, you need to send a string to identify what property is been changed.
Lets say all your tabs are listeners of a different property change, what will happen is: Any time any property changes, all your tabs are going to be warned, it's up to the tabs to know if the changed property is the one that matters to then.
When I did it the first time I had a nice tutorial about it but apparently I don't have it anymore .

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10519
    
    9

Vandre Caetano wrote:
When I did it the first time I had a nice tutorial about it but apparently I don't have it anymore .


Is this the one?
Vandre Caetano
Greenhorn

Joined: Dec 19, 2007
Posts: 15
Maneesh Godbole wrote:
Vandre Caetano wrote:
When I did it the first time I had a nice tutorial about it but apparently I don't have it anymore .


Is this the one?


No... but that is a nice one too.
Sunny Rodriguez
Greenhorn

Joined: Jun 30, 2009
Posts: 5
Vandre Caetano wrote:
When you fire a property change event, you need to send a string to identify what property is been changed.


So is it possible to have multiple properties being checked for changes?
Vandre Caetano
Greenhorn

Joined: Dec 19, 2007
Posts: 15
Sunny Rodriguez wrote:
Vandre Caetano wrote:
When you fire a property change event, you need to send a string to identify what property is been changed.


So is it possible to have multiple properties being checked for changes?


Yes, you actually check for all properties change, and in the listener implementation you verify what property was changed and what you want to do with it.

Try to code a little, even if you fell insecure, if after a while you still fell too lost, I'll post a more detailed example.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sharing Objects Between Tabs