• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!
     
    Rancher
    Posts: 3324
    32
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Ranch Hand
    Posts: 4632
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 244
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 244
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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 !
     
    Bartender
    Posts: 11497
    19
    Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 244
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Maneesh Godbole wrote:

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



    Thanks Maneesh !!

    :thumbup:
     
    Maneesh Godbole
    Bartender
    Posts: 11497
    19
    Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 244
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 244
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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 !
     
    Sheriff
    Posts: 22821
    132
    Eclipse IDE Spring Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    A modal dialog will block when setVisible(true) is called on it. Otherwise, a WindowListener and its windowClosed event will work.
     
    Fidel Edwards
    Ranch Hand
    Posts: 244
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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 !

     
    Ranch Hand
    Posts: 73
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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


     
    Fidel Edwards
    Ranch Hand
    Posts: 244
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 244
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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 !
     
    reply
      Bookmark Topic Watch Topic
    • New Topic