aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How To Refresh a JDialog? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How To Refresh a JDialog?" Watch "How To Refresh a JDialog?" New topic
Author

How To Refresh a JDialog?

James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi,

I've a JDialog displaying some PO items in a JPanel.
The items (JLabel) are generated based on a value object
and the UI components are added in the constructor of the JDialog.
Below is to depict:

JDialog
1 - PO item 1 (JLabel, not JTable)
2 - PO item 2
3 - PO item 3

I need to allow the deletion of PO item, as such there's
a DELETE button. Upon clicking DELETE, I would remove
the respective line item from the value object and then I would
have to refresh the JDialog

Could someone please advise on how to refresh the JDialog?
I've tried calling validate() and repaint() but it's still showing
the old line items.

Thanks in advance.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
I've tried calling validate() and repaint() but it's still showing the old line items.


I use revalidate(), repaint() on the panel.

To increase your chances of getting help you should create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.

Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Below is the code snippets to give an idea what I'm trying to achieve:


Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
Below is the code snippets to give an idea what I'm trying to achieve


That is not a SSCCE. I'll check back tomorrow. I guess it will be another 24 hours until you get an answer. If a proper SSCCE was posted you could have had your answer sooner.
James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi Rob,

I used snippets intentionally as I felt this is more of a concept issue.
SSCCE might be too much to be swallowed

Anyway, below is the SSCCE.
My objective is to get the JDialog to refresh to reflect the
deleted PO item after the delete button is clicked.

I managed to achieve it by disposing and re-creating the JDialog
but there might be better ways.


pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Why not put them in a JList or JTable and then place that structure in your JDialog? Then you can change the model and the display will update.
James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi Pete,

Using JList and JTable is a good way around but then the effect
of the display is going to be different.

What's in my mind is to have the whole panel scrollable instead
of scrolling within the JList/JTable.


Thanks.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

edit Scratch that, it's just a poorly named method.

Why do you have a method named paintDialog that actually has nothing whatsoever to do with painting?

edit2 All you've done in the actionPerformed is remove an item from a List. You're not removing it from the panel at all.


luck, db
There are no new questions, but there may be new answers.
James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi Darryl,

By removing the JLabel, I'll end up with blank lines.
Consequently, I would still have to refresh the JDialog right?

item 1
<blank line>
item 3

That's what I'm trying to figure out - how to refresh the screen.


Thanks.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
I used snippets intentionally as I felt this is more of a concept issue.


But you where not asked for snippets, you where asked for a SSCCE, why should we have to spend time repeating ourselves? We know what information is required to problem solve. For example:

a) when you build the GUI you loop though the List adding components to the screen. In your original question you stated you where using validate() and repaint(). To any person answering this question that implies you you are actully removing component from the GUI. However when we see your code it turns out you are only removing them from the List. Well I'm not sure why you expect the component to be automatically removed from the GUI since you had to manually add them. So there is no way we could guess the problem without seeing you code.

b) now you are complaining that there are blank lines. Well no there are no blank lines. That is the way tha GridLayout works. All components are sized to share the space equally, so since you have fewer lines there is no space allocated to each line. Again there is no way we could have guessed this without the benefit of a SSCCE, which is why a SSCCE should be included with every question. The solution here is to use a different layout manager, probably a BoxLayout. Then instead of adding individual components to the panel I would create a separate panel for each row. Then you add the components to the row panel and than add the panel to the main panel. Then when you want to remove the row you just remove the panel not the individual components.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How To Refresh a JDialog?