Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Populating JList in Parent window from Child window's save button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Populating JList in Parent window from Child window Watch "Populating JList in Parent window from Child window New topic
Author

Populating JList in Parent window from Child window's save button

Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 231
Hi Folks,

I am new to Java Swings.I have a problem which is described as :

I have two list in Parent window (say list ListA and ListB) .ListA has few items .On Clicking the ListA's item one popup window will be displayed .In this pop-up (child) window we have a TextArea and a save button.

On clicking the Save Button the data entered into the TextArea should be displayed in ListB immediately.

I used this approach in parent window

[list] On clicking the ListA item


[/list]

  • In pop-up window created text area and button


  • On clicking button will set the textarea value to the parentwindow.setListB (May be I am wrong here )



  • So when I click on ListA item gui appears, I enter data and click Save ....!!!
    No data display in ListB , while Again clicking the ListA item the previous entered data of ListB appears .

    I want to reflect the data in ListB immediately as click on Pop-up save button .

    Help me please !

    Thanks in advance !!

    God Gave Me Nothing I Wanted, He Gave Me Everything I Needed.
    OCPJP6
    Rob Camick
    Ranch Hand

    Joined: Jun 13, 2009
    Posts: 2215
        
        7
    I don't really understand your question so I'll just point you to the section from the Swing tutorial on How to Use Lists which contains a working example of dynamically adding/removing elements from the ListModel.

    Once you understand that example you should be able to customize your code.
    Michael Dunn
    Ranch Hand

    Joined: Jun 09, 2003
    Posts: 4632
    add the new data to ListB's model
    (you may also need a custom renderer if you want to display multiple lines from a JTextArea)

    if you want to change what's in ListB, set a new model
    Fidel Edwards
    Ranch Hand

    Joined: Mar 19, 2008
    Posts: 231
    Rob Camick wrote:I don't really understand your question so I'll just point you to the section from the Swing tutorial on How to Use Lists which contains a working example of dynamically adding/removing elements from the ListModel.

    Once you understand that example you should be able to customize your code.



    Thanks Rob,
    It is something like fill the ListB, with whatever we Fill in Child window's TextArea.

    It is pretty clear !(I need to notify the Parent Window that child's save button been pressed.)


    Thanks for your reply !



    Fidel Edwards
    Ranch Hand

    Joined: Mar 19, 2008
    Posts: 231
    Michael Dunn wrote:add the new data to ListB's model
    (you may also need a custom renderer if you want to display multiple lines from a JTextArea)

    if you want to change what's in ListB, set a new model


    Thanks Micheal !


    I am really new to Java Swing ! Could you explain me or suggest me that how should I write Custom Renderer ?


    Again tons of thanks !
    Maneesh Godbole
    Saloon Keeper

    Joined: Jul 26, 2007
    Posts: 10519
        
        9

    Ashish Tiwari wrote:
    I am really new to Java Swing ! Could you explain me or suggest me that how should I write Custom Renderer ?


    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html#renderer
    Fidel Edwards
    Ranch Hand

    Joined: Mar 19, 2008
    Posts: 231


    Thanks Maneesh !!

    :thumbup:
    Maneesh Godbole
    Saloon Keeper

    Joined: Jul 26, 2007
    Posts: 10519
        
        9

    You are welcome.
    It is interesting to note that the "renderer" concept can be used with a JTable as well as JTree along with the list. Check out the tutorials whenever you get time.
    Fidel Edwards
    Ranch Hand

    Joined: Mar 19, 2008
    Posts: 231
    Maneesh Godbole wrote:You are welcome.
    It is interesting to note that the "renderer" concept can be used with a JTable as well as JTree along with the list. Check out the tutorials whenever you get time.



    Thanks Maneesh,

    For nice tutorial ! But still I am not able to find out the desired solution


    I will be more happy if I get something more descriptive (and depicted) well.


    Again tons of thanks for early reply !
    Fidel Edwards
    Ranch Hand

    Joined: Mar 19, 2008
    Posts: 231
    I am not able to find out that how can parent window know that child window has closed. And parent window call repaint() method for ListA.

    Having tried lots of Idea but couldn't find the solution.


    Thanks in advance !
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19759
        
      20

    A modal dialog will block when setVisible(true) is called on it. Otherwise, a WindowListener and its windowClosed event will work.


    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
    How To Ask Questions How To Answer Questions
    Fidel Edwards
    Ranch Hand

    Joined: Mar 19, 2008
    Posts: 231
    Rob Prime wrote:A modal dialog will block when setVisible(true) is called on it. Otherwise, a WindowListener and its windowClosed event will work.


    Could you elaborate it more ? Still could not find any thing which can help to resolve this issue


    Thanks for reply !

    Alan Mehio
    Ranch Hand

    Joined: Apr 04, 2005
    Posts: 73
    Ashish Tiwari wrote:Hi Folks,

    I am new to Java Swings.I have a problem which is described as :

    I have two list in Parent window (say list ListA and ListB) .ListA has few items .On Clicking the ListA's item one popup window will be displayed .In this pop-up (child) window we have a TextArea and a save button.

    On clicking the Save Button the data entered into the TextArea should be displayed in ListB immediately.

    I used this approach in parent window

    [list] On clicking the ListA item


    [/list]

  • In pop-up window created text area and button


  • On clicking button will set the textarea value to the parentwindow.setListB (May be I am wrong here )



  • So when I click on ListA item gui appears, I enter data and click Save ....!!!
    No data display in ListB , while Again clicking the ListA item the previous entered data of ListB appears .

    I want to reflect the data in ListB immediately as click on Pop-up save button .



    something similar to the below just to give you some idea of intereaction between the main window ( JFrame) and the JDialog




    Regards,
    Alan Mehio
    London, UK
    Fidel Edwards
    Ranch Hand

    Joined: Mar 19, 2008
    Posts: 231
    Thanks Alan Mehio,


    Timber ! Exactly I was looking for the same , Tons of thanks ! I hope today I will not see the JList's ghost in my dream.

    Again Thanks for effort and patience!!
    Fidel Edwards
    Ranch Hand

    Joined: Mar 19, 2008
    Posts: 231
    Thanks Alan ,

    After seeing your code I found my mistake . I was doing the same as you did except I forget to write



    that stuck me badly.

    Again Thanks !
     
     
    subject: Populating JList in Parent window from Child window's save button