Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java GUI > Re: How to upda...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 5 Topic 9617 of 9960
Post > Topic >>

Re: How to update JTable from JMenuBar?

by Royan <romayankin@[EMAIL PROTECTED] > Mar 30, 2008 at 09:37 AM

On 30 =CD=C1=D2, 03:50, Royan <romayan...@[EMAIL PROTECTED]
> wrote:
> 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!

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.
 




 5 Posts in Topic:
How to update JTable from JMenuBar?
Royan <romayankin@[EMA  2008-03-29 16:50:07 
Re: How to update JTable from JMenuBar?
"David A. Redick&quo  2008-03-30 08:18:14 
Re: How to update JTable from JMenuBar?
Royan <romayankin@[EMA  2008-03-30 09:37:24 
Re: How to update JTable from JMenuBar?
Chase Preuninger <chas  2008-03-31 06:43:47 
Re: How to update JTable from JMenuBar?
Sabine Dinis Blochberger   2008-04-01 09:39:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 16:21:12 CDT 2008.