File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Refreshing a J-Frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Refreshing a J-Frame" Watch "Refreshing a J-Frame" New topic

Refreshing a J-Frame

Ramzi Hajaj

Joined: Aug 19, 2012
Posts: 13

Atm i have:

1. a class consisting of j-frame that is constructed by feeding in parameters.

2,These parameters change throughout the program.

3.This change occurs after a user response (comes through button click).

4. The GUI layout is always the same.

How do i refresh the object with new parameters without destroying it and creating a new one?

Basically the problem is that i need to refresh from the button click but this GUI class has no information?
Kemal Sokolovic

Joined: Jun 19, 2010
Posts: 825

Why are you adding MouseListeners to JButton controls?
Shouldn't you use ActionListener instead?

The quieter you are, the more you are able to hear.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> How do i refresh the object with new parameters without destroying it and creating a new one?

create a refresh() method to update the components.
this may mean moving the scope of some components from the constructor to a class field.

if the new parameters are just changes in text or icons etc, the update will occur immediately,
some other changes may require you to revalidate()/repaint() the parent container 'contentPane'
I agree. Here's the link:
subject: Refreshing a J-Frame
Similar Threads
Won't repaint!
Resizing JPanel and its inner components when JFrame is maximised
Prevent Duplicate value from jlist to jlist by way of a jbutton
mouseClicked event for the "Cancel button"
Switching between two forms