Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2008

Tip: Looking for answers? Try searching our database.

How to update JTable from JMenuBar?

Thread view: 
Royan - 30 Mar 2008 00:50 GMT
The initial problem is to update JTable when user opens file from my
JMenuBar

I handle JMenuBar events by implementing AbstractAction
My JTable has its own implementation of TableModel (I extend
DefaultTableModel)

The JTable itself is added into the JPanel that resides within the
JFrame that actually holds,the described above JMenuBar, I know its
getting too confusing, so I'll try to visualize my words

---------------------------------
| MyJMenuBar
| -------------------------------
| MyJPanel
| ------------------------------
| |JTable
| |*************************
| |* MyTableModel is here  *
| |*************************

So how to I update my JTable when user clicks File > Open on JMenuBar?

There is one hack I think about right now. In File-Open handler I can
add the following line of code

SwingUtilities.windowForComponent(MyJMenuBar.this).getMyJPanel().getJTable().setNewModel(new
MyTableModel());

Frankly I don't like this approach, because I don't think its good to
make my JMenuBar to be aware of MyTableModel, so I desperately need
somebody's help and advice.
Thanks a lot beforehand!
David A. Redick - 30 Mar 2008 16:18 GMT
I make my 'main' JFrame an ActionListener for my 'open' MenuItem.
When the 'open' sends the ActionEvent to 'main' and then I create a
FileChooser
and let the user pick the file.

After the FileChooser returns I just call the various methods for the
table model.
Royan - 30 Mar 2008 17:37 GMT
> The initial problem is to update JTable when user opens file from my
> JMenuBar
[quoted text clipped - 29 lines]
> somebody's help and advice.
> Thanks a lot beforehand!

Thanks David, but I think i've come up with something that answers my
question:

public void actionPerformed(final ActionEvent e) {
   if (FILE_OPEN.equals(e.getActionCommand())) {
       SwingUtilities.windowForComponent(MyJMenuBar.this)
               .firePropertyChange("fileOpen", 0, 1);
   }
}

As far as you can understand each menu item is initialized with an
instance of AbstractAction implementation with similar code. The last
step is that Controller class within main window handles fired
property change within its code.
Chase Preuninger - 31 Mar 2008 14:43 GMT
Pass the reference along.

http://groups.google.com/group/java-software-develoupment?hl=en
Sabine Dinis Blochberger - 01 Apr 2008 09:39 GMT
> Pass the reference along.
>
> http://groupspam.google.com/group/java-spam-develoupment?hl=en

Go away, you spammer.

Signature

Sabine Dinis Blochberger

Op3racional
www.op3racional.eu



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.