Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #3336 > unrolled thread

Re: How to update JTable

Started by"Royan" <royan@THRWHITE.remove-dii-this>
First post2011-04-27 15:44 +0000
Last post2011-04-27 15:44 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.java.gui

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to update JTable "Royan" <royan@THRWHITE.remove-dii-this> - 2011-04-27 15:44 +0000

#3336 — Re: How to update JTable

From"Royan" <royan@THRWHITE.remove-dii-this>
Date2011-04-27 15:44 +0000
SubjectRe: How to update JTable
Message-ID<5e5bbad7-0b50-4cda-b0dc-e799addf1d4e@i29g2000prf.googlegroups.com>
  To: comp.lang.java.gui
On 30 =CD=C1=D2, 03:50, Royan <romayan...@gmail.com> 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.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web