Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • 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 !!
     
    Rob Camick
    Ranch Hand
    Posts: 2534
    9
    • Mark post as helpful
    • send pies
    • 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.
     
    Michael Dunn
    Ranch Hand
    Posts: 4632
    • Mark post as helpful
    • send pies
    • 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: 234
    • Mark post as helpful
    • send pies
    • 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: 234
    • Mark post as helpful
    • send pies
    • 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 !
     
    Maneesh Godbole
    Saloon Keeper
    Posts: 11021
    12
    Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
    • Mark post as helpful
    • send pies
    • 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: 234
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator


    Thanks Maneesh !!

    :thumbup:
     
    Maneesh Godbole
    Saloon Keeper
    Posts: 11021
    12
    Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
    • Mark post as helpful
    • send pies
    • 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: 234
    • Mark post as helpful
    • send pies
    • 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: 234
    • Mark post as helpful
    • send pies
    • 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 !
     
    Rob Spoor
    Sheriff
    Pie
    Posts: 20492
    54
    Chrome Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • 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: 234
    • Mark post as helpful
    • send pies
    • 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 !

     
    Alan Mehio
    Ranch Hand
    Posts: 73
    • Mark post as helpful
    • send pies
    • 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: 234
    • Mark post as helpful
    • send pies
    • 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: 234
    • Mark post as helpful
    • send pies
    • 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 !
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic